From 956623157f828b2b4fd91a9bc5e78ba8e42437d9 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 1 Dec 2013 08:49:16 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- vcs-svn/fast_export.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'vcs-svn') diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c index f2b23c81d..bd0f2c2b8 100644 --- a/vcs-svn/fast_export.c +++ b/vcs-svn/fast_export.c @@ -162,22 +162,13 @@ static void die_short_read(struct line_buffer *input) die("invalid dump: unexpected end of file"); } -static int ends_with(const char *s, size_t len, const char *suffix) -{ - const size_t suffixlen = strlen(suffix); - if (len < suffixlen) - return 0; - return !memcmp(s + len - suffixlen, suffix, suffixlen); -} - static int parse_cat_response_line(const char *header, off_t *len) { - size_t headerlen = strlen(header); uintmax_t n; const char *type; const char *end; - if (ends_with(header, headerlen, " missing")) + if (ends_with(header, " missing")) return error("cat-blob reports missing blob: %s", header); type = strstr(header, " blob "); if (!type) -- cgit v1.2.1