Test JsonObject::prettyPrintTo()

This commit is contained in:
Benoit Blanchon
2014-10-07 11:58:59 +02:00
parent 7a40711af3
commit e28119f03b
7 changed files with 126 additions and 6 deletions

View File

@ -16,14 +16,12 @@ public:
virtual void beginArray()
{
_length += _sink.write('[');
_indenter.indent();
_length += _indenter.println();
indent();
}
virtual void endArray()
{
_length += _indenter.println();
_indenter.unindent();
unindent();
_length += _sink.write(']');
}
@ -41,14 +39,27 @@ public:
virtual void beginObject()
{
_length += _sink.write('{');
indent();
}
virtual void endObject()
{
unindent();
_length += _sink.write('}');
_indenter.unindent();
}
private:
IndentedPrint& _indenter;
void indent()
{
_indenter.indent();
_length += _indenter.println();
}
void unindent()
{
_length += _indenter.println();
_indenter.unindent();
}
};

View File

@ -57,7 +57,6 @@ protected:
bool checkNodeType(JsonNodeType expectedType);
private:
JsonNode* _node;
};

View File

@ -33,6 +33,20 @@ void JsonObject::remove(char const* key)
}
}
JsonObject JsonObject::createNestedObject(char const* key)
{
JsonNode* node = getOrCreateNodeAt(key);
if (node)
{
node->type = JSON_OBJECT;
node->content.asContainer.child = 0;
node->content.asContainer.buffer = _node->content.asContainer.buffer;
}
return JsonObject(node);
}
JsonNode* JsonObject::getOrCreateNodeAt(const char* key)
{
if (!checkNodeType(JSON_OBJECT)) return 0;

View File

@ -8,6 +8,7 @@ struct JsonNode;
class JsonObject : public JsonContainer
{
public:
JsonObject()
{
}
@ -20,6 +21,8 @@ public:
JsonValue operator[](const char* key);
void remove(const char* key);
JsonObject createNestedObject(const char* key);
private:
JsonNode* getOrCreateNodeAt(char const* key);
};