| 878 | */ |
| 879 | |
| 880 | uint err_conv(char *buff, size_t to_length, const char *from, |
| 881 | size_t from_length, const CHARSET_INFO *from_cs) |
| 882 | { |
| 883 | char *to= buff; |
| 884 | const char *from_start= from; |
| 885 | size_t res; |
| 886 | |
| 887 | DBUG_ASSERT(to_length > 0); |
| 888 | to_length--; |
| 889 | if (from_cs == &my_charset_bin) |
| 890 | { |
| 891 | uchar char_code; |
| 892 | res= 0; |
| 893 | while (1) |
| 894 | { |
| 895 | if ((uint)(from - from_start) >= from_length || |
| 896 | res >= to_length) |
| 897 | { |
| 898 | *to= 0; |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | char_code= ((uchar) *from); |
| 903 | if (char_code >= 0x20 && char_code <= 0x7E) |
| 904 | { |
| 905 | *to++= char_code; |
| 906 | from++; |
| 907 | res++; |
| 908 | } |
| 909 | else |
| 910 | { |
| 911 | if (res + 4 >= to_length) |
| 912 | { |
| 913 | *to= 0; |
| 914 | break; |
| 915 | } |
| 916 | res+= my_snprintf(to, 5, "\\x%02X", (uint) char_code); |
| 917 | to+=4; |
| 918 | from++; |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | uint errors; |
| 925 | res= copy_and_convert(to, to_length, system_charset_info, |
| 926 | from, from_length, from_cs, &errors); |
| 927 | to+= res; |
| 928 | *to= 0; |
| 929 | } |
| 930 | return to - buff; |
| 931 | } |
| 932 | |
| 933 | |
| 934 | /** |
no test coverage detected