diff options
author | Ben Straub <bstraub@github.com> | 2012-07-17 08:08:34 -0700 |
---|---|---|
committer | Ben Straub <bstraub@github.com> | 2012-07-17 08:08:34 -0700 |
commit | bfc65634050dc52e3ed6b4497ebbb511e39d6e1e (patch) | |
tree | 32b03847b8a152b69bc3b48b6bb32e7b8621f45e /src/buffer.c | |
parent | 1d68fcd04b21a2c5665d0ca6a5543e7166c73457 (diff) | |
parent | ea5d2ce4cfa6cec89e2d844a70d1eb24bb401c7d (diff) | |
download | libgit2-bfc65634050dc52e3ed6b4497ebbb511e39d6e1e.tar.gz |
Merge branch 'development' into clone
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c index 04aaec3df..5d54ee1a5 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -141,6 +141,42 @@ int git_buf_puts(git_buf *buf, const char *string) return git_buf_put(buf, string, strlen(string)); } +int git_buf_puts_escaped( + git_buf *buf, const char *string, const char *esc_chars, const char *esc_with) +{ + const char *scan = string; + size_t total = 0, esc_with_len = strlen(esc_with); + + while (*scan) { + size_t count = strcspn(scan, esc_chars); + total += count + 1 + esc_with_len; + scan += count + 1; + } + + ENSURE_SIZE(buf, buf->size + total + 1); + + for (scan = string; *scan; ) { + size_t count = strcspn(scan, esc_chars); + + memmove(buf->ptr + buf->size, scan, count); + scan += count; + buf->size += count; + + if (*scan) { + memmove(buf->ptr + buf->size, esc_with, esc_with_len); + buf->size += esc_with_len; + + memmove(buf->ptr + buf->size, scan, 1); + scan += 1; + buf->size += 1; + } + } + + buf->ptr[buf->size] = '\0'; + + return 0; +} + int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) { int len; |