| 471 | |
| 472 | |
| 473 | size_t UTF8NextCodepoint(const std::string& s8, size_t pos) { |
| 474 | // Check out of bounds |
| 475 | if (pos >= s8.size()) |
| 476 | return s8.size(); |
| 477 | size_t size = UTF8CodepointSize(s8[pos]); |
| 478 | // Check for continuation byte 0b10xxxxxx |
| 479 | // if ((s8[1] & 0xc0) != 0x80) return 0; |
| 480 | // if ((s8[2] & 0xc0) != 0x80) return 0; |
| 481 | // if ((s8[3] & 0xc0) != 0x80) return 0; |
| 482 | return std::min(pos + size, s8.size()); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /** Finds the byte index of the front of a codepoint by reversing until a non-continuation byte is found. */ |
no test coverage detected