| 79 | |
| 80 | |
| 81 | static bool assign_fixed_string(MEM_ROOT *mem_root, |
| 82 | CHARSET_INFO *dst_cs, |
| 83 | size_t max_char, |
| 84 | String *dst, |
| 85 | const String* src) |
| 86 | { |
| 87 | bool truncated; |
| 88 | size_t numchars; |
| 89 | CHARSET_INFO *src_cs; |
| 90 | const char* src_str; |
| 91 | const char* src_end; |
| 92 | size_t src_len; |
| 93 | size_t to_copy; |
| 94 | char* dst_str; |
| 95 | size_t dst_len; |
| 96 | size_t dst_copied; |
| 97 | uint32 dummy_offset; |
| 98 | |
| 99 | src_str= src->ptr(); |
| 100 | if (src_str == NULL) |
| 101 | { |
| 102 | dst->set((const char*) NULL, 0, dst_cs); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | src_cs= src->charset(); |
| 107 | src_len= src->length(); |
| 108 | src_end= src_str + src_len; |
| 109 | numchars= src_cs->numchars(src_str, src_end); |
| 110 | |
| 111 | if (numchars <= max_char) |
| 112 | { |
| 113 | to_copy= src->length(); |
| 114 | truncated= false; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | numchars= max_char; |
| 119 | to_copy= dst_cs->charpos(src_str, src_end, numchars); |
| 120 | truncated= true; |
| 121 | } |
| 122 | |
| 123 | if (String::needs_conversion(to_copy, src_cs, dst_cs, & dummy_offset)) |
| 124 | { |
| 125 | dst_len= numchars * dst_cs->mbmaxlen; |
| 126 | dst_str= (char*) alloc_root(mem_root, dst_len + 1); |
| 127 | if (dst_str) |
| 128 | { |
| 129 | dst_copied= String_copier().well_formed_copy(dst_cs, dst_str, dst_len, |
| 130 | src_cs, src_str, src_len, |
| 131 | numchars); |
| 132 | DBUG_ASSERT(dst_copied <= dst_len); |
| 133 | dst_len= dst_copied; /* In case the copy truncated the data */ |
| 134 | dst_str[dst_copied]= '\0'; |
| 135 | } |
| 136 | } |
| 137 | else |
| 138 | { |
no test coverage detected