Skip to content

Commit bfe69f2

Browse files
committed
unify indent char handling
There is a new indent_char() api in jsoncons, but it is a subset of the already present indent_chars() api. the indent_char_ state is removed, and to preserve compatibilty with test code etc, the setter is preserved to set the char into the underlying string. Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
1 parent 5b5e7d1 commit bfe69f2

2 files changed

Lines changed: 6 additions & 29 deletions

File tree

include/jsoncons/json_encoder.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ namespace detail {
329329

330330
Sink sink_;
331331
basic_json_encode_options<CharT> options_;
332-
char_type indent_char_{' '};
333332
jsoncons::write_double fp_;
334333

335334
std::vector<encoding_context,encoding_context_allocator_type> stack_;
@@ -359,7 +358,6 @@ namespace detail {
359358
const Allocator& alloc = Allocator())
360359
: sink_(std::forward<Sink>(sink)),
361360
options_(options),
362-
indent_char_(options.indent_char()),
363361
fp_(options.float_format(), options.precision()),
364362
stack_(alloc)
365363
{
@@ -1084,14 +1082,7 @@ namespace detail {
10841082
sink_.append(options_.new_line_chars().data(),options_.new_line_chars().length());
10851083
for (int i = 0; i < indent_amount_; ++i)
10861084
{
1087-
if (options_.indent_chars().empty())
1088-
{
1089-
sink_.push_back(indent_char_);
1090-
}
1091-
else
1092-
{
1093-
sink_.append(options_.indent_chars().data(), options_.indent_chars().length());
1094-
}
1085+
sink_.append(options_.indent_chars().data(), options_.indent_chars().length());
10951086
}
10961087
column_ = indent_amount_ * options_.new_line_chars().length();
10971088
}
@@ -1101,14 +1092,7 @@ namespace detail {
11011092
sink_.append(options_.new_line_chars().data(),options_.new_line_chars().length());
11021093
for (std::size_t i = 0; i < len; ++i)
11031094
{
1104-
if (options_.indent_chars().empty())
1105-
{
1106-
sink_.push_back(indent_char_);
1107-
}
1108-
else
1109-
{
1110-
sink_.append(options_.indent_chars().data(), options_.indent_chars().length());
1111-
}
1095+
sink_.append(options_.indent_chars().data(), options_.indent_chars().length());
11121096
}
11131097
column_ = len;
11141098
}

include/jsoncons/json_options.hpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ class basic_json_encode_options : public virtual basic_json_options_common<CharT
339339
uint8_t indent_size_{indent_size_default};
340340
std::size_t line_length_limit_{line_length_limit_default};
341341
string_type new_line_chars_;
342-
char_type indent_char_;
343342
string_type after_key_chars_;
344343
string_type indent_chars_;
345344
public:
@@ -357,10 +356,10 @@ class basic_json_encode_options : public virtual basic_json_options_common<CharT
357356
array_array_line_splits_(line_split_kind::multi_line),
358357
array_object_line_splits_(line_split_kind::multi_line),
359358
spaces_around_colon_(spaces_option::space_after),
360-
spaces_around_comma_(spaces_option::space_after),
361-
indent_char_(' ')
359+
spaces_around_comma_(spaces_option::space_after)
362360
{
363361
new_line_chars_.push_back('\n');
362+
indent_chars_.push_back(' ');
364363
}
365364

366365
basic_json_encode_options(const basic_json_encode_options&) = default;
@@ -385,7 +384,6 @@ class basic_json_encode_options : public virtual basic_json_options_common<CharT
385384
indent_size_(other.indent_size_),
386385
line_length_limit_(other.line_length_limit_),
387386
new_line_chars_(std::move(other.new_line_chars_)),
388-
indent_char_(other.indent_char_),
389387
after_key_chars_(std::move(other.after_key_chars_)),
390388
indent_chars_(std::move(other.indent_chars_))
391389
{
@@ -434,12 +432,7 @@ class basic_json_encode_options : public virtual basic_json_options_common<CharT
434432
return spaces_around_comma_;
435433
}
436434

437-
char_type indent_char() const
438-
{
439-
return indent_char_;
440-
}
441-
442-
bool pad_inside_object_braces() const
435+
bool pad_inside_object_braces() const
443436
{
444437
return pad_inside_object_braces_;
445438
}
@@ -645,7 +638,7 @@ class basic_json_options final: public basic_json_decode_options<CharT>,
645638

646639
basic_json_options& indent_char(char_type value)
647640
{
648-
this->indent_char_ = value;
641+
this->indent_chars_ = value;
649642
return *this;
650643
}
651644

0 commit comments

Comments
 (0)