| 280 | // end::snippet_strings_5[] |
| 281 | |
| 282 | void |
| 283 | usingStrings() |
| 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 | |