Finds the byte index of the front of a codepoint by reversing until a non-continuation byte is found. */
| 485 | |
| 486 | /** Finds the byte index of the front of a codepoint by reversing until a non-continuation byte is found. */ |
| 487 | static size_t UTF8StartCodepoint(const std::string& s8, size_t pos) { |
| 488 | // Check out of bounds |
| 489 | if (pos >= s8.size()) |
| 490 | return s8.size(); |
| 491 | while (pos > 0) { |
| 492 | // Check for continuation byte 0b10xxxxxx |
| 493 | if ((s8[pos] & 0xc0) != 0x80) |
| 494 | break; |
| 495 | pos--; |
| 496 | } |
| 497 | return pos; |
| 498 | } |
| 499 | |
| 500 | |
| 501 | size_t UTF8PrevCodepoint(const std::string& s8, size_t pos) { |
no test coverage detected