Skip to content

Commit 6f8f80c

Browse files
committed
toon options
1 parent 7728eb2 commit 6f8f80c

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

doc/ref/toon/key_folding_kind.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### jsoncons::toon::key_folding_kind
2+
3+
```cpp
4+
#include <jsoncons_ext/toon/toon_options.hpp>
5+
6+
enum class key_folding_kind
7+
{
8+
off,
9+
safe
10+
};
11+
```
12+
13+
Value |Definition
14+
-----------|-----------
15+
off | No key folding
16+
safe | Safe key_folding
17+
18+

doc/ref/toon/toon_options.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ class toon_options;
1212

1313
Specifies options for reading and writing [toon-format](https://github.com/toon-format/toon).
1414

15-
16-
Option|Reading|Writing|Default
17-
------|-------|-------|-------
18-
delimiter|&nbsp;|[Delimiter character](toon_delimiter_kind.md) for arrays|**comma**
15+
Option|Reading|Writing|Default|Comment
16+
------|-------|-------|-------|-------
1917
indent|Number of spaces to indent each level|Number of spaces to indent each level.|**2**
20-
length_marker|&nbsp;|Optional marker for prefixing array lengths|None
21-
strict|See [strict mode errors and diagnostics](https://github.com/toon-format/spec/blob/main/SPEC.md#14-strict-mode-errors-and-diagnostics-authoritative-checklist)|&nbsp;|**true**
2218
max_nesting_depth|Maximum nesting depth allowed when reading toon-format|Maximum nesting depth allowed when writing toon-format|**1024**
19+
strict|See [strict mode errors and diagnostics](https://github.com/toon-format/spec/blob/main/SPEC.md#14-strict-mode-errors-and-diagnostics-authoritative-checklist)|&nbsp;|**true**
20+
expand_policy|Expand policy|&nbsp;|**off**|Not supported
21+
delimiter|&nbsp;|[Delimiter character](toon_delimiter_kind.md) for arrays|**comma**
22+
length_marker|&nbsp;|Optional marker for prefixing array lengths|None
23+
key_folding|&nbsp;|Key folding|**off**|Not supported
24+
flatten_depth|&nbsp;|Flatten depth|1024|Not supported
2325

2426
#### Constructor
2527

@@ -28,9 +30,12 @@ Constructs a `toon_options` with default values.
2830

2931
#### Setters
3032

31-
toon_options& delimiter(toon_delimiter_kind value)
3233
toon_options& indent(int value)
33-
toon_options& length_marker(jsoncons::optional<char> value)
34-
toon_options& strict(bool value)
3534
toon_options& max_nesting_depth(int depth)
35+
toon_options& strict(bool value)
36+
toon_options& delimiter(toon_delimiter_kind value)
37+
toon_options& length_marker(jsoncons::optional<char> value)
38+
toon_options& expand_paths(key_folding_kind value)
39+
toon_options& key_folding(key_folding_kind value)
40+
toon_options& flatten_depth(std::size_t value)
3641

include/jsoncons_ext/toon/toon_options.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace toon {
2222

2323
enum class toon_delimiter_kind : char {comma=',', tab='\t', pipe='|'};
2424

25+
enum class key_folding_kind {off, safe};
26+
2527
class toon_options;
2628

2729
class toon_options_common
@@ -66,6 +68,7 @@ class toon_decode_options : public virtual toon_options_common
6668
using typename super_type::string_type;
6769
private:
6870
bool strict_{true};
71+
key_folding_kind expand_paths_{key_folding_kind::off};
6972
public:
7073
toon_decode_options() = default;
7174

@@ -80,6 +83,7 @@ class toon_decode_options : public virtual toon_options_common
8083
toon_decode_options& operator=(toon_decode_options&&) = default;
8184
public:
8285
bool strict() const {return strict_;}
86+
key_folding_kind expand_paths() const {return expand_paths_;}
8387
};
8488

8589
class toon_encode_options : public virtual toon_options_common
@@ -92,6 +96,8 @@ class toon_encode_options : public virtual toon_options_common
9296
private:
9397
toon_delimiter_kind delimiter_{toon_delimiter_kind::comma};
9498
jsoncons::optional<char> length_marker_;
99+
key_folding_kind key_folding_{key_folding_kind::off};
100+
std::size_t flatten_depth_{1024};
95101
public:
96102
toon_encode_options() = default;
97103

@@ -117,6 +123,10 @@ class toon_encode_options : public virtual toon_options_common
117123
{
118124
return length_marker_;
119125
}
126+
127+
key_folding_kind key_folding() const {return key_folding_;}
128+
129+
std::size_t flatten_depth() const {return flatten_depth_;}
120130
};
121131

122132
class toon_options final: public toon_decode_options,
@@ -129,8 +139,11 @@ class toon_options final: public toon_decode_options,
129139
using toon_options_common::indent;
130140
using toon_options_common::max_nesting_depth;
131141
using toon_decode_options::strict;
142+
using toon_decode_options::expand_paths;
132143
using toon_encode_options::delimiter;
133144
using toon_encode_options::length_marker;
145+
using toon_encode_options::key_folding;
146+
using toon_encode_options::flatten_depth;
134147
public:
135148

136149
// Constructors
@@ -165,6 +178,24 @@ class toon_options final: public toon_decode_options,
165178
return *this;
166179
}
167180

181+
toon_options& key_folding(key_folding_kind value)
182+
{
183+
this->key_folding_ = value;
184+
return *this;
185+
}
186+
187+
toon_options& flatten_depth(std::size_t value)
188+
{
189+
this->flatten_depth_ = value;
190+
return *this;
191+
}
192+
193+
toon_options& expand_paths(key_folding_kind value)
194+
{
195+
this->expand_paths_ = value;
196+
return *this;
197+
}
198+
168199
toon_options& max_nesting_depth(int value)
169200
{
170201
this->max_nesting_depth_ = value;

0 commit comments

Comments
 (0)