diff options
author | wm4 <wm4@nowhere> | 2013-12-30 22:45:40 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-30 22:49:51 +0100 |
commit | 7639e05ea80f565ff8fc3c7990e35da64be2ae02 (patch) | |
tree | 40d43c8d9815bb519df88b2480c5b8afcc79529c | |
parent | b0efd3f36a3d2c72a8682d6a2b97925716ff9ba5 (diff) | |
download | mpv-7639e05ea80f565ff8fc3c7990e35da64be2ae02.tar.bz2 mpv-7639e05ea80f565ff8fc3c7990e35da64be2ae02.tar.xz |
bstr: use mp_append_utf8_bstr()
Drop usage of the ugly PUT_UTF8() macro.
-rw-r--r-- | bstr/bstr.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/bstr/bstr.c b/bstr/bstr.c index 730b7474b8..c0826625c0 100644 --- a/bstr/bstr.c +++ b/bstr/bstr.c @@ -25,6 +25,7 @@ #include "talloc.h" +#include "common/common.h" #include "bstr/bstr.h" int bstrcmp(struct bstr str1, struct bstr str2) @@ -318,13 +319,6 @@ int bstr_validate_utf8(struct bstr s) return 0; } -static void append_bstr(bstr *buf, bstr s) -{ - buf->start = talloc_realloc(NULL, buf->start, unsigned char, buf->len + s.len); - memcpy(buf->start + buf->len, s.start, s.len); - buf->len += s.len; -} - struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s) { bstr new = {0}; @@ -333,13 +327,8 @@ struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s) while (left.len) { int r = bstr_decode_utf8(left, &left); if (r < 0) { - append_bstr(&new, (bstr){first_ok, left.start - first_ok}); - uint32_t codepoint = (unsigned char)left.start[0]; - char data[8]; - uint8_t tmp; - char *output = data; - PUT_UTF8(codepoint, tmp, *output++ = tmp;); - append_bstr(&new, (bstr){data, output - data}); + bstr_xappend(talloc_ctx, &new, (bstr){first_ok, left.start - first_ok}); + mp_append_utf8_bstr(talloc_ctx, &new, (unsigned char)left.start[0]); left.start += 1; left.len -= 1; first_ok = left.start; @@ -348,11 +337,7 @@ struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s) if (!new.start) return s; if (first_ok != left.start) - append_bstr(&new, (bstr){first_ok, left.start - first_ok}); - // For convenience - append_bstr(&new, (bstr){"\0", 1}); - new.len -= 1; - talloc_steal(talloc_ctx, new.start); + bstr_xappend(talloc_ctx, &new, (bstr){first_ok, left.start - first_ok}); return new; } |