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>
maint
parent
f3ba426e35
commit
f006e0323e
28
strbuf.c
28
strbuf.c
|
|
@ -8,55 +8,55 @@
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
|
|
||||||
int starts_with(const char *str, const char *prefix)
|
bool starts_with(const char *str, const char *prefix)
|
||||||
{
|
{
|
||||||
for (; ; str++, prefix++)
|
for (; ; str++, prefix++)
|
||||||
if (!*prefix)
|
if (!*prefix)
|
||||||
return 1;
|
return true;
|
||||||
else if (*str != *prefix)
|
else if (*str != *prefix)
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int istarts_with(const char *str, const char *prefix)
|
bool istarts_with(const char *str, const char *prefix)
|
||||||
{
|
{
|
||||||
for (; ; str++, prefix++)
|
for (; ; str++, prefix++)
|
||||||
if (!*prefix)
|
if (!*prefix)
|
||||||
return 1;
|
return true;
|
||||||
else if (tolower(*str) != tolower(*prefix))
|
else if (tolower(*str) != tolower(*prefix))
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int starts_with_mem(const char *str, size_t len, const char *prefix)
|
bool starts_with_mem(const char *str, size_t len, const char *prefix)
|
||||||
{
|
{
|
||||||
const char *end = str + len;
|
const char *end = str + len;
|
||||||
for (; ; str++, prefix++) {
|
for (; ; str++, prefix++) {
|
||||||
if (!*prefix)
|
if (!*prefix)
|
||||||
return 1;
|
return true;
|
||||||
else if (str == end || *str != *prefix)
|
else if (str == end || *str != *prefix)
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int skip_to_optional_arg_default(const char *str, const char *prefix,
|
bool skip_to_optional_arg_default(const char *str, const char *prefix,
|
||||||
const char **arg, const char *def)
|
const char **arg, const char *def)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (!skip_prefix(str, prefix, &p))
|
if (!skip_prefix(str, prefix, &p))
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
if (!*p) {
|
if (!*p) {
|
||||||
if (arg)
|
if (arg)
|
||||||
*arg = def;
|
*arg = def;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*p != '=')
|
if (*p != '=')
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
if (arg)
|
if (arg)
|
||||||
*arg = p + 1;
|
*arg = p + 1;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
12
strbuf.h
12
strbuf.h
|
|
@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
|
||||||
__attribute__((format (printf, 1, 2)))
|
__attribute__((format (printf, 1, 2)))
|
||||||
char *xstrfmt(const char *fmt, ...);
|
char *xstrfmt(const char *fmt, ...);
|
||||||
|
|
||||||
int starts_with(const char *str, const char *prefix);
|
bool starts_with(const char *str, const char *prefix);
|
||||||
int istarts_with(const char *str, const char *prefix);
|
bool istarts_with(const char *str, const char *prefix);
|
||||||
int starts_with_mem(const char *str, size_t len, const char *prefix);
|
bool starts_with_mem(const char *str, size_t len, const char *prefix);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the string "str" is the same as the string in "prefix", then the "arg"
|
* 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);
|
||||||
* can be used instead of !strcmp(arg, "--key") and then
|
* can be used instead of !strcmp(arg, "--key") and then
|
||||||
* skip_prefix(arg, "--key=", &arg) to parse such an option.
|
* skip_prefix(arg, "--key=", &arg) to parse such an option.
|
||||||
*/
|
*/
|
||||||
int skip_to_optional_arg_default(const char *str, const char *prefix,
|
bool skip_to_optional_arg_default(const char *str, const char *prefix,
|
||||||
const char **arg, const char *def);
|
const char **arg, const char *def);
|
||||||
|
|
||||||
static inline int skip_to_optional_arg(const char *str, const char *prefix,
|
static inline bool skip_to_optional_arg(const char *str, const char *prefix,
|
||||||
const char **arg)
|
const char **arg)
|
||||||
{
|
{
|
||||||
return skip_to_optional_arg_default(str, prefix, arg, "");
|
return skip_to_optional_arg_default(str, prefix, arg, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ends_with(const char *str, const char *suffix)
|
static inline bool ends_with(const char *str, const char *suffix)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
return strip_suffix(str, suffix, &len);
|
return strip_suffix(str, suffix, &len);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue