| 325 | |
| 326 | |
| 327 | uint strconvert(CHARSET_INFO *from_cs, const char *from, size_t from_length, |
| 328 | CHARSET_INFO *to_cs, char *to, size_t to_length, uint *errors) |
| 329 | { |
| 330 | int cnvres; |
| 331 | my_wc_t wc; |
| 332 | char *to_start= to; |
| 333 | uchar *to_end= (uchar*) to + to_length - 1; |
| 334 | const uchar *from_end= (const uchar*) from + from_length; |
| 335 | my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc; |
| 336 | my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb; |
| 337 | uint error_count= 0; |
| 338 | |
| 339 | while (1) |
| 340 | { |
| 341 | if ((cnvres= (*mb_wc)(from_cs, &wc, |
| 342 | (uchar*) from, from_end)) > 0) |
| 343 | { |
| 344 | if (!wc) |
| 345 | break; |
| 346 | from+= cnvres; |
| 347 | } |
| 348 | else if (cnvres == MY_CS_ILSEQ) |
| 349 | { |
| 350 | error_count++; |
| 351 | from++; |
| 352 | wc= '?'; |
| 353 | } |
| 354 | else |
| 355 | break; // Impossible char. |
| 356 | |
| 357 | outp: |
| 358 | |
| 359 | if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0) |
| 360 | to+= cnvres; |
| 361 | else if (cnvres == MY_CS_ILUNI && wc != '?') |
| 362 | { |
| 363 | error_count++; |
| 364 | wc= '?'; |
| 365 | goto outp; |
| 366 | } |
| 367 | else |
| 368 | break; |
| 369 | } |
| 370 | *to= '\0'; |
| 371 | *errors= error_count; |
| 372 | return (uint32) (to - to_start); |
| 373 | |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /* |
no outgoing calls
no test coverage detected