Shows how to control formatting of flow styles.
5351{
5352
5355 };
5358 };
5360
5362 "{" "\n"
5363 " map: {" "\n"
5364 " seq: [" "\n"
5365 " 0," "\n"
5366 " 1," "\n"
5367 " 2," "\n"
5368 " 3," "\n"
5369 " [40,41]" "\n"
5370 " ]" "\n"
5371 " }" "\n"
5372 "}" "\n"
5373 "";
5374
5375
5376 {
5378 CHECK(tree[
"map"].is_flow_ml1());
5379 CHECK(tree[
"map"][
"seq"].is_flow_ml1());
5380 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5381
5382 CHECK(tostr(tree, emit_defaults) == yaml);
5383
5384 CHECK(tostr_json(tree, emit_defaults) ==
5385 "{" "\n"
5386 " \"map\": {" "\n"
5387 " \"seq\": [" "\n"
5388 " 0," "\n"
5389 " 1," "\n"
5390 " 2," "\n"
5391 " 3," "\n"
5392 " [40,41]" "\n"
5393 " ]" "\n"
5394 " }" "\n"
5395 "}" "\n"
5396 "");
5397 }
5398
5399
5400
5401 {
5405 CHECK(tree[
"map"].is_flow_sl());
5406
5407 CHECK(tostr(tree, emit_defaults) ==
5408 "{map: {seq: [0,1,2,3,[40,41]]}}");
5409
5410 CHECK(tostr_json(tree, emit_defaults) ==
5411 "{\"map\": {\"seq\": [0,1,2,3,[40,41]]}}");
5412
5413
5416 CHECK(tostr(tree, with_spaces) ==
5417 "{map: {seq: [0, 1, 2, 3, [40, 41]]}}");
5418
5419 CHECK(tostr_json(tree, with_spaces) ==
5420 "{\"map\": {\"seq\": [0, 1, 2, 3, [40, 41]]}}");
5421 }
5422
5423
5424
5425 {
5429 CHECK(tree[
"map"].is_flow_mln());
5430 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5431 CHECK(tostr(tree, emit_defaults) ==
5432 "{" "\n"
5433 " map: {" "\n"
5434 " seq: [" "\n"
5435 " 0,1,2,3,[40,41]" "\n"
5436 " ]" "\n"
5437 " }" "\n"
5438 "}" "\n");
5439 CHECK(tostr_json(tree, emit_defaults) ==
5440 "{" "\n"
5441 " \"map\": {" "\n"
5442 " \"seq\": [" "\n"
5443 " 0,1,2,3,[40,41]" "\n"
5444 " ]" "\n"
5445 " }" "\n"
5446 "}" "\n");
5447
5450 CHECK(tostr(tree, with_spaces) ==
5451 "{" "\n"
5452 " map: {" "\n"
5453 " seq: [" "\n"
5454 " 0, 1, 2, 3, [40, 41]" "\n"
5455 " ]" "\n"
5456 " }" "\n"
5457 "}" "\n");
5458 CHECK(tostr_json(tree, with_spaces) ==
5459 "{" "\n"
5460 " \"map\": {" "\n"
5461 " \"seq\": [" "\n"
5462 " 0, 1, 2, 3, [40, 41]" "\n"
5463 " ]" "\n"
5464 " }" "\n"
5465 "}" "\n");
5466 }
5467
5468
5469 {
5473 CHECK(tree[
"map"].is_flow_ml1());
5474 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5475 CHECK(tostr(tree, noindent) ==
""
5476 "{" "\n"
5477 "map: {" "\n"
5478 "seq: [" "\n"
5479 "0," "\n"
5480 "1," "\n"
5481 "2," "\n"
5482 "3," "\n"
5483 "[40,41]" "\n"
5484 "]" "\n"
5485 "}" "\n"
5486 "}" "\n"
5487 "");
5488 CHECK(tostr_json(tree, noindent) ==
""
5489 "{" "\n"
5490 "\"map\": {" "\n"
5491 "\"seq\": [" "\n"
5492 "0," "\n"
5493 "1," "\n"
5494 "2," "\n"
5495 "3," "\n"
5496 "[40,41]" "\n"
5497 "]" "\n"
5498 "}" "\n"
5499 "}" "\n"
5500 "");
5501 }
5502
5503 {
5504
5506 "[" "\n"
5507 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9," "\n"
5508 " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, " "\n"
5509 " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, " "\n"
5510 " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, " "\n"
5511 " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, " "\n"
5512 " 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, " "\n"
5513 " 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, " "\n"
5514 " 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 " "\n"
5515 "]";
5516
5517
5518
5519
5524
5525 CHECK(tostr(tree, emit_defaults) ==
""
5526 "[\n"
5527 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,\n"
5528 " 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,\n"
5529 " 56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79\n"
5530 "]\n"
5531 "");
5532 CHECK(tostr_json(tree, emit_defaults) ==
""
5533 "[\n"
5534 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,\n"
5535 " 29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,\n"
5536 " 55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79\n"
5537 "]\n"
5538 "");
5539
5542 CHECK(tostr(tree, maxcols40) ==
""
5543 "[\n"
5544 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n"
5545 " 16,17,18,19,20,21,22,23,24,25,26,27,28,\n"
5546 " 29,30,31,32,33,34,35,36,37,38,39,40,41,\n"
5547 " 42,43,44,45,46,47,48,49,50,51,52,53,54,\n"
5548 " 55,56,57,58,59,60,61,62,63,64,65,66,67,\n"
5549 " 68,69,70,71,72,73,74,75,76,77,78,79\n"
5550 "]\n"
5551 "");
5552 CHECK(tostr_json(tree, maxcols40) ==
""
5553 "[\n"
5554 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n"
5555 " 16,17,18,19,20,21,22,23,24,25,26,27,28,\n"
5556 " 29,30,31,32,33,34,35,36,37,38,39,40,41,\n"
5557 " 42,43,44,45,46,47,48,49,50,51,52,53,54,\n"
5558 " 55,56,57,58,59,60,61,62,63,64,65,66,67,\n"
5559 " 68,69,70,71,72,73,74,75,76,77,78,79\n"
5560 "]\n"
5561 "");
5562
5563
5566 CHECK(tostr(tree, with_spaces) ==
""
5567 "[\n"
5568 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5569 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5570 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5571 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79\n"
5572 "]\n"
5573 "");
5574 CHECK(tostr_json(tree, with_spaces) ==
""
5575 "[\n"
5576 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5577 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5578 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5579 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79\n"
5580 "]\n"
5581 "");
5582
5586 CHECK(tostr(tree, maxcols40_spc) ==
""
5587 "[\n"
5588 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\n"
5589 " 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5590 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,\n"
5591 " 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5592 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n"
5593 " 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5594 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,\n"
5595 " 72, 73, 74, 75, 76, 77, 78, 79\n"
5596 "]\n"
5597 "");
5598 CHECK(tostr_json(tree, maxcols40_spc) ==
""
5599 "[\n"
5600 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\n"
5601 " 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5602 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,\n"
5603 " 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5604 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n"
5605 " 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5606 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,\n"
5607 " 72, 73, 74, 75, 76, 77, 78, 79\n"
5608 "]\n"
5609 "");
5610
5615 CHECK(tostr(tree, maxcols40_spc_noindent) ==
""
5616 "[\n"
5617 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,\n"
5618 "13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\n"
5619 "23, 24, 25, 26, 27, 28, 29, 30, 31, 32,\n"
5620 "33, 34, 35, 36, 37, 38, 39, 40, 41, 42,\n"
5621 "43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n"
5622 "53, 54, 55, 56, 57, 58, 59, 60, 61, 62,\n"
5623 "63, 64, 65, 66, 67, 68, 69, 70, 71, 72,\n"
5624 "73, 74, 75, 76, 77, 78, 79\n"
5625 "]\n"
5626 "");
5627 CHECK(tostr_json(tree, maxcols40_spc_noindent) ==
""
5628 "[\n"
5629 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,\n"
5630 "13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\n"
5631 "23, 24, 25, 26, 27, 28, 29, 30, 31, 32,\n"
5632 "33, 34, 35, 36, 37, 38, 39, 40, 41, 42,\n"
5633 "43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n"
5634 "53, 54, 55, 56, 57, 58, 59, 60, 61, 62,\n"
5635 "63, 64, 65, 66, 67, 68, 69, 70, 71, 72,\n"
5636 "73, 74, 75, 76, 77, 78, 79\n"
5637 "]\n"
5638 "");
5639 }
5640
5641
5642
5643}
substr emitrs_json(Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
(1) emit+resize: emit JSON to the given std::string/std::vector<char>-like container,...
bool indent_flow_ml() const noexcept
Indent the contents of FLOW_ML1 and FLOW_MLN containers.
EmitOptions & force_flow_spc(bool enabled) noexcept
Force everywhere a space after comma in flow mode, overriding the FLOW_SPC status of individual conta...
bool is_flow_mln() const noexcept
Options to give to the ParseEngine to control its behavior.
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of flow multiline container style.
ParserOptions & flow_ml_style(NodeType style) noexcept
choose the default style of multiline flow containers, when a container is detected as flow multiline...
NodeType type() const RYML_NOEXCEPT
Forward to Tree::type().