aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_string.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2014-12-12 20:25:35 +0300
committerValentin Bartenev <vbart@nginx.com>2014-12-12 20:25:35 +0300
commit5453f0afe6be1ee3d405ea825cf1de797419b4b7 (patch)
tree71ae2106c4811843b07d03a07acef564360c08d6 /src/core/ngx_string.c
parent921f72852690320189bd9414da9c96bf4c63eeb0 (diff)
downloadnginx-5453f0afe6be1ee3d405ea825cf1de797419b4b7.tar.gz
nginx-5453f0afe6be1ee3d405ea825cf1de797419b4b7.zip
Autoindex: implemented JSON output format.
Diffstat (limited to 'src/core/ngx_string.c')
-rw-r--r--src/core/ngx_string.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 9d854fa0e..a41c38d37 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -1773,6 +1773,58 @@ ngx_escape_html(u_char *dst, u_char *src, size_t size)
}
+uintptr_t
+ngx_escape_json(u_char *dst, u_char *src, size_t size)
+{
+ u_char ch;
+ ngx_uint_t len;
+
+ if (dst == NULL) {
+ len = 0;
+
+ while (size) {
+ ch = *src++;
+
+ if (ch == '\\' || ch == '"') {
+ len++;
+
+ } else if (ch <= 0x1f) {
+ len += sizeof("\\u001F") - 2;
+ }
+
+ size--;
+ }
+
+ return (uintptr_t) len;
+ }
+
+ while (size) {
+ ch = *src++;
+
+ if (ch > 0x1f) {
+
+ if (ch == '\\' || ch == '"') {
+ *dst++ = '\\';
+ }
+
+ *dst++ = ch;
+
+ } else {
+ *dst++ = '\\'; *dst++ = 'u'; *dst++ = '0'; *dst++ = '0';
+ *dst++ = '0' + (ch >> 4);
+
+ ch &= 0xf;
+
+ *dst++ = (ch < 10) ? ('0' + ch) : ('A' + ch - 10);
+ }
+
+ size--;
+ }
+
+ return (uintptr_t) dst;
+}
+
+
void
ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)