diff --git a/src/flb_sds.c b/src/flb_sds.c index 1d8263b3432..4ac36ad22e8 100644 --- a/src/flb_sds.c +++ b/src/flb_sds.c @@ -331,106 +331,6 @@ flb_sds_t flb_sds_cat_utf8(flb_sds_t *sds, const char *str, int str_len) flb_sds_len_set(s, offset); s[head->len] = '\0'; return s; - - - - for (i = 0; i < str_len; i++) { - if (flb_sds_avail(s) < 8) { - tmp = flb_sds_increase(s, 8); - if (tmp == NULL) { - return NULL; - } - *sds = s = tmp; - head = FLB_SDS_HEADER(s); - } - - c = (unsigned char)str[i]; - if (c == '\\' || c == '"') { - s[head->len++] = '\\'; - s[head->len++] = c; - } - else if (c >= '\b' && c <= '\r') { - s[head->len++] = '\\'; - switch (c) { - case '\n': - s[head->len++] = 'n'; - break; - case '\t': - s[head->len++] = 't'; - break; - case '\b': - s[head->len++] = 'b'; - break; - case '\f': - s[head->len++] = 'f'; - break; - case '\r': - s[head->len++] = 'r'; - break; - case '\v': - s[head->len++] = 'u'; - s[head->len++] = '0'; - s[head->len++] = '0'; - s[head->len++] = '0'; - s[head->len++] = 'b'; - break; - } - } - else if (c < 32 || c == 0x7f) { - s[head->len++] = '\\'; - s[head->len++] = 'u'; - s[head->len++] = '0'; - s[head->len++] = '0'; - s[head->len++] = int2hex[ (unsigned char) ((c & 0xf0) >> 4)]; - s[head->len++] = int2hex[ (unsigned char) (c & 0x0f)]; - } - else if (c >= 0x80) { - hex_bytes = flb_utf8_len(str + i); - state = FLB_UTF8_ACCEPT; - cp = 0; - for (b = 0; b < hex_bytes; b++) { - p = (const unsigned char *) str + i + b; - if (p >= (unsigned char *) (str + str_len)) { - break; - } - ret = flb_utf8_decode(&state, &cp, *p); - if (ret == 0) { - break; - } - } - - if (state != FLB_UTF8_ACCEPT) { - /* Invalid UTF-8 hex, just skip utf-8 bytes */ - flb_warn("[pack] invalid UTF-8 bytes, skipping"); - break; - } - - s[head->len++] = '\\'; - s[head->len++] = 'u'; - if (cp > 0xFFFF) { - c = (unsigned char) ((cp & 0xf00000) >> 20); - if (c > 0) { - s[head->len++] = int2hex[c]; - } - c = (unsigned char) ((cp & 0x0f0000) >> 16); - if (c > 0) { - s[head->len++] = int2hex[c]; - } - } - s[head->len++] = int2hex[ (unsigned char) ((cp & 0xf000) >> 12)]; - s[head->len++] = int2hex[ (unsigned char) ((cp & 0x0f00) >> 8)]; - s[head->len++] = int2hex[ (unsigned char) ((cp & 0xf0) >> 4)]; - s[head->len++] = int2hex[ (unsigned char) (cp & 0x0f)]; - i += (hex_bytes - 1); - } - else { - s[head->len++] = c; - } - } - - s[head->len] = '\0'; - - return s; } flb_sds_t flb_sds_printf(flb_sds_t *sds, const char *fmt, ...)