]> git.ipfire.org Git - thirdparty/git.git/blobdiff - strbuf.c
strbuf API additions and enhancements.
[thirdparty/git.git] / strbuf.c
index 59383ac7763dd58ba8da1c1daea6906740affea0..dcb725dcdd2f8edb04502fed425bd3b7a7204ebf 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -50,16 +50,6 @@ void strbuf_rtrim(struct strbuf *sb)
        sb->buf[sb->len] = '\0';
 }
 
-void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len)
-{
-       strbuf_grow(sb, len);
-       if (pos > sb->len)
-               die("`pos' is too far after the end of the buffer");
-       memmove(sb->buf + pos + len, sb->buf + pos, sb->len - pos);
-       memcpy(sb->buf + pos, data, len);
-       strbuf_setlen(sb, sb->len + len);
-}
-
 void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
                                   const void *data, size_t dlen)
 {
@@ -79,6 +69,16 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
        strbuf_setlen(sb, sb->len + dlen - len);
 }
 
+void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len)
+{
+       strbuf_splice(sb, pos, 0, data, len);
+}
+
+void strbuf_remove(struct strbuf *sb, size_t pos, size_t len)
+{
+       strbuf_splice(sb, pos, len, NULL, 0);
+}
+
 void strbuf_add(struct strbuf *sb, const void *data, size_t len)
 {
        strbuf_grow(sb, len);