mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Add function to get the byte length of n characters in a utf8 string.
This commit is contained in:
parent
c205378a8d
commit
c3f21572ed
18
utils/utf8.c
18
utils/utf8.c
@ -117,6 +117,24 @@ size_t utf8_bounded_length(const char *s, size_t l)
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the length (in bytes) of a bounded UTF-8 string
|
||||
*
|
||||
* \param s The string
|
||||
* \param l Maximum length of input (in bytes)
|
||||
* \param c Maximum number of characters to measure
|
||||
* \return Length of string, in bytes
|
||||
*/
|
||||
size_t utf8_bounded_byte_length(const char *s, size_t l, size_t c)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (len < l && c-- > 0)
|
||||
len = utf8_next(s, l, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the length (in bytes) of a UTF-8 character
|
||||
*
|
||||
|
@ -37,6 +37,7 @@ size_t utf8_from_ucs4(uint32_t c, char *s);
|
||||
|
||||
size_t utf8_length(const char *s);
|
||||
size_t utf8_bounded_length(const char *s, size_t l);
|
||||
size_t utf8_bounded_byte_length(const char *s, size_t l, size_t c);
|
||||
|
||||
size_t utf8_char_byte_length(const char *s);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user