@@ -109,8 +109,8 @@ int do_list_object(string_view prefix, ObjectList& result, string* marker) {
109109 EXPECT_TRUE (key);
110110 auto size = child[" Size" ];
111111 EXPECT_TRUE (size);
112- auto text = key.to_string ();
113- auto dsize = size.to_integer ();
112+ auto text = key.to_string_view ();
113+ auto dsize = size.to_int64_t ();
114114 LOG_DEBUG (VALUE (text), VALUE (dsize));
115115 result.emplace_back (0 , DT_REG , text.substr (prefix.size ()),
116116 dsize, text.size () == prefix.size ());
@@ -123,15 +123,15 @@ int do_list_object(string_view prefix, ObjectList& result, string* marker) {
123123 for (auto child: list_bucket_result.enumerable_children (" CommonPrefixes" )) {
124124 auto key = child[" Prefix" ];
125125 EXPECT_TRUE (key);
126- auto dirname = key.to_string ();
126+ auto dirname = key.to_string_view ();
127127 if (dirname.back () == ' /' ) dirname.remove_suffix (1 );
128128 // update_stat_cache(dirname, 0, OSS_DIR_MODE);
129129 dirname.remove_prefix (prefix.size ());
130130 result.emplace_back (0 , DT_DIR , dirname, 0 , false );
131131 }
132132 if (marker) {
133133 auto next_marker = list_bucket_result[" NextMarker" ];
134- if (next_marker) *marker = next_marker.to_string ();
134+ if (next_marker) *marker = next_marker.to_string_view ();
135135 else marker->clear ();
136136 }
137137 return 0 ;
@@ -153,7 +153,7 @@ void expect_eq_kvs(Node node, const char * const * truth, size_t n) {
153153 for (size_t i = 0 ; i < n; ++i) {
154154 auto x = truth + i * 2 ;
155155 auto q = node[x[0 ]];
156- LOG_DEBUG (" expect node['`'] => '`' (got '`' )" , x[0 ], x[1 ], q.to_string ());
156+ LOG_DEBUG (" expect node['`'] => '`' (got ` )" , x[0 ], x[1 ], q.to_string_view ());
157157 EXPECT_EQ (q, x[1 ]);
158158 }
159159}
@@ -167,7 +167,7 @@ void expect_eq_vals(Node node, const char * const * truth, size_t n) {
167167 for (size_t i = 0 ; i < n; ++i) {
168168 auto x = truth[i];
169169 auto q = node[i];
170- LOG_DEBUG (" expect node[`] => '`' (got '`')" , i, x, q.to_string ());
170+ LOG_DEBUG (" expect node[`] => '`' (got '`')" , i, x, q.to_string_view ());
171171 EXPECT_EQ (q, x);
172172 }
173173}
@@ -196,8 +196,8 @@ TEST(simple_dom, json) {
196196 {" i" , " -123" },
197197 {" pi" , " 3.1416" },
198198 });
199- EXPECT_EQ (doc[" i" ].to_integer (), -123 );
200- EXPECT_NEAR (doc[" pi" ].to_number (), 3.1416 , 1e-5 );
199+ EXPECT_EQ (doc[" i" ].to_int64_t (), -123 );
200+ EXPECT_NEAR (doc[" pi" ].to_double (), 3.1416 , 1e-5 );
201201 expect_eq_vals (doc[" a" ], {" 1" , " 2" , " 3" , " 4" });
202202}
203203
@@ -241,3 +241,93 @@ I am something: indeed
241241 expect_eq_vals (doc[" bar" ], {" 20" , " 30" ,
242242 " oh so nice" , " oh so nice (serialized)" });
243243}
244+
245+ const static char example_ini[] = R"(
246+ [protocol] ; Protocol configuration
247+ version=6 ; IPv6
248+
249+ [user]
250+ name = Bob Smith ; Spaces around '=' are stripped
251+ email = bob@smith.com ; And comments (like this) ignored
252+ active = true ; Test a boolean
253+ pi = 3.14159 ; Test a floating point number
254+ trillion = 1000000000000 ; Test 64-bit integers
255+
256+ [protocol] ; Protocol configuration
257+ ver = 4 ; IPv4
258+
259+ [section1]
260+ single1 = abc
261+ single2 = xyz
262+ [section3]
263+ single: ghi
264+ multi: the quick
265+ name = bob smith ; comment line 1
266+ ; comment line 2
267+ foo = bar ;c1
268+
269+ [comment_test]
270+ test1 = 1;2;3 ; only this will be a comment
271+ test2 = 2;3;4;this won't be a comment, needs whitespace before ';'
272+ test;3 = 345 ; key should be "test;3"
273+ test4 = 4#5#6 ; '#' only starts a comment at start of line
274+ #test5 = 567 ; entire line commented
275+ # test6 = 678 ; entire line commented, except in MULTILINE mode
276+ test7 = ; blank value, except if inline comments disabled
277+ test8 =; not a comment, needs whitespace before ';'
278+
279+ [colon_tests]
280+ Content-Type: text/html
281+ foo:bar
282+ adams : 42
283+ funny1 : with = equals
284+ funny2 = with : colons
285+ funny3 = two = equals
286+ funny4 : two : colons
287+
288+
289+ )" ;
290+
291+ TEST (simple_dom, ini) {
292+ auto doc = parse_copy (example_ini, sizeof (example_ini) - 1 , DOC_INI );
293+ EXPECT_TRUE (doc);
294+ EXPECT_EQ (doc.num_children (), 6 );
295+ expect_eq_kvs (doc[" protocol" ], {
296+ {" version" , " 6" },
297+ {" ver" , " 4" },
298+ });
299+ expect_eq_kvs (doc[" user" ], {
300+ {" name" , " Bob Smith" },
301+ {" email" , " bob@smith.com" },
302+ {" active" , " true" },
303+ {" pi" , " 3.14159" },
304+ {" trillion" , " 1000000000000" },
305+ });
306+ expect_eq_kvs (doc[" section1" ], {
307+ {" single1" , " abc" },
308+ {" single2" , " xyz" },
309+ });
310+ expect_eq_kvs (doc[" section3" ], {
311+ {" single" , " ghi" },
312+ {" multi" , " the quick" },
313+ {" name" , " bob smith" },
314+ {" foo" , " bar" },
315+ });
316+ expect_eq_kvs (doc[" comment_test" ], {
317+ {" test1" , " 1;2;3" },
318+ {" test2" , " 2;3;4;this won't be a comment, needs whitespace before ';'" },
319+ {" test;3" , " 345" },
320+ {" test4" , " 4#5#6" },
321+ {" test7" , " " },
322+ {" test8" , " ; not a comment, needs whitespace before ';'" },
323+ });
324+ expect_eq_kvs (doc[" colon_tests" ], {
325+ {" Content-Type" , " text/html" },
326+ {" foo" , " bar" },
327+ {" adams" , " 42" },
328+ {" funny1" , " with = equals" },
329+ {" funny2" , " with : colons" },
330+ {" funny3" , " two = equals" },
331+ {" funny4" , " two : colons" },
332+ });
333+ }
0 commit comments