Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to error_category
  • Loading branch information
danielaparker committed Feb 7, 2020
2 parents 86edd85 + 628d474 commit fad234b
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 197 deletions.
170 changes: 85 additions & 85 deletions include/jsoncons/json_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,102 +46,102 @@ namespace jsoncons {
unpaired_high_surrogate
};

class json_error_category_impl
: public std::error_category
{
public:
const char* name() const noexcept override
class json_error_category_impl
: public std::error_category
{
return "jsoncons/json";
}
std::string message(int ev) const override
{
switch (static_cast<json_errc>(ev))
public:
const char* name() const noexcept override
{
case json_errc::unexpected_eof:
return "Unexpected end of file";
case json_errc::source_error:
return "Source error";
case json_errc::invalid_json_text:
return "Invalid JSON text";
case json_errc::extra_character:
return "Unexpected non-whitespace character after JSON text";
case json_errc::max_depth_exceeded:
return "Maximum JSON depth exceeded";
case json_errc::single_quote:
return "JSON strings cannot be quoted with single quotes";
case json_errc::illegal_character_in_string:
return "Illegal character in string";
case json_errc::extra_comma:
return "Extra comma";
case json_errc::expected_name:
return "Expected object member name";
case json_errc::expected_value:
return "Expected value";
case json_errc::invalid_value:
return "Invalid value";
case json_errc::expected_colon:
return "Expected name separator ':'";
case json_errc::illegal_control_character:
return "Illegal control character in string";
case json_errc::illegal_escaped_character:
return "Illegal escaped character in string";
case json_errc::expected_codepoint_surrogate_pair:
return "Invalid codepoint, expected another \\u token to begin the second half of a codepoint surrogate pair.";
case json_errc::invalid_hex_escape_sequence:
return "Invalid codepoint, expected hexadecimal digit.";
case json_errc::invalid_unicode_escape_sequence:
return "Invalid codepoint, expected four hexadecimal digits.";
case json_errc::leading_zero:
return "A number cannot have a leading zero";
case json_errc::invalid_number:
return "Invalid number";
case json_errc::expected_comma_or_right_brace:
return "Expected comma or right brace '}'";
case json_errc::expected_comma_or_right_bracket:
return "Expected comma or right bracket ']'";
case json_errc::unexpected_right_brace:
return "Unexpected right brace '}'";
case json_errc::unexpected_right_bracket:
return "Unexpected right bracket ']'";
case json_errc::illegal_comment:
return "Illegal comment";
case json_errc::expected_continuation_byte:
return "Expected continuation byte";
case json_errc::over_long_utf8_sequence:
return "Over long UTF-8 sequence";
case json_errc::illegal_codepoint:
return "Illegal codepoint (>= 0xd800 && <= 0xdfff)";
case json_errc::illegal_surrogate_value:
return "UTF-16 surrogate values are illegal in UTF-32";
case json_errc::unpaired_high_surrogate:
return "Expected low surrogate following the high surrogate";
default:
return "Unknown JSON parser error";
}
}
};
return "jsoncons/json";
}
std::string message(int ev) const override
{
switch (static_cast<json_errc>(ev))
{
case json_errc::unexpected_eof:
return "Unexpected end of file";
case json_errc::source_error:
return "Source error";
case json_errc::invalid_json_text:
return "Invalid JSON text";
case json_errc::extra_character:
return "Unexpected non-whitespace character after JSON text";
case json_errc::max_depth_exceeded:
return "Maximum JSON depth exceeded";
case json_errc::single_quote:
return "JSON strings cannot be quoted with single quotes";
case json_errc::illegal_character_in_string:
return "Illegal character in string";
case json_errc::extra_comma:
return "Extra comma";
case json_errc::expected_name:
return "Expected object member name";
case json_errc::expected_value:
return "Expected value";
case json_errc::invalid_value:
return "Invalid value";
case json_errc::expected_colon:
return "Expected name separator ':'";
case json_errc::illegal_control_character:
return "Illegal control character in string";
case json_errc::illegal_escaped_character:
return "Illegal escaped character in string";
case json_errc::expected_codepoint_surrogate_pair:
return "Invalid codepoint, expected another \\u token to begin the second half of a codepoint surrogate pair.";
case json_errc::invalid_hex_escape_sequence:
return "Invalid codepoint, expected hexadecimal digit.";
case json_errc::invalid_unicode_escape_sequence:
return "Invalid codepoint, expected four hexadecimal digits.";
case json_errc::leading_zero:
return "A number cannot have a leading zero";
case json_errc::invalid_number:
return "Invalid number";
case json_errc::expected_comma_or_right_brace:
return "Expected comma or right brace '}'";
case json_errc::expected_comma_or_right_bracket:
return "Expected comma or right bracket ']'";
case json_errc::unexpected_right_brace:
return "Unexpected right brace '}'";
case json_errc::unexpected_right_bracket:
return "Unexpected right bracket ']'";
case json_errc::illegal_comment:
return "Illegal comment";
case json_errc::expected_continuation_byte:
return "Expected continuation byte";
case json_errc::over_long_utf8_sequence:
return "Over long UTF-8 sequence";
case json_errc::illegal_codepoint:
return "Illegal codepoint (>= 0xd800 && <= 0xdfff)";
case json_errc::illegal_surrogate_value:
return "UTF-16 surrogate values are illegal in UTF-32";
case json_errc::unpaired_high_surrogate:
return "Expected low surrogate following the high surrogate";
default:
return "Unknown JSON parser error";
}
}
};

inline
const std::error_category& json_error_category()
{
static json_error_category_impl instance;
return instance;
}
inline
const std::error_category& json_error_category()
{
static json_error_category_impl instance;
return instance;
}

inline
std::error_code make_error_code(json_errc result)
{
return std::error_code(static_cast<int>(result),json_error_category());
}
inline
std::error_code make_error_code(json_errc result)
{
return std::error_code(static_cast<int>(result),json_error_category());
}

#if !defined(JSONCONS_NO_DEPRECATED)
JSONCONS_DEPRECATED_MSG("Instead, use json_errc") typedef json_errc json_parser_errc;

JSONCONS_DEPRECATED_MSG("Instead, use json_errc") typedef json_errc json_parse_errc;
#endif

}
} // jsoncons

namespace std {
template<>
Expand Down
15 changes: 4 additions & 11 deletions include/jsoncons/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class stream_sink
// Noncopyable
stream_sink(const stream_sink&) = delete;
stream_sink& operator=(const stream_sink&) = delete;
stream_sink& operator=(stream_sink&&) = delete;

public:
stream_sink(stream_sink&&) = default;
Expand All @@ -59,8 +60,6 @@ class stream_sink
os_->flush();
}

stream_sink& operator=(stream_sink&&) = default;

void flush()
{
os_->write(begin_buffer_, buffer_length());
Expand Down Expand Up @@ -124,6 +123,7 @@ class binary_stream_sink
// Noncopyable
binary_stream_sink(const binary_stream_sink&) = delete;
binary_stream_sink& operator=(const binary_stream_sink&) = delete;
binary_stream_sink& operator=(binary_stream_sink&&) = delete;

public:
binary_stream_sink(binary_stream_sink&&) = default;
Expand All @@ -150,8 +150,6 @@ class binary_stream_sink
os_->flush();
}

binary_stream_sink& operator=(binary_stream_sink&&) = default;

void flush()
{
os_->write((char*)begin_buffer_, buffer_length());
Expand Down Expand Up @@ -209,6 +207,7 @@ class string_sink
// Noncopyable
string_sink(const string_sink&) = delete;
string_sink& operator=(const string_sink&) = delete;
string_sink& operator=(string_sink&& val) = delete;
public:
string_sink(string_sink&& val)
: s_(nullptr)
Expand All @@ -221,11 +220,6 @@ class string_sink
{
}

string_sink& operator=(string_sink&& val)
{
std::swap(s_, val.s_);
}

void flush()
{
}
Expand Down Expand Up @@ -254,6 +248,7 @@ class bytes_sink
// Noncopyable
bytes_sink(const bytes_sink&) = delete;
bytes_sink& operator=(const bytes_sink&) = delete;
bytes_sink& operator=(bytes_sink&&) = delete;
public:
bytes_sink(bytes_sink&&) = default;

Expand All @@ -262,8 +257,6 @@ class bytes_sink
{
}

bytes_sink& operator=(bytes_sink&&) = default;

void flush()
{
}
Expand Down
2 changes: 1 addition & 1 deletion include/jsoncons/staj_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ class typed_array
span<const uint64_t> data(uint64_array_arg_t) const
{
JSONCONS_ASSERT(type_ == typed_array_type::uint64_value);
span<const uint64_t>(data_.uint64_data_, size_);
return span<const uint64_t>(data_.uint64_data_, size_);
}

span<int8_t> data(int8_array_arg_t)
Expand Down
Loading

0 comments on commit fad234b

Please sign in to comment.