9 static data_unset
*data_string_copy(const data_unset
*s
) {
10 data_string
*src
= (data_string
*)s
;
11 data_string
*ds
= data_string_init();
13 buffer_copy_buffer(ds
->key
, src
->key
);
14 buffer_copy_buffer(ds
->value
, src
->value
);
15 ds
->is_index_key
= src
->is_index_key
;
16 return (data_unset
*)ds
;
19 static void data_string_free(data_unset
*d
) {
20 data_string
*ds
= (data_string
*)d
;
23 buffer_free(ds
->value
);
28 static void data_string_reset(data_unset
*d
) {
29 data_string
*ds
= (data_string
*)d
;
31 /* reused array elements */
32 buffer_reset(ds
->key
);
33 buffer_reset(ds
->value
);
36 static int data_string_insert_dup(data_unset
*dst
, data_unset
*src
) {
37 data_string
*ds_dst
= (data_string
*)dst
;
38 data_string
*ds_src
= (data_string
*)src
;
40 if (!buffer_is_empty(ds_dst
->value
)) {
41 buffer_append_string_len(ds_dst
->value
, CONST_STR_LEN(", "));
42 buffer_append_string_buffer(ds_dst
->value
, ds_src
->value
);
44 buffer_copy_buffer(ds_dst
->value
, ds_src
->value
);
52 static void data_string_print(const data_unset
*d
, int depth
) {
53 data_string
*ds
= (data_string
*)d
;
57 /* empty and uninitialized strings */
58 if (buffer_string_is_empty(ds
->value
)) {
59 fputs("\"\"", stdout
);
63 /* print out the string as is, except prepend " with backslash */
65 len
= buffer_string_length(ds
->value
);
66 for (i
= 0; i
< len
; i
++) {
67 unsigned char c
= ds
->value
->ptr
[i
];
69 fputs("\\\"", stdout
);
78 data_string
*data_string_init(void) {
79 static const struct data_methods fn
= {
83 data_string_insert_dup
,
88 ds
= calloc(1, sizeof(*ds
));
89 force_assert(NULL
!= ds
);
91 ds
->key
= buffer_init();
92 ds
->value
= buffer_init();
94 ds
->type
= TYPE_STRING
;