| 455 | |
| 456 | |
| 457 | static size_t UTF8CodepointSize(char c) { |
| 458 | if (!c) return 0; |
| 459 | // First byte signals size |
| 460 | // 0b0xxxxxxx |
| 461 | if ((c & 0x80) == 0x00) return 1; |
| 462 | // 0b110xxxxx |
| 463 | if ((c & 0xe0) == 0xc0) return 2; |
| 464 | // 0b1110xxxx |
| 465 | if ((c & 0xf0) == 0xe0) return 3; |
| 466 | // 0b11110xxx |
| 467 | if ((c & 0xf8) == 0xf0) return 4; |
| 468 | // Invalid first UTF-8 byte |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | |
| 473 | size_t UTF8NextCodepoint(const std::string& s8, size_t pos) { |