diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2016-03-01 00:34:49 +0100 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2016-03-02 00:13:05 +0100 |
commit | 34ca477b353a48b315ef8dc598c35f9ddca20370 (patch) | |
tree | 8ada958c4264c42615c9c1625a37cf01fbfc6a3f | |
parent | 9c7536238c872ca3b4d7ab864c1ee9aef039501d (diff) | |
download | mupdf-34ca477b353a48b315ef8dc598c35f9ddca20370.tar.xz |
Move UTF-8 string length function to fitz.
-rw-r--r-- | include/mupdf/fitz/string.h | 10 | ||||
-rw-r--r-- | source/fitz/string.c | 18 | ||||
-rw-r--r-- | source/html/html-layout.c | 19 |
3 files changed, 31 insertions, 16 deletions
diff --git a/include/mupdf/fitz/string.h b/include/mupdf/fitz/string.h index 81429b67..8daa28fc 100644 --- a/include/mupdf/fitz/string.h +++ b/include/mupdf/fitz/string.h @@ -103,6 +103,16 @@ int fz_runetochar(char *str, int rune); int fz_runelen(int rune); /* + fz_utflen: Count how many runes the UTF-8 encoded string + consists of. + + s: The UTF-8 encoded, NUL-terminated text string. + + Returns the number of runes in the string. +*/ +int fz_utflen(const char *s); + +/* fz_strtod/fz_strtof: Locale-independent decimal to binary conversion. On overflow return (-)INFINITY and set errno to ERANGE. On underflow return 0 and set errno to ERANGE. Special inputs (case diff --git a/source/fitz/string.c b/source/fitz/string.c index d22efe8e..025b612c 100644 --- a/source/fitz/string.c +++ b/source/fitz/string.c @@ -352,6 +352,24 @@ fz_runelen(int c) return fz_runetochar(str, c); } +int +fz_utflen(const char *s) +{ + int c, n, rune; + n = 0; + for(;;) { + c = *(const unsigned char*)s; + if(c < Runeself) { + if(c == 0) + return n; + s++; + } else + s += fz_chartorune(&rune, s); + n++; + } + return 0; +} + float fz_atof(const char *s) { float result; diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 5b84df6b..7be32592 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -1808,19 +1808,6 @@ typedef struct uni_buf *buffer; } bidi_data; -static size_t utf8len(const char *text) -{ - size_t len = 0; - - while (*text) - { - int rune; - text += fz_chartorune(&rune, text); - len++; - } - return len; -} - static void newFragCb(const uint32_t *fragment, size_t fragment_len, int block_r2l, @@ -1855,12 +1842,12 @@ static void newFragCb(const uint32_t *fragment, else { /* Must be text */ - len = utf8len(data->flow->content.text); + len = fz_utflen(data->flow->content.text); if (len > fragment_len) { /* We need to split this flow box */ (void)split_flow(data->ctx, data->pool, data->flow, fragment_len); - len = utf8len(data->flow->content.text); + len = fz_utflen(data->flow->content.text); } } @@ -1905,7 +1892,7 @@ detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_b switch (end->type) { case FLOW_WORD: - len = utf8len(end->content.text); + len = fz_utflen(end->content.text); text = end->content.text; break; case FLOW_SPACE: |