22 #include "CharsetMap.hpp"
23 #include "CharsetMapImpl.h"
24 #include "my_global.h"
28 bool m_false_result =
false;
29 bool m_true_result =
true;
62 CharsetMap::CharsetMap()
65 if(_map->ready == 0) _map->build_map();
79 return cs ? cs->csname : 0;
85 return _map->UTF8Charset;
91 return _map->UTF16Charset;
97 return get_charset_number(name, MY_CS_AVAILABLE);
103 if(cset == 0)
return 0;
104 return use_mb(cset) ? & m_true_result : & m_false_result;
109 const void *void_src,
110 void *void_dest)
const
112 int32_t &total_read = lengths[0];
113 int32_t &total_written = lengths[1];
115 my_wc_t mystery_char =
'?';
116 const unsigned char * src = (
const unsigned char *) void_src;
117 unsigned char * dest = (
unsigned char *) void_dest;
121 if(! (csTo && csFrom))
return RECODE_BAD_CHARSET;
123 int32_t src_len = lengths[0];
124 int32_t dest_len = lengths[1];
125 const unsigned char * src_end = src + src_len;
126 unsigned char * dest_end = dest + dest_len;
130 while(src < src_end) {
132 int nread = csFrom->cset->mb_wc(csFrom, &wide, src, src_end);
133 if(nread < 0)
return RECODE_BUFF_TOO_SMALL;
134 if(nread == 0)
return RECODE_BAD_SRC;
137 int nwritten = csTo->cset->wc_mb(csTo, wide, dest, dest_end);
138 if(nwritten == MY_CS_ILUNI) {
140 nwritten = csTo->cset->wc_mb(csTo, mystery_char, dest, dest_end);
142 if(nwritten < 0)
return RECODE_BUFF_TOO_SMALL;
144 total_read += nread; src += nread;
145 total_written += nwritten; dest += nwritten;