| 266 | |
| 267 | |
| 268 | uint strconvert(CHARSET_INFO *from_cs, const char *from, |
| 269 | CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors) |
| 270 | { |
| 271 | int cnvres; |
| 272 | my_wc_t wc; |
| 273 | char *to_start= to; |
| 274 | uchar *to_end= (uchar*) to + to_length - 1; |
| 275 | my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc; |
| 276 | my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb; |
| 277 | uint error_count= 0; |
| 278 | |
| 279 | while (1) |
| 280 | { |
| 281 | /* |
| 282 | Using 'from + 10' is safe: |
| 283 | - it is enough to scan a single character in any character set. |
| 284 | - if remaining string is shorter than 10, then mb_wc will return |
| 285 | with error because of unexpected '\0' character. |
| 286 | */ |
| 287 | if ((cnvres= (*mb_wc)(from_cs, &wc, |
| 288 | (uchar*) from, (uchar*) from + 10)) > 0) |
| 289 | { |
| 290 | if (!wc) |
| 291 | break; |
| 292 | from+= cnvres; |
| 293 | } |
| 294 | else if (cnvres == MY_CS_ILSEQ) |
| 295 | { |
| 296 | error_count++; |
| 297 | from++; |
| 298 | wc= '?'; |
| 299 | } |
| 300 | else |
| 301 | break; // Impossible char. |
| 302 | |
| 303 | outp: |
| 304 | |
| 305 | if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0) |
| 306 | to+= cnvres; |
| 307 | else if (cnvres == MY_CS_ILUNI && wc != '?') |
| 308 | { |
| 309 | error_count++; |
| 310 | wc= '?'; |
| 311 | goto outp; |
| 312 | } |
| 313 | else |
| 314 | break; |
| 315 | } |
| 316 | *to= '\0'; |
| 317 | *errors= error_count; |
| 318 | return (uint32) (to - to_start); |
| 319 | |
| 320 | } |
| 321 | |
| 322 | |
| 323 | /* |
no outgoing calls
no test coverage detected