summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2013-12-01 07:49:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-12-05 22:12:52 (GMT)
commit956623157f828b2b4fd91a9bc5e78ba8e42437d9 (patch)
treeb081b8ea3eb225110374f985ca322bbb3a078156 /git-compat-util.h
parent3fb5aead2971c6181dbf143295c427175b8bf082 (diff)
downloadgit-956623157f828b2b4fd91a9bc5e78ba8e42437d9.zip
git-956623157f828b2b4fd91a9bc5e78ba8e42437d9.tar.gz
git-956623157f828b2b4fd91a9bc5e78ba8e42437d9.tar.bz2
strbuf: introduce starts_with() and ends_with()
prefixcmp() and suffixcmp() share the common "cmp" suffix that typically are used to name functions that can be used for ordering, but they can't, because they are not antisymmetric: prefixcmp("foo", "foobar") < 0 prefixcmp("foobar", "foo") == 0 We in fact do not use these functions for ordering. Replace them with functions that just check for equality. Add starts_with() and end_with() that will be used to replace prefixcmp() and suffixcmp(), respectively, as the first step. These are named after corresponding functions/methods in programming languages, like Java, Python and Ruby. In vcs-svn/fast_export.c, there was already an ends_with() function that did the same thing. Let's use the new one instead while at it. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 7776f12..b73916b 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -350,7 +350,9 @@ extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_lis
extern void set_error_routine(void (*routine)(const char *err, va_list params));
extern void set_die_is_recursing_routine(int (*routine)(void));
+extern int starts_with(const char *str, const char *prefix);
extern int prefixcmp(const char *str, const char *prefix);
+extern int ends_with(const char *str, const char *suffix);
extern int suffixcmp(const char *str, const char *suffix);
static inline const char *skip_prefix(const char *str, const char *prefix)