Returns false if conversion is not needed.
| 364 | |
| 365 | // Returns false if conversion is not needed. |
| 366 | bool DataTypeUtil::convertToUTF8(const string& src, string& dst, CHARSET_ID charset, ErrorFunction err) |
| 367 | { |
| 368 | thread_db* tdbb = JRD_get_thread_data(); |
| 369 | |
| 370 | if (charset == CS_dynamic) |
| 371 | { |
| 372 | fb_assert(tdbb->getAttachment()); |
| 373 | charset = tdbb->getAttachment()->att_charset; |
| 374 | } |
| 375 | |
| 376 | if (charset == CS_UTF8 || charset == CS_UNICODE_FSS) |
| 377 | return false; |
| 378 | |
| 379 | if (charset == CS_NONE) |
| 380 | { |
| 381 | const FB_SIZE_T length = src.length(); |
| 382 | |
| 383 | const char* s = src.c_str(); |
| 384 | char* p = dst.getBuffer(length); |
| 385 | |
| 386 | for (const char* end = src.end(); s < end; ++p, ++s) |
| 387 | *p = (*s < 0 ? '?' : *s); |
| 388 | } |
| 389 | else // charset != CS_UTF8 |
| 390 | { |
| 391 | DataTypeUtil dtUtil(tdbb); |
| 392 | ULONG length = dtUtil.convertLength(src.length(), charset, CS_UTF8); |
| 393 | |
| 394 | length = INTL_convert_bytes(tdbb, |
| 395 | CS_UTF8, (UCHAR*) dst.getBuffer(length), length, |
| 396 | charset, (const BYTE*) src.begin(), src.length(), |
| 397 | err); |
| 398 | |
| 399 | dst.resize(length); |
| 400 | } |
| 401 | |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | } // namespace Jrd |
nothing calls this directly
no test coverage detected