MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / lastCodepoint

Function lastCodepoint

lib/Epub/Epub/ParsedText.cpp:48–57  ·  view source on GitHub ↗

Returns the last codepoint of a word by scanning backward for the start of the last UTF-8 sequence.

Source from the content-addressed store, hash-verified

46
47// Returns the last codepoint of a word by scanning backward for the start of the last UTF-8 sequence.
48uint32_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
59bool containsSoftHyphen(const std::string& word) { return word.find(SOFT_HYPHEN_UTF8) != std::string::npos; }
60

Callers 4

addWordMethod · 0.85
computeLineBreaksMethod · 0.85
extractLineMethod · 0.85

Calls 3

utf8NextCodepointFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected