libcaption
libcaption copied to clipboard
Fix bug with counting utf-8 character lengths.
This resolves the issue in:
https://github.com/szatmary/libcaption/issues/46
This also appears to resolve my issues in #50 !
LGTM !!
While it may fix the issue, this change duplicates _utf8_newline
, and rolls back increments in the for
loop.
I'd propose something much simpler:
size_t utf8_line_length(const utf8_char_t* data)
{
size_t n, len = 0;
while (0 != data[len]) {
if (0 < (n = _utf8_newline(data + len))) {
return len + n;
}
len += utf8_char_length(data + len);
}
return len;
}