Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions json5_parser/json5_parser_reader_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#endif

#include <boost/algorithm/string.hpp>
#include <iterator>
#include <string>

#include "json5_parser_error_position.h"
Expand Down Expand Up @@ -139,28 +140,36 @@ template <class String_type>
String_type substitute_esc_chars(typename String_type::const_iterator begin,
typename String_type::const_iterator end) {
typedef typename String_type::const_iterator Iter_type;

if (end - begin < 2) return String_type(begin, end);

String_type result;

result.reserve(end - begin);
if (begin == end) return result;

const Iter_type end_minus_1(end - 1);
result.reserve(static_cast<typename String_type::size_type>(std::distance(begin, end)));

Iter_type substr_start = begin;
Iter_type i = begin;

for (; i < end_minus_1; ++i) {
if (*i == '\\') {
result.append(substr_start, i);
while (i != end) {
if (*i != '\\') {
++i;
continue;
}

++i; // skip the '\'
result.append(substr_start, i);

append_esc_char_and_incr_iter(result, i, end);
++i; // skip the '\\'

substr_start = i + 1;
// Preserve a trailing backslash literally.
if (i == end) {
result += '\\';
substr_start = end;
break;
}

append_esc_char_and_incr_iter(result, i, end);

++i;
substr_start = i;
}

result.append(substr_start, end);
Expand Down
2 changes: 2 additions & 0 deletions json5_parser/json5_parser_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class Value_impl {

class Variant_converter_visitor : public boost::static_visitor<Variant> {
public:
Variant operator()(const String_type& value) const { return value; }
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unit tests fails without the fix, as on debian12 and newer c++
what(): get_value< string > called on Array Value


template <typename T, typename A, template <typename, typename> class Cont>
Variant operator()(const Cont<T, A>& cont) const {
return Array(cont.begin(), cont.end());
Expand Down