Skip to content

Commit

Permalink
utf8: make utf8_strnwidth & utf8_strwidth return size_t instead of int
Browse files Browse the repository at this point in the history
This patch addresses the TODO comment of changing the return types
of these functions from int to size_t.

Signed-off-by: Mohit Marathe <[email protected]>
  • Loading branch information
mohit-marathe committed Mar 16, 2024
1 parent 2e89da2 commit 615481e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int utf8_width(const char **start, size_t *remainder_p)
* string, assuming that the string is utf8. Returns strlen() instead
* if the string does not look like a valid utf8 string.
*/
int utf8_strnwidth(const char *string, size_t len, int skip_ansi)
size_t utf8_strnwidth(const char *string, size_t len, int skip_ansi)
{
const char *orig = string;
size_t width = 0;
Expand All @@ -224,14 +224,10 @@ int utf8_strnwidth(const char *string, size_t len, int skip_ansi)
width += glyph_width;
}

/*
* TODO: fix the interface of this function and `utf8_strwidth()` to
* return `size_t` instead of `int`.
*/
return cast_size_t_to_int(string ? width : len);
return string ? width : len;
}

int utf8_strwidth(const char *string)
size_t utf8_strwidth(const char *string)
{
return utf8_strnwidth(string, strlen(string), 0);
}
Expand Down
4 changes: 2 additions & 2 deletions utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ typedef unsigned int ucs_char_t; /* assuming 32bit int */

size_t display_mode_esc_sequence_len(const char *s);
int utf8_width(const char **start, size_t *remainder_p);
int utf8_strnwidth(const char *string, size_t len, int skip_ansi);
int utf8_strwidth(const char *string);
size_t utf8_strnwidth(const char *string, size_t len, int skip_ansi);
size_t utf8_strwidth(const char *string);
int is_utf8(const char *text);
int is_encoding_utf8(const char *name);
int same_encoding(const char *, const char *);
Expand Down

0 comments on commit 615481e

Please sign in to comment.