| 947 | */ |
| 948 | |
| 949 | uint32 convert_error_message(char *to, uint32 to_length, |
| 950 | const CHARSET_INFO *to_cs, |
| 951 | const char *from, uint32 from_length, |
| 952 | const CHARSET_INFO *from_cs, uint *errors) |
| 953 | { |
| 954 | int cnvres; |
| 955 | my_wc_t wc; |
| 956 | const uchar *from_end= (const uchar*) from+from_length; |
| 957 | char *to_start= to; |
| 958 | uchar *to_end; |
| 959 | my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc; |
| 960 | my_charset_conv_wc_mb wc_mb; |
| 961 | uint error_count= 0; |
| 962 | uint length; |
| 963 | |
| 964 | DBUG_ASSERT(to_length > 0); |
| 965 | /* Make room for the null terminator. */ |
| 966 | to_length--; |
| 967 | to_end= (uchar*) (to + to_length); |
| 968 | |
| 969 | if (!to_cs || from_cs == to_cs || to_cs == &my_charset_bin) |
| 970 | { |
| 971 | length= MY_MIN(to_length, from_length); |
| 972 | memmove(to, from, length); |
| 973 | to[length]= 0; |
| 974 | return length; |
| 975 | } |
| 976 | |
| 977 | wc_mb= to_cs->cset->wc_mb; |
| 978 | while (1) |
| 979 | { |
| 980 | if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from, from_end)) > 0) |
| 981 | { |
| 982 | if (!wc) |
| 983 | break; |
| 984 | from+= cnvres; |
| 985 | } |
| 986 | else if (cnvres == MY_CS_ILSEQ) |
| 987 | { |
| 988 | wc= (ulong) (uchar) *from; |
| 989 | from+=1; |
| 990 | } |
| 991 | else |
| 992 | break; |
| 993 | |
| 994 | if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0) |
| 995 | to+= cnvres; |
| 996 | else if (cnvres == MY_CS_ILUNI) |
| 997 | { |
| 998 | length= (wc <= 0xFFFF) ? 6/* '\1234' format*/ : 9 /* '\+123456' format*/; |
| 999 | if ((uchar*)(to + length) >= to_end) |
| 1000 | break; |
| 1001 | cnvres= my_snprintf(to, 9, |
| 1002 | (wc <= 0xFFFF) ? "\\%04X" : "\\+%06X", (uint) wc); |
| 1003 | to+= cnvres; |
| 1004 | } |
| 1005 | else |
| 1006 | break; |
no test coverage detected