mirror of
https://github.com/nlohmann/json.git
synced 2025-07-25 13:41:56 +03:00
♻️ adjusting lexer/parser in symmetry to #1006
This commit is contained in:
@ -42,7 +42,7 @@ class alt_string
|
||||
using value_type = std::string::value_type;
|
||||
|
||||
alt_string(const char* str): str_impl(str) {}
|
||||
alt_string(const char* str, size_t count): str_impl(str, count) {}
|
||||
alt_string(const char* str, std::size_t count): str_impl(str, count) {}
|
||||
alt_string(size_t count, char chr): str_impl(count, chr) {}
|
||||
alt_string() = default;
|
||||
|
||||
@ -70,17 +70,17 @@ class alt_string
|
||||
return str_impl != op;
|
||||
}
|
||||
|
||||
size_t size() const noexcept
|
||||
std::size_t size() const noexcept
|
||||
{
|
||||
return str_impl.size();
|
||||
}
|
||||
|
||||
void resize (size_t n)
|
||||
void resize (std::size_t n)
|
||||
{
|
||||
str_impl.resize(n);
|
||||
}
|
||||
|
||||
void resize (size_t n, char c)
|
||||
void resize (std::size_t n, char c)
|
||||
{
|
||||
str_impl.resize(n, c);
|
||||
}
|
||||
@ -101,12 +101,12 @@ class alt_string
|
||||
return str_impl.c_str();
|
||||
}
|
||||
|
||||
char& operator[](int index)
|
||||
char& operator[](std::size_t index)
|
||||
{
|
||||
return str_impl[index];
|
||||
}
|
||||
|
||||
const char& operator[](int index) const
|
||||
const char& operator[](std::size_t index) const
|
||||
{
|
||||
return str_impl[index];
|
||||
}
|
||||
@ -121,6 +121,16 @@ class alt_string
|
||||
return str_impl.back();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
str_impl.clear();
|
||||
}
|
||||
|
||||
const value_type* data()
|
||||
{
|
||||
return str_impl.data();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string str_impl;
|
||||
};
|
||||
@ -192,4 +202,11 @@ TEST_CASE("alternative string type")
|
||||
CHECK(dump == R"({"list":[1,0,2]})");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("parse")
|
||||
{
|
||||
auto doc = alt_json::parse("{\"foo\": \"bar\"}");
|
||||
alt_string dump = doc.dump();
|
||||
CHECK(dump == R"({"foo":"bar"})");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user