mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: standard: add function "escape_string"
Similar to "escape_chunk", this function tries to prefix all characters tagged in the <map> with the <escape> character. The specified <string> contains the input to be escaped.
This commit is contained in:
parent
3146a4cde2
commit
1a5d06032b
@ -380,6 +380,18 @@ char *encode_chunk(char *start, char *stop,
|
||||
const char escape, const fd_set *map,
|
||||
const struct chunk *chunk);
|
||||
|
||||
/*
|
||||
* Tries to prefix characters tagged in the <map> with the <escape>
|
||||
* character. The input <string> must be zero-terminated. The result will
|
||||
* be stored between <start> (included) and <stop> (excluded). This
|
||||
* 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_string(char *start, char *stop,
|
||||
const char escape, const fd_set *map,
|
||||
const char *string);
|
||||
|
||||
/*
|
||||
* Tries to prefix characters tagged in the <map> with the <escape>
|
||||
* character. <chunk> contains the input to be escaped. The result will be
|
||||
|
@ -1470,6 +1470,36 @@ char *encode_chunk(char *start, char *stop,
|
||||
return start;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tries to prefix characters tagged in the <map> with the <escape>
|
||||
* character. The input <string> must be zero-terminated. The result will
|
||||
* be stored between <start> (included) and <stop> (excluded). This
|
||||
* 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_string(char *start, char *stop,
|
||||
const char escape, const fd_set *map,
|
||||
const char *string)
|
||||
{
|
||||
if (start < stop) {
|
||||
stop--; /* reserve one byte for the final '\0' */
|
||||
while (start < stop && *string != '\0') {
|
||||
if (!FD_ISSET((unsigned char)(*string), map))
|
||||
*start++ = *string;
|
||||
else {
|
||||
if (start + 2 >= stop)
|
||||
break;
|
||||
*start++ = escape;
|
||||
*start++ = *string;
|
||||
}
|
||||
string++;
|
||||
}
|
||||
*start = '\0';
|
||||
}
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user