Merge branch 'rs/blame-refactor'
[gitweb.git] / strbuf.c
index c8217755e541f05281d10e07517602f0fdcbde42..ac62982e672c22457468f601b35716dc9a52a81c 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "refs.h"
+#include "utf8.h"
 
 int starts_with(const char *str, const char *prefix)
 {
@@ -99,6 +100,22 @@ void strbuf_ltrim(struct strbuf *sb)
        sb->buf[sb->len] = '\0';
 }
 
+int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
+{
+       char *out;
+       int len;
+
+       if (same_encoding(from, to))
+               return 0;
+
+       out = reencode_string_len(sb->buf, sb->len, to, from, &len);
+       if (!out)
+               return -1;
+
+       strbuf_attach(sb, out, len, len);
+       return 0;
+}
+
 void strbuf_tolower(struct strbuf *sb)
 {
        char *p = sb->buf, *end = sb->buf + sb->len;