Convert text descriptor into UTF8 string. Binary data converted into HEX representation.
| 62 | // Convert text descriptor into UTF8 string. |
| 63 | // Binary data converted into HEX representation. |
| 64 | bool descToUTF8(const dsc* param, string& result) |
| 65 | { |
| 66 | UCHAR* address; |
| 67 | USHORT length; |
| 68 | |
| 69 | switch (param->dsc_dtype) |
| 70 | { |
| 71 | case dtype_text: |
| 72 | address = param->dsc_address; |
| 73 | length = param->dsc_length; |
| 74 | break; |
| 75 | |
| 76 | case dtype_varying: |
| 77 | address = param->dsc_address + sizeof(USHORT); |
| 78 | length = *(USHORT*) param->dsc_address; |
| 79 | fb_assert(length <= param->dsc_length - 2); |
| 80 | break; |
| 81 | |
| 82 | default: |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | if (param->getCharSet() == CS_BINARY) |
| 87 | { |
| 88 | // Convert OCTETS and [VAR]BINARY to HEX string |
| 89 | |
| 90 | char* hex = result.getBuffer(length * 2); |
| 91 | |
| 92 | for (const UCHAR* p = address; p < address + length; p++) |
| 93 | { |
| 94 | UCHAR c = (*p & 0xF0) >> 4; |
| 95 | *hex++ = c + (c < 10 ? '0' : 'A' - 10); |
| 96 | |
| 97 | c = (*p & 0x0F); |
| 98 | *hex++ = c + (c < 10 ? '0' : 'A' - 10); |
| 99 | } |
| 100 | return result.c_str(); |
| 101 | } |
| 102 | |
| 103 | string src(address, length); |
| 104 | |
| 105 | try |
| 106 | { |
| 107 | if (!Jrd::DataTypeUtil::convertToUTF8(src, result, param->dsc_sub_type, status_exception::raise)) |
| 108 | result = src; |
| 109 | } |
| 110 | catch (const Firebird::Exception&) |
| 111 | { |
| 112 | result = src; |
| 113 | } |
| 114 | |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | } // namespace |
| 119 |
no test coverage detected