rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches

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<char>-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<char>-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<char>-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<char>-like container.

Detailed Description

Function Documentation

◆ emitrs_yaml() [1/3]

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<char>-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 35 of file emit_container.hpp.

36{
37 const size_t startpos = append ? cont->size() : 0u;
38 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
39 substr buf = to_substr(*cont).sub(startpos);
40 substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
41 cont->resize(startpos + ret.len);
42 if(ret.len && !ret.str)
43 {
44 buf = to_substr(*cont).sub(startpos);
45 ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
46 }
47 return ret;
48}
substr emit_yaml(Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess)
(1) emit YAML to the given buffer.
Definition emit_buf.cpp:28
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/3]

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 51 of file emit_container.hpp.

52{
53 return emitrs_yaml(t, id, EmitOptions{}, cont, append);
54}
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<char>-like container,...
A lightweight object containing options to be used when emitting.

◆ emitrs_json() [1/3]

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<char>-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 63 of file emit_container.hpp.

64{
65 const size_t startpos = append ? cont->size() : 0u;
66 cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
67 substr buf = to_substr(*cont).sub(startpos);
68 substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
69 cont->resize(startpos + ret.len);
70 if(ret.len && !ret.str)
71 {
72 buf = to_substr(*cont).sub(startpos);
73 ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
74 }
75 return ret;
76}
substr emit_json(Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess)
(1) emit JSON to the given buffer.
Definition emit_buf.cpp:42

◆ emitrs_json() [2/3]

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 79 of file emit_container.hpp.

80{
81 return emitrs_json(t, id, EmitOptions{}, cont, append);
82}
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,...

◆ emitrs_yaml() [3/3]

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<char>-like container.

Definition at line 87 of file emit_container.hpp.

87 {})
88{
89 CharOwningContainer c;
90 emitrs_yaml(t, id, opts, &c);
91 return c;
92}

◆ emitrs_json() [3/3]

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<char>-like container.

Definition at line 95 of file emit_container.hpp.

95 {})
96{
97 CharOwningContainer c;
98 emitrs_json(t, id, opts, &c);
99 return c;
100}