rapidyaml 0.15.2
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 877 of file emit.hpp.

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

898{
899 return emitrs_yaml(t, id, EmitOptions{}, cont, append);
900}
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:877
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 907 of file emit.hpp.

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

929{
930 return emitrs_json(t, id, EmitOptions{}, cont, append);
931}
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:907

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

936 {})
937{
938 CharOwningContainer c;
939 emitrs_yaml(t, id, opts, &c);
940 return c;
941}

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

944 {})
945{
946 CharOwningContainer c;
947 emitrs_json(t, id, opts, &c);
948 return c;
949}

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

959{
960 if(t.empty())
961 return {};
962 return emitrs_yaml(t, t.root_id(), opts, cont, append);
963}

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

967{
968 if(t.empty())
969 return {};
970 return emitrs_yaml(t, t.root_id(), EmitOptions{}, cont, append);
971}

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

977{
978 if(t.empty())
979 return {};
980 return emitrs_json(t, t.root_id(), opts, cont, append);
981}

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

985{
986 if(t.empty())
987 return {};
988 return emitrs_json(t, t.root_id(), EmitOptions{}, cont, append);
989}

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

994 {})
995{
996 CharOwningContainer c;
997 if(t.empty())
998 return c;
999 emitrs_yaml(t, t.root_id(), opts, &c);
1000 return c;
1001}

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

1004 {})
1005{
1006 CharOwningContainer c;
1007 if(t.empty())
1008 return c;
1009 emitrs_json(t, t.root_id(), opts, &c);
1010 return c;
1011}

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

1022{
1023 if(!n.readable())
1024 return {};
1025 return emitrs_yaml(*n.tree(), n.id(), opts, cont, append);
1026}

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

1030{
1031 if(!n.readable())
1032 return {};
1033 return emitrs_yaml(*n.tree(), n.id(), EmitOptions{}, cont, append);
1034}

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

1040{
1041 if(!n.readable())
1042 return {};
1043 return emitrs_json(*n.tree(), n.id(), opts, cont, append);
1044}

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

1048{
1049 if(!n.readable())
1050 return {};
1051 return emitrs_json(*n.tree(), n.id(), EmitOptions{}, cont, append);
1052}

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

1057 {})
1058{
1059 if(!n.readable())
1060 return {};
1061 CharOwningContainer c;
1062 emitrs_yaml(*n.tree(), n.id(), opts, &c);
1063 return c;
1064}

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

1067 {})
1068{
1069 if(!n.readable())
1070 return {};
1071 CharOwningContainer c;
1072 emitrs_json(*n.tree(), n.id(), opts, &c);
1073 return c;
1074}