[reader] Fixed bug when a word is too big

This commit is contained in:
Laury
2022-04-08 19:03:13 +02:00
parent 22ba190542
commit 2bf6de5044
17 changed files with 218 additions and 75 deletions

View File

@@ -120,6 +120,7 @@ size_t StringGlyphLength(const char * s, int maxSize = -1);
const char * BeginningOfWord(const char * text, const char * word);
// Returns the position of the first following char ' ', '\n' or 0
const char * EndOfWord(const char * word);
const char * EndOfWord(const char * word, const char * end);
// On a line, count number of glyphs before and after locations
void countGlyphsInLine(const char * text, int * before, int * after, const char * beforeLocation, const char *afterLocation = nullptr);

View File

@@ -475,6 +475,20 @@ const char * EndOfWord(const char * word) {
return result;
}
const char * EndOfWord(const char * word, const char * end) {
UTF8Decoder decoder(word);
CodePoint codePoint = decoder.nextCodePoint();
const char * result = word;
while (!CodePointIsEndOfWord(codePoint)) {
result = decoder.stringPosition();
if (result >= end) {
break;
}
codePoint = decoder.nextCodePoint();
}
return result;
}
void countGlyphsInLine(const char * text, int * before, int * after, const char * beforeLocation, const char *afterLocation) {
UTF8Helper::CodePointAction countGlyph = [](int, void * glyphCount, int, int) {
int * castedCount = (int *) glyphCount;