764
if ((to_cs == &my_charset_bin) ||
765
(from_cs == &my_charset_bin) ||
766
(to_cs == from_cs) ||
767
my_charset_same(from_cs, to_cs))
769
if (to_length < to_cs->mbminlen || !nchars)
772
*cannot_convert_error_pos= NULL;
773
*well_formed_error_pos= NULL;
777
if (to_cs == &my_charset_bin)
779
res= cmin(cmin(nchars, to_length), from_length);
780
memmove(to, from, res);
781
*from_end_pos= from + res;
782
*well_formed_error_pos= NULL;
783
*cannot_convert_error_pos= NULL;
787
int well_formed_error;
788
uint32_t from_offset;
790
if ((from_offset= (from_length % to_cs->mbminlen)) &&
791
(from_cs == &my_charset_bin))
794
Copying from BINARY to UCS2 needs to prepend zeros sometimes:
795
INSERT INTO t1 (ucs2_column) VALUES (0x01);
798
uint32_t pad_length= to_cs->mbminlen - from_offset;
799
memset(to, 0, pad_length);
800
memmove(to + pad_length, from, from_offset);
803
from_length-= from_offset;
804
to+= to_cs->mbminlen;
805
to_length-= to_cs->mbminlen;
808
set_if_smaller(from_length, to_length);
809
res= to_cs->cset->well_formed_len(to_cs, from, from + from_length,
810
nchars, &well_formed_error);
811
memmove(to, from, res);
812
*from_end_pos= from + res;
813
*well_formed_error_pos= well_formed_error ? from + res : NULL;
814
*cannot_convert_error_pos= NULL;
816
res+= to_cs->mbminlen;
764
assert((to_cs == &my_charset_bin) ||
765
(from_cs == &my_charset_bin) ||
766
(to_cs == from_cs) ||
767
my_charset_same(from_cs, to_cs));
769
if (to_length < to_cs->mbminlen || !nchars)
772
*cannot_convert_error_pos= NULL;
773
*well_formed_error_pos= NULL;
777
if (to_cs == &my_charset_bin)
779
res= cmin(cmin(nchars, to_length), from_length);
780
memmove(to, from, res);
781
*from_end_pos= from + res;
782
*well_formed_error_pos= NULL;
783
*cannot_convert_error_pos= NULL;
823
my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
824
my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
825
const unsigned char *from_end= (const unsigned char*) from + from_length;
826
unsigned char *to_end= (unsigned char*) to + to_length;
828
*well_formed_error_pos= NULL;
829
*cannot_convert_error_pos= NULL;
787
int well_formed_error;
788
uint32_t from_offset;
831
for ( ; nchars; nchars--)
790
if ((from_offset= (from_length % to_cs->mbminlen)) &&
791
(from_cs == &my_charset_bin))
833
const char *from_prev= from;
834
if ((cnvres= (*mb_wc)(from_cs, &wc, (unsigned char*) from, from_end)) > 0)
836
else if (cnvres == MY_CS_ILSEQ)
838
if (!*well_formed_error_pos)
839
*well_formed_error_pos= from;
843
else if (cnvres > MY_CS_TOOSMALL)
846
A correct multibyte sequence detected
847
But it doesn't have Unicode mapping.
849
if (!*cannot_convert_error_pos)
850
*cannot_convert_error_pos= from;
855
break; // Not enough characters
858
if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
860
else if (cnvres == MY_CS_ILUNI && wc != '?')
862
if (!*cannot_convert_error_pos)
863
*cannot_convert_error_pos= from_prev;
794
Copying from BINARY to UCS2 needs to prepend zeros sometimes:
795
INSERT INTO t1 (ucs2_column) VALUES (0x01);
798
uint32_t pad_length= to_cs->mbminlen - from_offset;
799
memset(to, 0, pad_length);
800
memmove(to + pad_length, from, from_offset);
803
from_length-= from_offset;
804
to+= to_cs->mbminlen;
805
to_length-= to_cs->mbminlen;
808
set_if_smaller(from_length, to_length);
809
res= to_cs->cset->well_formed_len(to_cs, from, from + from_length,
810
nchars, &well_formed_error);
811
memmove(to, from, res);
812
*from_end_pos= from + res;
813
*well_formed_error_pos= well_formed_error ? from + res : NULL;
814
*cannot_convert_error_pos= NULL;
816
res+= to_cs->mbminlen;
876
return (uint32_t) res;