Skip to content

Commit

Permalink
sds: utf8: remove dead code
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Dec 13, 2024
1 parent 8aba382 commit 362ca1f
Showing 1 changed file with 0 additions and 100 deletions.
100 changes: 0 additions & 100 deletions src/flb_sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down

0 comments on commit 362ca1f

Please sign in to comment.