strbuf: convert predicates to return bool
Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Jul 16, 2025 at 10:38 UTC
f006e0323ee4b407bee3e0ff241d9d3f7a03b66a
2 files changed
+20
-20
strbuf.c
+14
-14
@@ -8,55 +8,55 @@
8
#include "utf8.h"
9
#include "date.h"
10
11
-int starts_with(const char *str, const char *prefix)
11
+bool starts_with(const char *str, const char *prefix)
12
{
13
for (; ; str++, prefix++)
14
if (!*prefix)
15
- return 1;
15
+ return true;
16
else if (*str != *prefix)
17
- return 0;
17
+ return false;
18
}
19
20
-int istarts_with(const char *str, const char *prefix)
20
+bool istarts_with(const char *str, const char *prefix)
21
{
22
for (; ; str++, prefix++)
23
if (!*prefix)
24
- return 1;
24
+ return true;
25
else if (tolower(*str) != tolower(*prefix))
26
- return 0;
26
+ return false;
27
}
28
29
-int starts_with_mem(const char *str, size_t len, const char *prefix)
29
+bool starts_with_mem(const char *str, size_t len, const char *prefix)
30
{
31
const char *end = str + len;
32
for (; ; str++, prefix++) {
33
if (!*prefix)
34
- return 1;
34
+ return true;
35
else if (str == end || *str != *prefix)
36
- return 0;
36
+ return false;
37
}
38
}
39
40
-int skip_to_optional_arg_default(const char *str, const char *prefix,
40
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
41
const char **arg, const char *def)
42
{
43
const char *p;
44
45
if (!skip_prefix(str, prefix, &p))
46
- return 0;
46
+ return false;
47
48
if (!*p) {
49
if (arg)
50
*arg = def;
51
- return 1;
51
+ return true;
52
}
53
54
if (*p != '=')
55
- return 0;
55
+ return false;
56
57
if (arg)
58
*arg = p + 1;
59
- return 1;
59
+ return true;
60
}
61
62
/*
strbuf.h
+6
-6
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
660
__attribute__((format (printf, 1, 2)))
661
char *xstrfmt(const char *fmt, ...);
662
663
-int starts_with(const char *str, const char *prefix);
664
-int istarts_with(const char *str, const char *prefix);
665
-int starts_with_mem(const char *str, size_t len, const char *prefix);
663
+bool starts_with(const char *str, const char *prefix);
664
+bool istarts_with(const char *str, const char *prefix);
665
+bool starts_with_mem(const char *str, size_t len, const char *prefix);
666
667
/*
668
* If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);
678
* can be used instead of !strcmp(arg, "--key") and then
679
* skip_prefix(arg, "--key=", &arg) to parse such an option.
680
*/
681
-int skip_to_optional_arg_default(const char *str, const char *prefix,
681
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
682
const char **arg, const char *def);
683
684
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
684
+static inline bool skip_to_optional_arg(const char *str, const char *prefix,
685
const char **arg)
686
{
687
return skip_to_optional_arg_default(str, prefix, arg, "");
688
}
689
690
-static inline int ends_with(const char *str, const char *suffix)
690
+static inline bool ends_with(const char *str, const char *suffix)
691
{
692
size_t len;
693
return strip_suffix(str, suffix, &len);