Skip to content

Commit 9012d79

Browse files
Christoph Hellwigkrisman-at-collabora
authored andcommitted
unicode: simplify utf8len
Just use the utf8nlen implementation with a (size_t)-1 len argument, similar to utf8_lookup. Also move the function to utf8-selftest.c, as it isn't used anywhere else. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
1 parent 379210d commit 9012d79

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

fs/unicode/utf8-norm.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -391,36 +391,6 @@ static utf8leaf_t *utf8lookup(const struct utf8data *data,
391391
return utf8nlookup(data, hangul, s, (size_t)-1);
392392
}
393393

394-
/*
395-
* Length of the normalization of s.
396-
* Return -1 if s is not valid UTF-8 unicode.
397-
*
398-
* A string of Default_Ignorable_Code_Point has length 0.
399-
*/
400-
ssize_t utf8len(const struct utf8data *data, const char *s)
401-
{
402-
utf8leaf_t *leaf;
403-
size_t ret = 0;
404-
unsigned char hangul[UTF8HANGULLEAF];
405-
406-
if (!data)
407-
return -1;
408-
while (*s) {
409-
leaf = utf8lookup(data, hangul, s);
410-
if (!leaf)
411-
return -1;
412-
if (utf8agetab[LEAF_GEN(leaf)] > data->maxage)
413-
ret += utf8clen(s);
414-
else if (LEAF_CCC(leaf) == DECOMPOSE)
415-
ret += strlen(LEAF_STR(leaf));
416-
else
417-
ret += utf8clen(s);
418-
s += utf8clen(s);
419-
}
420-
return ret;
421-
}
422-
EXPORT_SYMBOL(utf8len);
423-
424394
/*
425395
* Length of the normalization of s, touch at most len bytes.
426396
* Return -1 if s is not valid UTF-8 unicode.

fs/unicode/utf8-selftest.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ static const struct {
160160
}
161161
};
162162

163+
static ssize_t utf8len(const struct utf8data *data, const char *s)
164+
{
165+
return utf8nlen(data, s, (size_t)-1);
166+
}
167+
163168
static void check_utf8_nfdi(void)
164169
{
165170
int i;

fs/unicode/utf8n.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extern const struct utf8data *utf8nfdicf(unsigned int maxage);
3939
* Returns 0 if only ignorable code points are present.
4040
* Returns -1 if the input is not valid UTF-8.
4141
*/
42-
extern ssize_t utf8len(const struct utf8data *data, const char *s);
4342
extern ssize_t utf8nlen(const struct utf8data *data, const char *s, size_t len);
4443

4544
/* Needed in struct utf8cursor below. */

0 commit comments

Comments
 (0)