From: "Mohit Marathe via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Mohit Marathe <mohitmarathe@proton.me>,
Mohit Marathe <mohitmarathe@proton.me>
Subject: [PATCH 2/2] utf8: make utf8_strnwidth & utf8_strwidth return size_t instead of int
Date: Sun, 17 Mar 2024 08:27:51 +0000 [thread overview]
Message-ID: <615481efd70fbd7e8950bea3edca12e43a024cd8.1710664071.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1690.git.1710664071.gitgitgadget@gmail.com>
From: Mohit Marathe <mohitmarathe@proton.me>
This patch addresses the TODO comment of changing the return types
of these functions from int to size_t.
Signed-off-by: Mohit Marathe <mohitmarathe@proton.me>
---
utf8.c | 10 +++-------
utf8.h | 4 ++--
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/utf8.c b/utf8.c
index 8ccdf684e07..050fc8b3cdf 100644
--- a/utf8.c
+++ b/utf8.c
@@ -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;
@@ -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);
}
diff --git a/utf8.h b/utf8.h
index 35df76086a6..cae10d5ac1f 100644
--- a/utf8.h
+++ b/utf8.h
@@ -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 *);
--
gitgitgadget
next prev parent reply other threads:[~2024-03-17 8:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-17 8:27 [PATCH 0/2] utf8: change return type of some helpers from int to size_t Mohit Marathe via GitGitGadget
2024-03-17 8:27 ` [PATCH 1/2] utf8: change type " Mohit Marathe via GitGitGadget
2024-03-21 10:30 ` Patrick Steinhardt
2024-03-17 8:27 ` Mohit Marathe via GitGitGadget [this message]
2024-03-17 16:51 ` [PATCH 0/2] utf8: change return type of some helpers " Junio C Hamano
2024-03-21 10:30 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=615481efd70fbd7e8950bea3edca12e43a024cd8.1710664071.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=mohitmarathe@proton.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).