MINOR: standard: add function "encode_chunk"
This function has the same behavior as encode_string(), except it
takes a "struct chunk" instead of a "char *" on input.
diff --git a/src/standard.c b/src/standard.c
index adaba75..46c940d 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -21,6 +21,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <common/chunk.h>
#include <common/config.h>
#include <common/standard.h>
#include <eb32tree.h>
@@ -1045,6 +1046,36 @@
return start;
}
+/*
+ * Same behavior as encode_string() above, except that it encodes chunk
+ * <chunk> instead of a string.
+ */
+char *encode_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 + 3 >= stop)
+ break;
+ *start++ = escape;
+ *start++ = hextab[(*str >> 4) & 15];
+ *start++ = hextab[*str & 15];
+ }
+ str++;
+ }
+ *start = '\0';
+ }
+ return start;
+}
+
/* Decode an URL-encoded string in-place. The resulting string might
* be shorter. If some forbidden characters are found, the conversion is
* aborted, the string is truncated before the issue and a negative value is