diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2013-03-17 22:01:42 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2013-03-17 22:01:42 +0000 |
commit | c3f21572ed18b9319aeba0fc5caf4a6394fd3905 (patch) | |
tree | 761308ff1d2c8b03396f84fbc2e6b51f52654798 /utils/utf8.c | |
parent | c205378a8df1c3b099adf2436e2eacd16d070bb6 (diff) | |
download | netsurf-c3f21572ed18b9319aeba0fc5caf4a6394fd3905.tar.gz netsurf-c3f21572ed18b9319aeba0fc5caf4a6394fd3905.tar.bz2 |
Add function to get the byte length of n characters in a utf8 string.
Diffstat (limited to 'utils/utf8.c')
-rw-r--r-- | utils/utf8.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/utils/utf8.c b/utils/utf8.c index b4e308044..885ca94ee 100644 --- a/utils/utf8.c +++ b/utils/utf8.c @@ -118,6 +118,24 @@ size_t utf8_bounded_length(const char *s, size_t l) } /** + * 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 * * \param s Pointer to start of character |