libcaption icon indicating copy to clipboard operation
libcaption copied to clipboard

Fix bug with counting utf-8 character lengths.

Open benburkhart1 opened this issue 6 years ago • 3 comments

This resolves the issue in:

https://github.com/szatmary/libcaption/issues/46

benburkhart1 avatar Oct 18 '18 16:10 benburkhart1

This also appears to resolve my issues in #50 !

nabeards avatar Nov 01 '18 17:11 nabeards

LGTM !!

boxerab avatar Mar 26 '19 13:03 boxerab

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;
}

micolous avatar Sep 19 '21 05:09 micolous