| 360 | } |
| 361 | |
| 362 | bool IsStringUTF8(const StringPiece& str) { |
| 363 | const char *src = str.data(); |
| 364 | int32_t src_len = static_cast<int32_t>(str.length()); |
| 365 | int32_t char_index = 0; |
| 366 | |
| 367 | while (char_index < src_len) { |
| 368 | int32_t code_point; |
| 369 | CBU8_NEXT(src, char_index, src_len, code_point); |
| 370 | if (!IsValidCharacter(code_point)) |
| 371 | return false; |
| 372 | } |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | } // namespace butil |
| 377 |