Shows how to control formatting of flow styles.
5435{
5436
5439 };
5442 };
5444
5446 "{" "\n"
5447 " map: {" "\n"
5448 " seq: [" "\n"
5449 " 0," "\n"
5450 " 1," "\n"
5451 " 2," "\n"
5452 " 3," "\n"
5453 " [40,41]" "\n"
5454 " ]" "\n"
5455 " }" "\n"
5456 "}" "\n"
5457 "";
5458
5459
5460 {
5462 CHECK(tree[
"map"].is_flow_ml1());
5463 CHECK(tree[
"map"][
"seq"].is_flow_ml1());
5464 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5465
5466 CHECK(tostr(tree, emit_defaults) == yaml);
5467
5468 CHECK(tostr_json(tree, emit_defaults) ==
5469 "{" "\n"
5470 " \"map\": {" "\n"
5471 " \"seq\": [" "\n"
5472 " 0," "\n"
5473 " 1," "\n"
5474 " 2," "\n"
5475 " 3," "\n"
5476 " [40,41]" "\n"
5477 " ]" "\n"
5478 " }" "\n"
5479 "}" "\n"
5480 "");
5481 }
5482
5483
5484
5485 {
5489 CHECK(tree[
"map"].is_flow_sl());
5490
5491 CHECK(tostr(tree, emit_defaults) ==
5492 "{map: {seq: [0,1,2,3,[40,41]]}}");
5493
5494 CHECK(tostr_json(tree, emit_defaults) ==
5495 "{\"map\": {\"seq\": [0,1,2,3,[40,41]]}}");
5496
5497
5500 CHECK(tostr(tree, with_spaces) ==
5501 "{map: {seq: [0, 1, 2, 3, [40, 41]]}}");
5502
5503 CHECK(tostr_json(tree, with_spaces) ==
5504 "{\"map\": {\"seq\": [0, 1, 2, 3, [40, 41]]}}");
5505 }
5506
5507
5508
5509 {
5513 CHECK(tree[
"map"].is_flow_mln());
5514 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5515 CHECK(tostr(tree, emit_defaults) ==
5516 "{" "\n"
5517 " map: {" "\n"
5518 " seq: [" "\n"
5519 " 0,1,2,3,[40,41]" "\n"
5520 " ]" "\n"
5521 " }" "\n"
5522 "}" "\n");
5523 CHECK(tostr_json(tree, emit_defaults) ==
5524 "{" "\n"
5525 " \"map\": {" "\n"
5526 " \"seq\": [" "\n"
5527 " 0,1,2,3,[40,41]" "\n"
5528 " ]" "\n"
5529 " }" "\n"
5530 "}" "\n");
5531
5534 CHECK(tostr(tree, with_spaces) ==
5535 "{" "\n"
5536 " map: {" "\n"
5537 " seq: [" "\n"
5538 " 0, 1, 2, 3, [40, 41]" "\n"
5539 " ]" "\n"
5540 " }" "\n"
5541 "}" "\n");
5542 CHECK(tostr_json(tree, with_spaces) ==
5543 "{" "\n"
5544 " \"map\": {" "\n"
5545 " \"seq\": [" "\n"
5546 " 0, 1, 2, 3, [40, 41]" "\n"
5547 " ]" "\n"
5548 " }" "\n"
5549 "}" "\n");
5550 }
5551
5552
5553 {
5557 CHECK(tree[
"map"].is_flow_ml1());
5558 CHECK(tree[
"map"][
"seq"][4].is_flow_sl());
5559 CHECK(tostr(tree, noindent) ==
""
5560 "{" "\n"
5561 "map: {" "\n"
5562 "seq: [" "\n"
5563 "0," "\n"
5564 "1," "\n"
5565 "2," "\n"
5566 "3," "\n"
5567 "[40,41]" "\n"
5568 "]" "\n"
5569 "}" "\n"
5570 "}" "\n"
5571 "");
5572 CHECK(tostr_json(tree, noindent) ==
""
5573 "{" "\n"
5574 "\"map\": {" "\n"
5575 "\"seq\": [" "\n"
5576 "0," "\n"
5577 "1," "\n"
5578 "2," "\n"
5579 "3," "\n"
5580 "[40,41]" "\n"
5581 "]" "\n"
5582 "}" "\n"
5583 "}" "\n"
5584 "");
5585 }
5586
5587 {
5588
5590 "[" "\n"
5591 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9," "\n"
5592 " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, " "\n"
5593 " 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, " "\n"
5594 " 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, " "\n"
5595 " 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, " "\n"
5596 " 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, " "\n"
5597 " 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, " "\n"
5598 " 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 " "\n"
5599 "]";
5600
5601
5602
5603
5608
5609 CHECK(tostr(tree, emit_defaults) ==
""
5610 "[\n"
5611 " 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"
5612 " 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"
5613 " 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"
5614 "]\n"
5615 "");
5616 CHECK(tostr_json(tree, emit_defaults) ==
""
5617 "[\n"
5618 " 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"
5619 " 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"
5620 " 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"
5621 "]\n"
5622 "");
5623
5626 CHECK(tostr(tree, maxcols40) ==
""
5627 "[\n"
5628 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n"
5629 " 16,17,18,19,20,21,22,23,24,25,26,27,28,\n"
5630 " 29,30,31,32,33,34,35,36,37,38,39,40,41,\n"
5631 " 42,43,44,45,46,47,48,49,50,51,52,53,54,\n"
5632 " 55,56,57,58,59,60,61,62,63,64,65,66,67,\n"
5633 " 68,69,70,71,72,73,74,75,76,77,78,79\n"
5634 "]\n"
5635 "");
5636 CHECK(tostr_json(tree, maxcols40) ==
""
5637 "[\n"
5638 " 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n"
5639 " 16,17,18,19,20,21,22,23,24,25,26,27,28,\n"
5640 " 29,30,31,32,33,34,35,36,37,38,39,40,41,\n"
5641 " 42,43,44,45,46,47,48,49,50,51,52,53,54,\n"
5642 " 55,56,57,58,59,60,61,62,63,64,65,66,67,\n"
5643 " 68,69,70,71,72,73,74,75,76,77,78,79\n"
5644 "]\n"
5645 "");
5646
5647
5650 CHECK(tostr(tree, with_spaces) ==
""
5651 "[\n"
5652 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5653 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5654 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5655 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79\n"
5656 "]\n"
5657 "");
5658 CHECK(tostr_json(tree, with_spaces) ==
""
5659 "[\n"
5660 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5661 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5662 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5663 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79\n"
5664 "]\n"
5665 "");
5666
5670 CHECK(tostr(tree, maxcols40_spc) ==
""
5671 "[\n"
5672 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\n"
5673 " 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5674 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,\n"
5675 " 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5676 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n"
5677 " 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5678 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,\n"
5679 " 72, 73, 74, 75, 76, 77, 78, 79\n"
5680 "]\n"
5681 "");
5682 CHECK(tostr_json(tree, maxcols40_spc) ==
""
5683 "[\n"
5684 " 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\n"
5685 " 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,\n"
5686 " 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,\n"
5687 " 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,\n"
5688 " 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,\n"
5689 " 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,\n"
5690 " 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,\n"
5691 " 72, 73, 74, 75, 76, 77, 78, 79\n"
5692 "]\n"
5693 "");
5694
5699 CHECK(tostr(tree, maxcols40_spc_noindent) ==
""
5700 "[\n"
5701 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,\n"
5702 "13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\n"
5703 "23, 24, 25, 26, 27, 28, 29, 30, 31, 32,\n"
5704 "33, 34, 35, 36, 37, 38, 39, 40, 41, 42,\n"
5705 "43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n"
5706 "53, 54, 55, 56, 57, 58, 59, 60, 61, 62,\n"
5707 "63, 64, 65, 66, 67, 68, 69, 70, 71, 72,\n"
5708 "73, 74, 75, 76, 77, 78, 79\n"
5709 "]\n"
5710 "");
5711 CHECK(tostr_json(tree, maxcols40_spc_noindent) ==
""
5712 "[\n"
5713 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,\n"
5714 "13, 14, 15, 16, 17, 18, 19, 20, 21, 22,\n"
5715 "23, 24, 25, 26, 27, 28, 29, 30, 31, 32,\n"
5716 "33, 34, 35, 36, 37, 38, 39, 40, 41, 42,\n"
5717 "43, 44, 45, 46, 47, 48, 49, 50, 51, 52,\n"
5718 "53, 54, 55, 56, 57, 58, 59, 60, 61, 62,\n"
5719 "63, 64, 65, 66, 67, 68, 69, 70, 71, 72,\n"
5720 "73, 74, 75, 76, 77, 78, 79\n"
5721 "]\n"
5722 "");
5723 }
5724
5725
5726
5727}
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().