Returns the last codepoint of a word by scanning backward for the start of the last UTF-8 sequence.
| 46 | |
| 47 | // Returns the last codepoint of a word by scanning backward for the start of the last UTF-8 sequence. |
| 48 | uint32_t lastCodepoint(const std::string& word) { |
| 49 | if (word.empty()) return 0; |
| 50 | // UTF-8 continuation bytes start with 10xxxxxx; scan backward to find the leading byte. |
| 51 | size_t i = word.size() - 1; |
| 52 | while (i > 0 && (static_cast<uint8_t>(word[i]) & 0xC0) == 0x80) { |
| 53 | --i; |
| 54 | } |
| 55 | const auto* ptr = reinterpret_cast<const unsigned char*>(word.c_str() + i); |
| 56 | return utf8NextCodepoint(&ptr); |
| 57 | } |
| 58 | |
| 59 | bool containsSoftHyphen(const std::string& word) { return word.find(SOFT_HYPHEN_UTF8) != std::string::npos; } |
| 60 |
no test coverage detected