forked from github/server
cleanup unused conde
This commit is contained in:
parent
60a86e7b2f
commit
e53a1caa08
1 changed files with 0 additions and 78 deletions
|
@ -394,81 +394,3 @@ const char *str_escape_ex(const char *str, char *buffer, size_t size, const char
|
|||
const char *str_escape(const char *str, char *buffer, size_t size) {
|
||||
return str_escape_ex(str, buffer, size, "\n\t\r\'\"\\");
|
||||
}
|
||||
|
||||
const char *str_escape_slow(const char *str, char *buffer, size_t size) {
|
||||
const char *read = str;
|
||||
char *write = buffer;
|
||||
if (size < 1) return NULL;
|
||||
while (size > 1 && *read) {
|
||||
size_t len;
|
||||
const char *pos = read;
|
||||
while (pos + 1 < read + size && *pos) {
|
||||
unsigned char ch = *(unsigned char *)pos;
|
||||
if (iscntrl(ch) || ch == '\"' || ch == '\\' || ch == '\'' || ch == '\n' || ch == '\r' || ch == '\t') {
|
||||
len = pos - read;
|
||||
memmove(write, read, len);
|
||||
write += len;
|
||||
size -= len;
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
if (size > 2) {
|
||||
*write++ = '\\';
|
||||
*write++ = 't';
|
||||
size -= 2;
|
||||
}
|
||||
else size = 1;
|
||||
break;
|
||||
case '\n':
|
||||
if (size > 2) {
|
||||
*write++ = '\\';
|
||||
*write++ = 'n';
|
||||
size -= 2;
|
||||
}
|
||||
else size = 1;
|
||||
break;
|
||||
case '\r':
|
||||
if (size > 2) {
|
||||
*write++ = '\\';
|
||||
*write++ = 'r';
|
||||
size -= 2;
|
||||
}
|
||||
else size = 1;
|
||||
break;
|
||||
case '\"':
|
||||
case '\'':
|
||||
case '\\':
|
||||
if (size > 2) {
|
||||
*write++ = '\\';
|
||||
*write++ = ch;
|
||||
size -= 2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (size > 5) {
|
||||
int n = sprintf(write, "\\%03o", ch);
|
||||
if (n > 0) {
|
||||
assert(n == 5);
|
||||
write += n;
|
||||
size -= n;
|
||||
}
|
||||
else size = 1;
|
||||
}
|
||||
else size = 1;
|
||||
}
|
||||
assert(size > 0);
|
||||
read = pos + 1;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
if (read < pos) {
|
||||
len = pos - read;
|
||||
memmove(write, read, len);
|
||||
read = pos;
|
||||
write += len;
|
||||
size -= len;
|
||||
}
|
||||
}
|
||||
*write = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue