rapidyaml 0.15.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 871 of file emit.hpp.

872{
873 size_t startpos = append ? cont->size() : 0u;
874 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
875 substr buf = to_substr(*cont).sub(startpos);
876 substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
877 if(ret.str == nullptr && ret.len > 0)
878 {
879 cont->resize(startpos + ret.len);
880 buf = to_substr(*cont).sub(startpos);
881 ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
882 }
883 else
884 {
885 cont->resize(startpos + ret.len);
886 }
887 return ret;
888}
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:522
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 891 of file emit.hpp.

892{
893 return emitrs_yaml(t, id, EmitOptions{}, cont, append);
894}
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:871
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 901 of file emit.hpp.

902{
903 const size_t startpos = append ? cont->size() : 0u;
904 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
905 substr buf = to_substr(*cont).sub(startpos);
906 EmitterBuf em(opts, buf);
907 substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
908 if(ret.str == nullptr && ret.len > 0)
909 {
910 cont->resize(startpos + ret.len);
911 buf = to_substr(*cont).sub(startpos);
912 ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
913 }
914 else
915 {
916 cont->resize(startpos + ret.len);
917 }
918 return ret;
919}
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:535
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 922 of file emit.hpp.

923{
924 return emitrs_json(t, id, EmitOptions{}, cont, append);
925}
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:901

◆ 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 930 of file emit.hpp.

930 {})
931{
932 CharOwningContainer c;
933 emitrs_yaml(t, id, opts, &c);
934 return c;
935}

◆ 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 938 of file emit.hpp.

938 {})
939{
940 CharOwningContainer c;
941 emitrs_json(t, id, opts, &c);
942 return c;
943}

◆ 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 952 of file emit.hpp.

953{
954 if(t.empty())
955 return {};
956 return emitrs_yaml(t, t.root_id(), opts, cont, append);
957}

◆ 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 960 of file emit.hpp.

961{
962 if(t.empty())
963 return {};
964 return emitrs_yaml(t, t.root_id(), EmitOptions{}, cont, append);
965}

◆ 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 970 of file emit.hpp.

971{
972 if(t.empty())
973 return {};
974 return emitrs_json(t, t.root_id(), opts, cont, append);
975}

◆ 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 978 of file emit.hpp.

979{
980 if(t.empty())
981 return {};
982 return emitrs_json(t, t.root_id(), EmitOptions{}, cont, append);
983}

◆ 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 988 of file emit.hpp.

988 {})
989{
990 CharOwningContainer c;
991 if(t.empty())
992 return c;
993 emitrs_yaml(t, t.root_id(), opts, &c);
994 return c;
995}

◆ 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 998 of file emit.hpp.

998 {})
999{
1000 CharOwningContainer c;
1001 if(t.empty())
1002 return c;
1003 emitrs_json(t, t.root_id(), opts, &c);
1004 return c;
1005}

◆ 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 1015 of file emit.hpp.

1016{
1017 if(!n.readable())
1018 return {};
1019 return emitrs_yaml(*n.tree(), n.id(), opts, cont, append);
1020}

◆ 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 1023 of file emit.hpp.

1024{
1025 if(!n.readable())
1026 return {};
1027 return emitrs_yaml(*n.tree(), n.id(), EmitOptions{}, cont, append);
1028}

◆ 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 1033 of file emit.hpp.

1034{
1035 if(!n.readable())
1036 return {};
1037 return emitrs_json(*n.tree(), n.id(), opts, cont, append);
1038}

◆ 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 1041 of file emit.hpp.

1042{
1043 if(!n.readable())
1044 return {};
1045 return emitrs_json(*n.tree(), n.id(), EmitOptions{}, cont, append);
1046}

◆ 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 1051 of file emit.hpp.

1051 {})
1052{
1053 if(!n.readable())
1054 return {};
1055 CharOwningContainer c;
1056 emitrs_yaml(*n.tree(), n.id(), opts, &c);
1057 return c;
1058}

◆ 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 1061 of file emit.hpp.

1061 {})
1062{
1063 if(!n.readable())
1064 return {};
1065 CharOwningContainer c;
1066 emitrs_json(*n.tree(), n.id(), opts, &c);
1067 return c;
1068}