| 340 | } |
| 341 | |
| 342 | int columnWidthUTF8(StringRef Text) { |
| 343 | unsigned ColumnWidth = 0; |
| 344 | unsigned Length; |
| 345 | for (size_t i = 0, e = Text.size(); i < e; i += Length) { |
| 346 | Length = getNumBytesForUTF8(Text[i]); |
| 347 | if (Length <= 0 || i + Length > Text.size()) |
| 348 | return ErrorInvalidUTF8; |
| 349 | UTF32 buf[1]; |
| 350 | const UTF8 *Start = reinterpret_cast<const UTF8 *>(Text.data() + i); |
| 351 | UTF32 *Target = &buf[0]; |
| 352 | if (conversionOK != ConvertUTF8toUTF32(&Start, Start + Length, &Target, |
| 353 | Target + 1, strictConversion)) |
| 354 | return ErrorInvalidUTF8; |
| 355 | int Width = charWidth(buf[0]); |
| 356 | if (Width < 0) |
| 357 | return ErrorNonPrintableCharacter; |
| 358 | ColumnWidth += Width; |
| 359 | } |
| 360 | return ColumnWidth; |
| 361 | } |
| 362 | |
| 363 | } // namespace unicode |
| 364 | } // namespace sys |
no test coverage detected