Skip to content

Commit f006e03

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3ba426 commit f006e03

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

strbuf.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,55 @@
88
#include "utf8.h"
99
#include "date.h"
1010

11-
int starts_with(const char *str, const char *prefix)
11+
bool starts_with(const char *str, const char *prefix)
1212
{
1313
for (; ; str++, prefix++)
1414
if (!*prefix)
15-
return 1;
15+
return true;
1616
else if (*str != *prefix)
17-
return 0;
17+
return false;
1818
}
1919

20-
int istarts_with(const char *str, const char *prefix)
20+
bool istarts_with(const char *str, const char *prefix)
2121
{
2222
for (; ; str++, prefix++)
2323
if (!*prefix)
24-
return 1;
24+
return true;
2525
else if (tolower(*str) != tolower(*prefix))
26-
return 0;
26+
return false;
2727
}
2828

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)
3030
{
3131
const char *end = str + len;
3232
for (; ; str++, prefix++) {
3333
if (!*prefix)
34-
return 1;
34+
return true;
3535
else if (str == end || *str != *prefix)
36-
return 0;
36+
return false;
3737
}
3838
}
3939

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,
4141
const char **arg, const char *def)
4242
{
4343
const char *p;
4444

4545
if (!skip_prefix(str, prefix, &p))
46-
return 0;
46+
return false;
4747

4848
if (!*p) {
4949
if (arg)
5050
*arg = def;
51-
return 1;
51+
return true;
5252
}
5353

5454
if (*p != '=')
55-
return 0;
55+
return false;
5656

5757
if (arg)
5858
*arg = p + 1;
59-
return 1;
59+
return true;
6060
}
6161

6262
/*

strbuf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
660660
__attribute__((format (printf, 1, 2)))
661661
char *xstrfmt(const char *fmt, ...);
662662

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);
666666

667667
/*
668668
* 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);
678678
* can be used instead of !strcmp(arg, "--key") and then
679679
* skip_prefix(arg, "--key=", &arg) to parse such an option.
680680
*/
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,
682682
const char **arg, const char *def);
683683

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,
685685
const char **arg)
686686
{
687687
return skip_to_optional_arg_default(str, prefix, arg, "");
688688
}
689689

690-
static inline int ends_with(const char *str, const char *suffix)
690+
static inline bool ends_with(const char *str, const char *suffix)
691691
{
692692
size_t len;
693693
return strip_suffix(str, suffix, &len);

0 commit comments

Comments
 (0)