version 1.1, 2013/10/14 10:32:48
|
version 1.1.1.3, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "array.h" |
#include "array.h" |
|
|
#include <string.h> |
#include <string.h> |
Line 9 static data_unset *data_string_copy(const data_unset *
|
Line 11 static data_unset *data_string_copy(const data_unset *
|
data_string *src = (data_string *)s; |
data_string *src = (data_string *)s; |
data_string *ds = data_string_init(); |
data_string *ds = data_string_init(); |
|
|
buffer_copy_string_buffer(ds->key, src->key); | buffer_copy_buffer(ds->key, src->key); |
buffer_copy_string_buffer(ds->value, src->value); | buffer_copy_buffer(ds->value, src->value); |
ds->is_index_key = src->is_index_key; |
ds->is_index_key = src->is_index_key; |
return (data_unset *)ds; |
return (data_unset *)ds; |
} |
} |
Line 36 static int data_string_insert_dup(data_unset *dst, dat
|
Line 38 static int data_string_insert_dup(data_unset *dst, dat
|
data_string *ds_dst = (data_string *)dst; |
data_string *ds_dst = (data_string *)dst; |
data_string *ds_src = (data_string *)src; |
data_string *ds_src = (data_string *)src; |
|
|
if (ds_dst->value->used) { | if (!buffer_is_empty(ds_dst->value)) { |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", ")); |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(", ")); |
buffer_append_string_buffer(ds_dst->value, ds_src->value); |
buffer_append_string_buffer(ds_dst->value, ds_src->value); |
} else { |
} else { |
buffer_copy_string_buffer(ds_dst->value, ds_src->value); | buffer_copy_buffer(ds_dst->value, ds_src->value); |
} |
} |
|
|
src->free(src); |
src->free(src); |
Line 52 static int data_response_insert_dup(data_unset *dst, d
|
Line 54 static int data_response_insert_dup(data_unset *dst, d
|
data_string *ds_dst = (data_string *)dst; |
data_string *ds_dst = (data_string *)dst; |
data_string *ds_src = (data_string *)src; |
data_string *ds_src = (data_string *)src; |
|
|
if (ds_dst->value->used) { | if (!buffer_is_empty(ds_dst->value)) { |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN("\r\n")); |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN("\r\n")); |
buffer_append_string_buffer(ds_dst->value, ds_dst->key); |
buffer_append_string_buffer(ds_dst->value, ds_dst->key); |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(": ")); |
buffer_append_string_len(ds_dst->value, CONST_STR_LEN(": ")); |
buffer_append_string_buffer(ds_dst->value, ds_src->value); |
buffer_append_string_buffer(ds_dst->value, ds_src->value); |
} else { |
} else { |
buffer_copy_string_buffer(ds_dst->value, ds_src->value); | buffer_copy_buffer(ds_dst->value, ds_src->value); |
} |
} |
|
|
src->free(src); |
src->free(src); |
Line 69 static int data_response_insert_dup(data_unset *dst, d
|
Line 71 static int data_response_insert_dup(data_unset *dst, d
|
|
|
static void data_string_print(const data_unset *d, int depth) { |
static void data_string_print(const data_unset *d, int depth) { |
data_string *ds = (data_string *)d; |
data_string *ds = (data_string *)d; |
unsigned int i; | size_t i, len; |
UNUSED(depth); |
UNUSED(depth); |
|
|
/* empty and uninitialized strings */ |
/* empty and uninitialized strings */ |
if (ds->value->used < 1) { | if (buffer_string_is_empty(ds->value)) { |
fputs("\"\"", stdout); |
fputs("\"\"", stdout); |
return; |
return; |
} |
} |
|
|
/* print out the string as is, except prepend " with backslash */ |
/* print out the string as is, except prepend " with backslash */ |
putc('"', stdout); |
putc('"', stdout); |
for (i = 0; i < ds->value->used - 1; i++) { | len = buffer_string_length(ds->value); |
| for (i = 0; i < len; i++) { |
unsigned char c = ds->value->ptr[i]; |
unsigned char c = ds->value->ptr[i]; |
if (c == '"') { |
if (c == '"') { |
fputs("\\\"", stdout); |
fputs("\\\"", stdout); |
Line 96 data_string *data_string_init(void) {
|
Line 99 data_string *data_string_init(void) {
|
data_string *ds; |
data_string *ds; |
|
|
ds = calloc(1, sizeof(*ds)); |
ds = calloc(1, sizeof(*ds)); |
assert(ds); | force_assert(NULL != ds); |
|
|
ds->key = buffer_init(); |
ds->key = buffer_init(); |
ds->value = buffer_init(); |
ds->value = buffer_init(); |