mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-09 06:46:55 +00:00
MINOR: standard: add function "escape_chunk"
This function tries to prefix all characters tagged in the <map> with the <escape> character. The specified <chunk> contains the input to be escaped.
This commit is contained in:
parent
1de1659923
commit
0edd10925d
@ -380,6 +380,17 @@ char *encode_chunk(char *start, char *stop,
|
|||||||
const char escape, const fd_set *map,
|
const char escape, const fd_set *map,
|
||||||
const struct chunk *chunk);
|
const struct chunk *chunk);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tries to prefix characters tagged in the <map> with the <escape>
|
||||||
|
* character. <chunk> contains the input to be escaped. The result will be
|
||||||
|
* stored between <start> (included) and <stop> (excluded). The function
|
||||||
|
* will always try to terminate the resulting string with a '\0' before
|
||||||
|
* <stop>, and will return its position if the conversion completes.
|
||||||
|
*/
|
||||||
|
char *escape_chunk(char *start, char *stop,
|
||||||
|
const char escape, const fd_set *map,
|
||||||
|
const struct chunk *chunk);
|
||||||
|
|
||||||
|
|
||||||
/* Check a string for using it in a CSV output format. If the string contains
|
/* Check a string for using it in a CSV output format. If the string contains
|
||||||
* one of the following four char <">, <,>, CR or LF, the string is
|
* one of the following four char <">, <,>, CR or LF, the string is
|
||||||
|
@ -1439,6 +1439,38 @@ char *encode_chunk(char *start, char *stop,
|
|||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tries to prefix characters tagged in the <map> with the <escape>
|
||||||
|
* character. <chunk> contains the input to be escaped. The result will be
|
||||||
|
* stored between <start> (included) and <stop> (excluded). The function
|
||||||
|
* will always try to terminate the resulting string with a '\0' before
|
||||||
|
* <stop>, and will return its position if the conversion completes.
|
||||||
|
*/
|
||||||
|
char *escape_chunk(char *start, char *stop,
|
||||||
|
const char escape, const fd_set *map,
|
||||||
|
const struct chunk *chunk)
|
||||||
|
{
|
||||||
|
char *str = chunk->str;
|
||||||
|
char *end = chunk->str + chunk->len;
|
||||||
|
|
||||||
|
if (start < stop) {
|
||||||
|
stop--; /* reserve one byte for the final '\0' */
|
||||||
|
while (start < stop && str < end) {
|
||||||
|
if (!FD_ISSET((unsigned char)(*str), map))
|
||||||
|
*start++ = *str;
|
||||||
|
else {
|
||||||
|
if (start + 2 >= stop)
|
||||||
|
break;
|
||||||
|
*start++ = escape;
|
||||||
|
*start++ = *str;
|
||||||
|
}
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
*start = '\0';
|
||||||
|
}
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check a string for using it in a CSV output format. If the string contains
|
/* Check a string for using it in a CSV output format. If the string contains
|
||||||
* one of the following four char <">, <,>, CR or LF, the string is
|
* one of the following four char <">, <,>, CR or LF, the string is
|
||||||
* encapsulated between <"> and the <"> are escaped by a <""> sequence.
|
* encapsulated between <"> and the <"> are escaped by a <""> sequence.
|
||||||
|
Loading…
Reference in New Issue
Block a user