Skip to content

Commit

Permalink
unicode: simplify utf8len
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and krisman-at-collabora committed Oct 11, 2021
1 parent 379210d commit 9012d79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
30 changes: 0 additions & 30 deletions fs/unicode/utf8-norm.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,36 +391,6 @@ static utf8leaf_t *utf8lookup(const struct utf8data *data,
return utf8nlookup(data, hangul, s, (size_t)-1);
}

/*
* Length of the normalization of s.
* Return -1 if s is not valid UTF-8 unicode.
*
* A string of Default_Ignorable_Code_Point has length 0.
*/
ssize_t utf8len(const struct utf8data *data, const char *s)
{
utf8leaf_t *leaf;
size_t ret = 0;
unsigned char hangul[UTF8HANGULLEAF];

if (!data)
return -1;
while (*s) {
leaf = utf8lookup(data, hangul, s);
if (!leaf)
return -1;
if (utf8agetab[LEAF_GEN(leaf)] > data->maxage)
ret += utf8clen(s);
else if (LEAF_CCC(leaf) == DECOMPOSE)
ret += strlen(LEAF_STR(leaf));
else
ret += utf8clen(s);
s += utf8clen(s);
}
return ret;
}
EXPORT_SYMBOL(utf8len);

/*
* Length of the normalization of s, touch at most len bytes.
* Return -1 if s is not valid UTF-8 unicode.
Expand Down
5 changes: 5 additions & 0 deletions fs/unicode/utf8-selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ static const struct {
}
};

static ssize_t utf8len(const struct utf8data *data, const char *s)
{
return utf8nlen(data, s, (size_t)-1);
}

static void check_utf8_nfdi(void)
{
int i;
Expand Down
1 change: 0 additions & 1 deletion fs/unicode/utf8n.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extern const struct utf8data *utf8nfdicf(unsigned int maxage);
* Returns 0 if only ignorable code points are present.
* Returns -1 if the input is not valid UTF-8.
*/
extern ssize_t utf8len(const struct utf8data *data, const char *s);
extern ssize_t utf8nlen(const struct utf8data *data, const char *s, size_t len);

/* Needed in struct utf8cursor below. */
Expand Down

0 comments on commit 9012d79

Please sign in to comment.