git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/3] strbuf: convert predicates to return bool

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 16, 2025, 09:38 UTC
Message-ID
<80e5cd3b9df80cbda58630cae20ff7ca44793d8f.1752658700.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1752658700.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

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>
---
 strbuf.c | 28 ++++++++++++++--------------
 strbuf.h | 12 ++++++------
 2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index f30fdc69843..6c3851a7f84 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,55 +8,55 @@
 #include "utf8.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++)
 		if (!*prefix)
-			return 1;
+			return true;
 		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++)
 		if (!*prefix)
-			return 1;
+			return true;
 		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;
 	for (; ; str++, prefix++) {
 		if (!*prefix)
-			return 1;
+			return true;
 		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 *p;
 
 	if (!skip_prefix(str, prefix, &p))
-		return 0;
+		return false;
 
 	if (!*p) {
 		if (arg)
 			*arg = def;
-		return 1;
+		return true;
 	}
 
 	if (*p != '=')
-		return 0;
+		return false;
 
 	if (arg)
 		*arg = p + 1;
-	return 1;
+	return true;
 }
 
 /*
diff --git a/strbuf.h b/strbuf.h
index 6362777c0a0..a580ac6084b 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
 __attribute__((format (printf, 1, 2)))
 char *xstrfmt(const char *fmt, ...);
 
-int starts_with(const char *str, const char *prefix);
-int istarts_with(const char *str, const char *prefix);
-int starts_with_mem(const char *str, size_t len, const char *prefix);
+bool starts_with(const char *str, const char *prefix);
+bool istarts_with(const char *str, 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"
@@ -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
  * 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);
 
-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)
 {
 	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;
 	return strip_suffix(str, suffix, &len);
-- 
2.49.0.897.gfad3eb7d210
Previous: Karthik NayakNext: Karthik Nayak
Message 29 of 33 in “C99: declare bool experiment a success”
  1. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 14, 2025
  2. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 14, 2025
  3. Junio C HamanoJul 14, 2025
  4. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 14, 2025
  5. Eric SunshineJul 14, 2025
  6. Elijah NewrenJul 14, 2025
  7. brian m. carlsonJul 14, 2025
  8. Phillip WoodJul 15, 2025
  9. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 14, 2025
  10. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 15, 2025
  11. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 15, 2025
  12. Jeff KingJul 16, 2025
  13. Jeff KingJul 16, 2025
  14. Elijah NewrenJul 16, 2025
  15. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 15, 2025
  16. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 15, 2025
  17. Elijah NewrenJul 15, 2025
  18. rsbecker@nexbridge.comJul 15, 2025
  19. Elijah NewrenJul 15, 2025
  20. rsbecker@nexbridge.comJul 15, 2025
  21. Junio C HamanoJul 15, 2025
  22. Junio C HamanoJul 15, 2025
  23. brian m. carlsonJul 15, 2025
  24. Junio C HamanoJul 15, 2025
  25. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 16, 2025
  26. 1/3 CodingGuidelines: allow the use of boolPhillip Wood, Jul 16, 2025
  27. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 16, 2025
  28. Karthik NayakJul 16, 2025
  29. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 16, 2025
  30. Karthik NayakJul 16, 2025
  31. Karthik NayakJul 16, 2025
  32. Phillip WoodJul 17, 2025
  33. Karthik NayakJul 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.