aboutsummaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-11 10:31:05 -0700
committerJunio C Hamano <gitster@pobox.com>2016-07-11 10:31:05 -0700
commit3c5de5c77b0718b47010b146160ecff6309f86b5 (patch)
tree10dfe3c6e701fab8fee60d0059a07b72cfd34c59 /git-compat-util.h
parentbb2d8a817df91c68742e10ace2a791de176f7247 (diff)
parent9dc3515cf005639317fb95492b3157aadf056923 (diff)
downloadgit-3c5de5c77b0718b47010b146160ecff6309f86b5.tar.gz
git-3c5de5c77b0718b47010b146160ecff6309f86b5.tar.xz
Merge branch 'jk/ansi-color'
The output coloring scheme learned two new attributes, italic and strike, in addition to existing bold, reverse, etc. * jk/ansi-color: color: support strike-through attribute color: support "italic" attribute color: allow "no-" for negating attributes color: refactor parse_attr add skip_prefix_mem helper doc: refactor description of color format color: fix max-size comment
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 49d4029b8..c99cddc54 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -474,6 +474,23 @@ static inline int skip_prefix(const char *str, const char *prefix,
}
/*
+ * Like skip_prefix, but promises never to read past "len" bytes of the input
+ * buffer, and returns the remaining number of bytes in "out" via "outlen".
+ */
+static inline int skip_prefix_mem(const char *buf, size_t len,
+ const char *prefix,
+ const char **out, size_t *outlen)
+{
+ size_t prefix_len = strlen(prefix);
+ if (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {
+ *out = buf + prefix_len;
+ *outlen = len - prefix_len;
+ return 1;
+ }
+ return 0;
+}
+
+/*
* If buf ends with suffix, return 1 and subtract the length of the suffix
* from *len. Otherwise, return 0 and leave *len untouched.
*/