Simplify JsonScope.
GitOrigin-RevId: c3a9aea0c053db9684853acb857ae2381d542cb2
This commit is contained in:
parent
8a7d6be7df
commit
a0d761f27e
@ -301,18 +301,6 @@ class JsonScope {
|
|||||||
JsonScope &operator<<(double x) {
|
JsonScope &operator<<(double x) {
|
||||||
return *this << JsonFloat(x);
|
return *this << JsonFloat(x);
|
||||||
}
|
}
|
||||||
template <class T>
|
|
||||||
JsonScope &operator<<(const T *x); // not implemented
|
|
||||||
template <size_t N>
|
|
||||||
JsonScope &operator<<(const char (&x)[N]) {
|
|
||||||
return *this << JsonString(Slice(x));
|
|
||||||
}
|
|
||||||
JsonScope &operator<<(const char *x) {
|
|
||||||
return *this << JsonString(Slice(x));
|
|
||||||
}
|
|
||||||
JsonScope &operator<<(const string &x) {
|
|
||||||
return *this << JsonString(Slice(x));
|
|
||||||
}
|
|
||||||
JsonScope &operator<<(Slice x) {
|
JsonScope &operator<<(Slice x) {
|
||||||
return *this << JsonString(x);
|
return *this << JsonString(x);
|
||||||
}
|
}
|
||||||
@ -401,12 +389,8 @@ class JsonObjectScope : public JsonScope {
|
|||||||
jb_->print_offset();
|
jb_->print_offset();
|
||||||
*sb_ << "}";
|
*sb_ << "}";
|
||||||
}
|
}
|
||||||
template <class S, class T>
|
template <class T>
|
||||||
JsonObjectScope &operator<<(std::pair<S, T> key_value) {
|
JsonObjectScope &operator()(Slice key, T &&value) {
|
||||||
return (*this)(key_value.first, key_value.second);
|
|
||||||
}
|
|
||||||
template <class S, class T>
|
|
||||||
JsonObjectScope &operator()(S &&key, T &&value) {
|
|
||||||
CHECK(is_active());
|
CHECK(is_active());
|
||||||
if (is_first_) {
|
if (is_first_) {
|
||||||
*sb_ << ",";
|
*sb_ << ",";
|
||||||
@ -590,7 +574,7 @@ class JsonValue : public Jsonable {
|
|||||||
case Type::Object: {
|
case Type::Object: {
|
||||||
auto object = scope->enter_object();
|
auto object = scope->enter_object();
|
||||||
for (auto &key_value : get_object()) {
|
for (auto &key_value : get_object()) {
|
||||||
object(JsonString(key_value.first), key_value.second);
|
object(key_value.first, key_value.second);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ TEST(JSON, object) {
|
|||||||
JsonBuilder jb(std::move(sb));
|
JsonBuilder jb(std::move(sb));
|
||||||
auto c = jb.enter_object();
|
auto c = jb.enter_object();
|
||||||
c("key", "value");
|
c("key", "value");
|
||||||
c << std::make_pair("1", 2);
|
c("1", 2);
|
||||||
c.leave();
|
c.leave();
|
||||||
ASSERT_EQ(jb.string_builder().is_error(), false);
|
ASSERT_EQ(jb.string_builder().is_error(), false);
|
||||||
auto encoded = jb.string_builder().as_cslice().str();
|
auto encoded = jb.string_builder().as_cslice().str();
|
||||||
|
Loading…
Reference in New Issue
Block a user