rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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_
7 #include "c4/yml/node_type.hpp"
8 #endif
9 
10 namespace c4 {
11 namespace 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. */
21 RYML_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. */
46 inline NodeType scalar_style_choose_flow(csubstr scalar) noexcept
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. */
65 RYML_EXPORT NodeType scalar_style_choose_block(csubstr scalar) noexcept;
66 
67 
68 /** choose a json scalar style based on the scalar's contents */
69 RYML_EXPORT NodeType scalar_style_choose_json(csubstr scalar) noexcept;
70 
71 
72 //-----------------------------------------------------------------------------
73 
74 /** @cond dev */ // LCOV_EXCL_START
75 RYML_DEPRECATED("use scalar_style_query_plain_{flow,block}()")
76 inline bool scalar_style_query_plain(csubstr s, bool flow=true) noexcept
77 {
79 }
80 RYML_DEPRECATED("use scalar_style_choose_{flow,block}()")
81 inline NodeType scalar_style_choose(csubstr s, bool flow=true) noexcept
82 {
84 }
85 RYML_DEPRECATED("use scalar_style_choose_json()")
86 inline 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_ */
bool scalar_style_query_plain_block(csubstr scalar) noexcept
query whether a scalar can be encoded using plain style while in block mode.
bool scalar_style_query_squo(csubstr scalar) noexcept
query whether a scalar can be encoded using single quotes.
NodeType scalar_style_choose_json(csubstr scalar) noexcept
choose a json scalar style based on the scalar's contents
mask of KEY_SQUO|VAL_SQUO,
Definition: node_type.hpp:171
NodeType scalar_style_choose_flow(csubstr scalar) noexcept
choose a YAML scalar style based on the scalar's contents, while in flow mode.
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
mask of KEY_PLAIN|VAL_PLAIN,
Definition: node_type.hpp:173
mask of KEY_DQUO|VAL_DQUO,
Definition: node_type.hpp:172
NodeType scalar_style_choose_block(csubstr scalar) noexcept
choose a YAML scalar style based on the scalar's contents, while in block mode.
#define RYML_EXPORT
Definition: export.hpp:18
Wraps a type_bits mask of NodeTypeBits flags with some syntactic sugar and predicates.
Definition: node_type.hpp:213
bool scalar_style_query_plain_flow(csubstr scalar) noexcept
query whether a scalar can be encoded using plain style while in flow mode.