rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
scalar_style.hpp
Go to the documentation of this file.
1#ifndef C4_YML_SCALAR_STYLE_HPP_
2#define C4_YML_SCALAR_STYLE_HPP_
3
4/** @file scalar_style.hpp */
5
6#ifndef C4_YML_NODE_TYPE_HPP_
8#endif
9
10namespace c4 {
11namespace yml {
12
13/** @addtogroup doc_scalar_style
14 *
15 * @{
16 */
17
18/** query whether a scalar can be encoded using single quotes.
19 * It may not be possible, notably when there is leading
20 * whitespace after a newline. */
21RYML_EXPORT bool scalar_style_query_squo(csubstr scalar) noexcept;
22
23
24/** query whether a scalar can be encoded using plain style while in
25 * flow mode. Plain scalars [have more constraints in flow mode than
26 * in block
27 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
28 * scalar_style_query_plain_block() is the block mode analogous function.*/
30
31
32/** query whether a scalar can be encoded using plain style while in
33 * block mode. Plain scalars [have more constraints in flow mode than
34 * in block
35 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
36 * scalar_style_query_plain_flow() is the flow mode analogous function.*/
38
39
40/** choose a YAML scalar style based on the scalar's contents, while
41 * in flow mode. Plain scalars [have more constraints in flow mode
42 * than in block
43 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
44 * scalar_style_choose_block() is the block mode analogous
45 * function. */
47{
48 if(scalar.len)
49 {
51 return SCALAR_PLAIN;
52 else if(scalar_style_query_squo(scalar))
53 return SCALAR_SQUO;
54 return SCALAR_DQUO;
55 }
56 return scalar.str ? SCALAR_SQUO : SCALAR_PLAIN;
57}
58
59
60/** choose a YAML scalar style based on the scalar's contents, while
61 * in block mode. Plain scalars [have more constraints in flow mode
62 * than in block
63 * mode](https://www.yaml.info/learn/quote.html#noplain). @ref
64 * scalar_style_choose_block() is the flow mode analogous function. */
65RYML_EXPORT NodeType scalar_style_choose_block(csubstr scalar) noexcept;
66
67
68/** choose a json scalar style based on the scalar's contents */
69RYML_EXPORT NodeType scalar_style_choose_json(csubstr scalar) noexcept;
70
71
72//-----------------------------------------------------------------------------
73
74/** @cond dev */ // LCOV_EXCL_START
75RYML_DEPRECATED("use scalar_style_query_plain_{flow,block}()")
76inline bool scalar_style_query_plain(csubstr s, bool flow=true) noexcept
77{
79}
80RYML_DEPRECATED("use scalar_style_choose_{flow,block}()")
81inline NodeType scalar_style_choose(csubstr s, bool flow=true) noexcept
82{
84}
85RYML_DEPRECATED("use scalar_style_choose_json()")
86inline NodeType scalar_style_json_choose(csubstr scalar) noexcept
87{
88 return scalar_style_choose_json(scalar);
89}
90/** @endcond */ // LCOV_EXCL_STOP
91
92/** @} */
93
94} // namespace yml
95} // namespace c4
96
97#endif /* C4_YML_SCALAR_STYLE_HPP_ */
#define RYML_EXPORT
Definition export.hpp:18
@ SCALAR_SQUO
mask of KEY_SQUO|VAL_SQUO,
@ SCALAR_DQUO
mask of KEY_DQUO|VAL_DQUO,
@ SCALAR_PLAIN
mask of KEY_PLAIN|VAL_PLAIN,
bool scalar_style_query_plain_block(csubstr scalar) noexcept
query whether a scalar can be encoded using plain style while in block mode.
NodeType scalar_style_choose_json(csubstr scalar) noexcept
choose a json scalar style based on the scalar's contents
NodeType scalar_style_choose_flow(csubstr scalar) noexcept
choose a YAML scalar style based on the scalar's contents, while in flow mode.
bool scalar_style_query_squo(csubstr scalar) noexcept
query whether a scalar can be encoded using single quotes.
bool scalar_style_query_plain_flow(csubstr scalar) noexcept
query whether a scalar can be encoded using plain style while in flow mode.
NodeType scalar_style_choose_block(csubstr scalar) noexcept
choose a YAML scalar style based on the scalar's contents, while in block mode.
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2356
Wraps a type_bits mask of NodeTypeBits flags with some syntactic sugar and predicates.