| 181 | // It will always be sorted by increasing offset. |
| 182 | template<typename SrcChar, typename DestStdString> |
| 183 | bool ConvertUnicode(const SrcChar* src, |
| 184 | size_t src_len, |
| 185 | DestStdString* output, |
| 186 | OffsetAdjuster::Adjustments* adjustments) { |
| 187 | if (adjustments) |
| 188 | adjustments->clear(); |
| 189 | // ICU requires 32-bit numbers. |
| 190 | bool success = true; |
| 191 | int32_t src_len32 = static_cast<int32_t>(src_len); |
| 192 | for (int32_t i = 0; i < src_len32; i++) { |
| 193 | uint32_t code_point; |
| 194 | size_t original_i = i; |
| 195 | size_t chars_written = 0; |
| 196 | if (ReadUnicodeCharacter(src, src_len32, &i, &code_point)) { |
| 197 | chars_written = WriteUnicodeCharacter(code_point, output); |
| 198 | } else { |
| 199 | chars_written = WriteUnicodeCharacter(0xFFFD, output); |
| 200 | success = false; |
| 201 | } |
| 202 | |
| 203 | // Only bother writing an adjustment if this modification changed the |
| 204 | // length of this character. |
| 205 | // NOTE: ReadUnicodeCharacter() adjusts |i| to point _at_ the last |
| 206 | // character read, not after it (so that incrementing it in the loop |
| 207 | // increment will place it at the right location), so we need to account |
| 208 | // for that in determining the amount that was read. |
| 209 | if (adjustments && ((i - original_i + 1) != chars_written)) { |
| 210 | adjustments->push_back(OffsetAdjuster::Adjustment( |
| 211 | original_i, i - original_i + 1, chars_written)); |
| 212 | } |
| 213 | } |
| 214 | return success; |
| 215 | } |
| 216 | |
| 217 | bool UTF8ToUTF16WithAdjustments( |
| 218 | const char* src, |
no test coverage detected