Re: [PATCH 2/3] git-compat-util: convert string predicates to return bool
- From
Elijah Newren <newren@gmail.com>
- Date
- Jul 14, 2025, 17:20 UTC
- Message-ID
- <CABPp-BEH9rtdPcS9hEXSdCqwydcWbakT59OuQOFUU7DGjPzdVw@mail.gmail.com>
- In-Reply-To
- <a0f9182aa20d0f956072a3d185a2d1288f1bd842.1752499610.git.phillip.wood@dunelm.org.uk>
On Mon, Jul 14, 2025 at 6:32 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 6 quoted lines
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
> to bool, 2023-12-16) a number of our sting predicates have been
> returning bool instead of int. Now we've declared that experimentNow we've -> Now that we've
> a success lets convert the return type the case independent
success lets -> success, let's type the -> type of the
> skip_iprefix() and skip_iprefix_mem() functions to match the return > type of their case dependent equivalents. Returning bool instead of
I wonder if case-independent and case-dependent should be hyphenated, or as separate words as you had them. Anyone know?
Show 55 quoted lines
> int makes it clear that these functions are predicates.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> git-compat-util.h | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 5bd69ec0403..9408f463e31 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)
> * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
> * locale-specific conversions).
> */
> -static inline int skip_iprefix(const char *str, const char *prefix,
> +static inline bool skip_iprefix(const char *str, const char *prefix,
> const char **out)
> {
> do {
> if (!*prefix) {
> *out = str;
> - return 1;
> + return true;
> }
> } while (tolower(*str++) == tolower(*prefix++));
> - return 0;
> + return false;
> }
>
> /*
> * Like skip_prefix_mem, but compare case-insensitively. Note that the
> * comparison is done via tolower(), so it is strictly ASCII (no multi-byte
> * characters or locale-specific conversions).
> */
> -static inline int skip_iprefix_mem(const char *buf, size_t len,
> +static inline bool skip_iprefix_mem(const char *buf, size_t len,
> const char *prefix,
> const char **out, size_t *outlen)
> {
> do {
> if (!*prefix) {
> *out = buf;
> *outlen = len;
> - return 1;
> + return true;
> }
> } while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));
> - return 0;
> + return false;
> }
>
> static inline int strtoul_ui(char const *s, int base, unsigned int *result)
> --
> 2.49.0.897.gfad3eb7d210Patch looks good.