Git fork

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>

authored by

Phillip Wood and committed by
Junio C Hamano
f006e032 f3ba426e

+20 -20
+14 -14
strbuf.c
··· 8 #include "utf8.h" 9 #include "date.h" 10 11 - int starts_with(const char *str, const char *prefix) 12 { 13 for (; ; str++, prefix++) 14 if (!*prefix) 15 - return 1; 16 else if (*str != *prefix) 17 - return 0; 18 } 19 20 - int istarts_with(const char *str, const char *prefix) 21 { 22 for (; ; str++, prefix++) 23 if (!*prefix) 24 - return 1; 25 else if (tolower(*str) != tolower(*prefix)) 26 - return 0; 27 } 28 29 - int 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; 35 else if (str == end || *str != *prefix) 36 - return 0; 37 } 38 } 39 40 - int 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; 47 48 if (!*p) { 49 if (arg) 50 *arg = def; 51 - return 1; 52 } 53 54 if (*p != '=') 55 - return 0; 56 57 if (arg) 58 *arg = p + 1; 59 - return 1; 60 } 61 62 /*
··· 8 #include "utf8.h" 9 #include "date.h" 10 11 + bool starts_with(const char *str, const char *prefix) 12 { 13 for (; ; str++, prefix++) 14 if (!*prefix) 15 + return true; 16 else if (*str != *prefix) 17 + return false; 18 } 19 20 + bool istarts_with(const char *str, const char *prefix) 21 { 22 for (; ; str++, prefix++) 23 if (!*prefix) 24 + return true; 25 else if (tolower(*str) != tolower(*prefix)) 26 + return false; 27 } 28 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 true; 35 else if (str == end || *str != *prefix) 36 + return false; 37 } 38 } 39 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 false; 47 48 if (!*p) { 49 if (arg) 50 *arg = def; 51 + return true; 52 } 53 54 if (*p != '=') 55 + return false; 56 57 if (arg) 58 *arg = p + 1; 59 + return true; 60 } 61 62 /*
+6 -6
strbuf.h
··· 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); 666 667 /* 668 * If the string "str" is the same as the string in "prefix", then the "arg" ··· 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, 682 const char **arg, const char *def); 683 684 - static inline int 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) 691 { 692 size_t len; 693 return strip_suffix(str, suffix, &len);
··· 660 __attribute__((format (printf, 1, 2))) 661 char *xstrfmt(const char *fmt, ...); 662 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 * can be used instead of !strcmp(arg, "--key") and then 679 * skip_prefix(arg, "--key=", &arg) to parse such an option. 680 */ 681 + bool skip_to_optional_arg_default(const char *str, const char *prefix, 682 const char **arg, const char *def); 683 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 bool ends_with(const char *str, const char *suffix) 691 { 692 size_t len; 693 return strip_suffix(str, suffix, &len);