rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
Emit to resizeable container

Functions

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: emit YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.
template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
substr c4::yml::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-like container, resizing it as needed to fit the emitted JSON.
template<class CharOwningContainer>
substr c4::yml::emitrs_json (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container.
template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.
template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
substr c4::yml::emitrs_json (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.
template<class CharOwningContainer>
substr c4::yml::emitrs_json (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container.
template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.
template<class CharOwningContainer>
substr c4::yml::emitrs_yaml (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
substr c4::yml::emitrs_json (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.
template<class CharOwningContainer>
substr c4::yml::emitrs_json (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Detailed Description

Function Documentation

◆ emitrs_yaml() [1/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( Tree const & t,
id_type id,
EmitOptions const & opts,
CharOwningContainer * cont,
bool append = false )

(1) emit+resize: emit YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

If append is set to true, the emitted YAML is appended at the end of the container.

Returns
a substr trimmed to the emitted YAML (excluding the initial contents, when appending)

Definition at line 765 of file emit.hpp.

766{
767 size_t startpos = append ? cont->size() : 0u;
768 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
769 substr buf = to_substr(*cont).sub(startpos);
770 substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
771 if(ret.str == nullptr && ret.len > 0)
772 {
773 cont->resize(startpos + ret.len);
774 buf = to_substr(*cont).sub(startpos);
775 ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
776 }
777 else
778 {
779 cont->resize(startpos + ret.len);
780 }
781 return ret;
782}
size_t emit_yaml(Tree const &t, id_type id, EmitOptions const &opts, FILE *f)
(1) emit YAML to the given file, starting at the given node.
Definition emit.hpp:416
substr to_substr(char(&s)[N]) noexcept
Definition substr.hpp:2377
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
size_t len
the length of the substring
Definition substr.hpp:218
basic_substring sub(size_t first) const noexcept
return [first,len[
Definition substr.hpp:503
C * str
a restricted pointer to the first character of the substring
Definition substr.hpp:216

◆ emitrs_yaml() [2/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( Tree const & t,
id_type id,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 785 of file emit.hpp.

786{
787 return emitrs_yaml(t, id, EmitOptions{}, cont, append);
788}
substr emitrs_yaml(Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
(1) emit+resize: emit YAML to the given std::string/std::vector-like container, resizing it as needed...
Definition emit.hpp:765
A lightweight object containing options to be used when emitting.
Definition emit.hpp:60

◆ emitrs_json() [1/9]

template<class CharOwningContainer>
substr c4::yml::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-like container, resizing it as needed to fit the emitted JSON.

If append is set to true, the emitted YAML is appended at the end of the container.

Returns
a substr trimmed to the emitted JSON (excluding the initial contents, when appending)

Definition at line 795 of file emit.hpp.

796{
797 const size_t startpos = append ? cont->size() : 0u;
798 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
799 substr buf = to_substr(*cont).sub(startpos);
800 EmitterBuf em(opts, buf);
801 substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
802 if(ret.str == nullptr && ret.len > 0)
803 {
804 cont->resize(startpos + ret.len);
805 buf = to_substr(*cont).sub(startpos);
806 ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
807 }
808 else
809 {
810 cont->resize(startpos + ret.len);
811 }
812 return ret;
813}
size_t emit_json(Tree const &t, id_type id, EmitOptions const &opts, FILE *f)
(1) emit JSON to the given file, starting at the given node.
Definition emit.hpp:429
Emitter< WriterBuf > EmitterBuf
Definition emit.hpp:40

◆ emitrs_json() [2/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_json ( Tree const & t,
id_type id,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 816 of file emit.hpp.

817{
818 return emitrs_json(t, id, EmitOptions{}, cont, append);
819}
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-like container, resizing it as needed...
Definition emit.hpp:795

◆ emitrs_yaml() [3/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml ( Tree const & t,
id_type id,
EmitOptions const & opts = {} )

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 824 of file emit.hpp.

824 {})
825{
826 CharOwningContainer c;
827 emitrs_yaml(t, id, opts, &c);
828 return c;
829}

◆ emitrs_json() [3/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json ( Tree const & t,
id_type id,
EmitOptions const & opts = {} )

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 832 of file emit.hpp.

832 {})
833{
834 CharOwningContainer c;
835 emitrs_json(t, id, opts, &c);
836 return c;
837}

◆ emitrs_yaml() [4/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( Tree const & t,
EmitOptions const & opts,
CharOwningContainer * cont,
bool append = false )

(1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

Returns
a substr trimmed to the new emitted contents.

Definition at line 846 of file emit.hpp.

847{
848 if(t.empty())
849 return {};
850 return emitrs_yaml(t, t.root_id(), opts, cont, append);
851}

◆ emitrs_yaml() [5/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( Tree const & t,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 854 of file emit.hpp.

855{
856 if(t.empty())
857 return {};
858 return emitrs_yaml(t, t.root_id(), EmitOptions{}, cont, append);
859}

◆ emitrs_json() [4/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_json ( Tree const & t,
EmitOptions const & opts,
CharOwningContainer * cont,
bool append = false )

(1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.

Returns
a substr trimmed to the new emitted contents.

Definition at line 864 of file emit.hpp.

865{
866 if(t.empty())
867 return {};
868 return emitrs_json(t, t.root_id(), opts, cont, append);
869}

◆ emitrs_json() [5/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_json ( Tree const & t,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 872 of file emit.hpp.

873{
874 if(t.empty())
875 return {};
876 return emitrs_json(t, t.root_id(), EmitOptions{}, cont, append);
877}

◆ emitrs_yaml() [6/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml ( Tree const & t,
EmitOptions const & opts = {} )

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 882 of file emit.hpp.

882 {})
883{
884 CharOwningContainer c;
885 if(t.empty())
886 return c;
887 emitrs_yaml(t, t.root_id(), opts, &c);
888 return c;
889}

◆ emitrs_json() [6/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json ( Tree const & t,
EmitOptions const & opts = {} )

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 892 of file emit.hpp.

892 {})
893{
894 CharOwningContainer c;
895 if(t.empty())
896 return c;
897 emitrs_json(t, t.root_id(), opts, &c);
898 return c;
899}

◆ emitrs_yaml() [7/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( ConstNodeRef const & n,
EmitOptions const & opts,
CharOwningContainer * cont,
bool append = false )

(1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

Returns
a substr trimmed to the new emitted contents

Definition at line 909 of file emit.hpp.

910{
911 if(!n.readable())
912 return {};
913 return emitrs_yaml(*n.tree(), n.id(), opts, cont, append);
914}

◆ emitrs_yaml() [8/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_yaml ( ConstNodeRef const & n,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 917 of file emit.hpp.

918{
919 if(!n.readable())
920 return {};
921 return emitrs_yaml(*n.tree(), n.id(), EmitOptions{}, cont, append);
922}

◆ emitrs_json() [7/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_json ( ConstNodeRef const & n,
EmitOptions const & opts,
CharOwningContainer * cont,
bool append = false )

(1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.

Returns
a substr trimmed to the new emitted contents

Definition at line 927 of file emit.hpp.

928{
929 if(!n.readable())
930 return {};
931 return emitrs_json(*n.tree(), n.id(), opts, cont, append);
932}

◆ emitrs_json() [8/9]

template<class CharOwningContainer>
substr c4::yml::emitrs_json ( ConstNodeRef const & n,
CharOwningContainer * cont,
bool append = false )

(2) like (1), but use default emit options

Definition at line 935 of file emit.hpp.

936{
937 if(!n.readable())
938 return {};
939 return emitrs_json(*n.tree(), n.id(), EmitOptions{}, cont, append);
940}

◆ emitrs_yaml() [9/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_yaml ( ConstNodeRef const & n,
EmitOptions const & opts = {} )

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 945 of file emit.hpp.

945 {})
946{
947 if(!n.readable())
948 return {};
949 CharOwningContainer c;
950 emitrs_yaml(*n.tree(), n.id(), opts, &c);
951 return c;
952}

◆ emitrs_json() [9/9]

template<class CharOwningContainer>
CharOwningContainer c4::yml::emitrs_json ( ConstNodeRef const & n,
EmitOptions const & opts = {} )

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 955 of file emit.hpp.

955 {})
956{
957 if(!n.readable())
958 return {};
959 CharOwningContainer c;
960 emitrs_json(*n.tree(), n.id(), opts, &c);
961 return c;
962}