summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-05-22 09:30:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-05-27 16:59:21 (GMT)
commitd4241f52d1a19bf464d63cbc4cd67fcc6a3af01d (patch)
tree470748d39f2a7747f0b892a38cf374c55b4b3e6f /strbuf.c
parente31316263af98c4583be39b469f3152a23eba91d (diff)
downloadgit-d4241f52d1a19bf464d63cbc4cd67fcc6a3af01d.zip
git-d4241f52d1a19bf464d63cbc4cd67fcc6a3af01d.tar.gz
git-d4241f52d1a19bf464d63cbc4cd67fcc6a3af01d.tar.bz2
strbuf: add strbuf_reencode helper
This is a convenience wrapper around `reencode_string_len` and `strbuf_attach`. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index ee96dcf..fc7290f 100644
--- 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)
{
@@ -106,6 +107,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;
+}
+
struct strbuf **strbuf_split_buf(const char *str, size_t slen,
int terminator, int max)
{