MCPcopy Create free account
hub / github.com/boostorg/json / usingStrings

Function usingStrings

test/snippets.cpp:282–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280// end::snippet_strings_5[]
281
282void
283usingStrings()
284{
285 {
286 // tag::snippet_strings_1[]
287
288 string str1; // empty string, uses the default memory resource
289
290 string str2( make_shared_resource<monotonic_resource>() ); // empty string, uses a counted monotonic resource
291
292 // end::snippet_strings_1[]
293 }
294 {
295 // tag::snippet_strings_2[]
296
297 std::string sstr1 = "helloworld";
298 std::string sstr2 = "world";
299
300 json::string jstr1 = "helloworld";
301 json::string jstr2 = "world";
302
303 assert( jstr2.insert(0, jstr1.subview(0, 5)) == "helloworld" );
304
305 // this is equivalent to
306 assert( sstr2.insert(0, sstr1, 0, 5) == "helloworld" );
307
308 // end::snippet_strings_2[]
309 }
310 {
311 // tag::snippet_strings_3[]
312
313 std::string sstr = "hello";
314
315 json::string jstr = "hello";
316
317 assert(sstr.append({'w', 'o', 'r', 'l', 'd'}) == "helloworld");
318
319 // such syntax is inefficient, and the same can
320 // be achieved with a character array.
321
322 assert(jstr.append("world") == "helloworld");
323
324 // end::snippet_strings_3[]
325 }
326
327 {
328 // tag::snippet_strings_4[]
329
330 json::string str = "Boost.JSON";
331 json::string_view sv = str;
332
333 // all of these call compare(string_view)
334 str.compare(sv);
335
336 str.compare(sv.substr(0, 5));
337
338 str.compare(str);
339

Callers 1

runMethod · 0.85

Calls 5

greetingFunction · 0.85
subviewMethod · 0.80
insertMethod · 0.45
appendMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected