Switched to Google coding style to match cpplint expectations

This commit is contained in:
Benoit Blanchon
2014-10-23 23:13:13 +02:00
parent 5c8283b3e4
commit b43da1e421
47 changed files with 262 additions and 308 deletions
+5 -10
View File
@@ -3,25 +3,21 @@
using namespace ArduinoJson::Internals;
void IndentedPrint::indent() {
if (level < MAX_LEVEL)
level++;
if (level < MAX_LEVEL) level++;
}
void IndentedPrint::unindent() {
if (level > 0)
level--;
if (level > 0) level--;
}
void IndentedPrint::setTabSize(uint8_t n) {
if (n < MAX_TAB_SIZE)
tabSize = n;
if (n < MAX_TAB_SIZE) tabSize = n;
}
size_t IndentedPrint::write(uint8_t c) {
size_t n = 0;
if (isNewLine)
n += writeTabs();
if (isNewLine) n += writeTabs();
n += sink->write(c);
@@ -33,8 +29,7 @@ size_t IndentedPrint::write(uint8_t c) {
inline size_t IndentedPrint::writeTabs() {
size_t n = 0;
for (int i = 0; i < level * tabSize; i++)
n += sink->write(' ');
for (int i = 0; i < level * tabSize; i++) n += sink->write(' ');
return n;
}
+30 -39
View File
@@ -9,42 +9,40 @@ using namespace ArduinoJson::Internals;
void JsonNode::writeTo(JsonWriter &writer) {
switch (type) {
case JSON_PROXY:
content.asProxy.target->writeTo(writer);
break;
case JSON_PROXY:
content.asProxy.target->writeTo(writer);
break;
case JSON_ARRAY:
writeArrayTo(writer);
break;
case JSON_ARRAY:
writeArrayTo(writer);
break;
case JSON_OBJECT:
writeObjectTo(writer);
break;
case JSON_OBJECT:
writeObjectTo(writer);
break;
case JSON_STRING:
writer.writeString(content.asString);
break;
case JSON_STRING:
writer.writeString(content.asString);
break;
case JSON_LONG:
writer.writeInteger(content.asInteger);
break;
case JSON_LONG:
writer.writeInteger(content.asInteger);
break;
case JSON_BOOLEAN:
writer.writeBoolean(content.asBoolean);
break;
case JSON_BOOLEAN:
writer.writeBoolean(content.asBoolean);
break;
default: // >= JSON_DOUBLE_0_DECIMALS
writer.writeDouble(content.asDouble, type - JSON_DOUBLE_0_DECIMALS);
break;
default: // >= JSON_DOUBLE_0_DECIMALS
writer.writeDouble(content.asDouble, type - JSON_DOUBLE_0_DECIMALS);
break;
}
}
void JsonNode::addChild(JsonNode *childToAdd) {
if (type == JSON_PROXY)
return content.asProxy.target->addChild(childToAdd);
if (type == JSON_PROXY) return content.asProxy.target->addChild(childToAdd);
if (type != JSON_ARRAY && type != JSON_OBJECT)
return;
if (type != JSON_ARRAY && type != JSON_OBJECT) return;
JsonNode *lastChild = content.asContainer.child;
@@ -53,8 +51,7 @@ void JsonNode::addChild(JsonNode *childToAdd) {
return;
}
while (lastChild->next)
lastChild = lastChild->next;
while (lastChild->next) lastChild = lastChild->next;
lastChild->next = childToAdd;
}
@@ -63,8 +60,7 @@ void JsonNode::removeChild(JsonNode *childToRemove) {
if (type == JSON_PROXY)
return content.asProxy.target->removeChild(childToRemove);
if (type != JSON_ARRAY && type != JSON_OBJECT)
return;
if (type != JSON_ARRAY && type != JSON_OBJECT) return;
if (content.asContainer.child == childToRemove) {
content.asContainer.child = childToRemove->next;
@@ -73,8 +69,7 @@ void JsonNode::removeChild(JsonNode *childToRemove) {
for (JsonNode *child = content.asContainer.child; child;
child = child->next) {
if (child->next == childToRemove)
child->next = childToRemove->next;
if (child->next == childToRemove) child->next = childToRemove->next;
}
}
@@ -88,8 +83,7 @@ void JsonNode::writeArrayTo(JsonWriter &writer) {
child->writeTo(writer);
child = child->next;
if (!child)
break;
if (!child) break;
writer.writeComma();
}
@@ -112,8 +106,7 @@ void JsonNode::writeObjectTo(JsonWriter &writer) {
child->content.asKeyValue.value->writeTo(writer);
child = child->next;
if (!child)
break;
if (!child) break;
writer.writeComma();
}
@@ -126,12 +119,10 @@ void JsonNode::writeObjectTo(JsonWriter &writer) {
void JsonNode::setAsProxyOfSelf() {
JsonBuffer *buffer = content.asContainer.buffer;
if (!buffer)
return;
if (!buffer) return;
JsonNode *newNode = buffer->createNode();
if (!newNode)
return;
if (!newNode) return;
*newNode = *this;
+45 -60
View File
@@ -1,6 +1,6 @@
#include "ArduinoJson/Internals/JsonParser.hpp"
#include <stdlib.h> // for strtol, strtod
#include <stdlib.h> // for strtol, strtod
#include <ctype.h>
#include "ArduinoJson/JsonBuffer.hpp"
@@ -9,14 +9,12 @@
using namespace ArduinoJson::Internals;
void JsonParser::skipSpaces() {
while (isspace(*_ptr))
_ptr++;
while (isspace(*_ptr)) _ptr++;
}
bool JsonParser::skip(char charToSkip) {
skipSpaces();
if (*_ptr != charToSkip)
return false;
if (*_ptr != charToSkip) return false;
_ptr++;
skipSpaces();
return true;
@@ -26,39 +24,39 @@ JsonNode *JsonParser::parseAnything() {
skipSpaces();
switch (*_ptr) {
case '[':
return parseArray();
case '[':
return parseArray();
case 't':
case 'f':
return parseBoolean();
case 't':
case 'f':
return parseBoolean();
case '-':
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return parseNumber();
case '-':
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return parseNumber();
case 'n':
return parseNull();
case 'n':
return parseNull();
case '{':
return parseObject();
case '{':
return parseObject();
case '\'':
case '\"':
return parseString();
case '\'':
case '\"':
return parseString();
default:
return NULL; // invalid JSON
default:
return NULL; // invalid JSON
}
}
@@ -67,25 +65,20 @@ JsonNode *JsonParser::parseArray() {
skip('[');
if (isEnd())
return 0;
if (isEnd()) return 0;
if (skip(']'))
return node; // empty array
if (skip(']')) return node; // empty array
for (;;) {
JsonNode *child = parseAnything();
if (!child)
return 0; // child parsing failed
if (!child) return 0; // child parsing failed
node->addChild(child);
if (skip(']'))
return node; // end of the array
if (skip(']')) return node; // end of the array
if (!skip(','))
return 0; // comma is missing
if (!skip(',')) return 0; // comma is missing
}
}
@@ -103,7 +96,7 @@ JsonNode *JsonParser::parseNumber() {
char *endOfLong;
long longValue = strtol(_ptr, &endOfLong, 10);
if (*endOfLong == '.') // stopped on a decimal separator
if (*endOfLong == '.') // stopped on a decimal separator
{
double value = strtod(_ptr, &_ptr);
int decimals = _ptr - endOfLong - 1;
@@ -115,7 +108,7 @@ JsonNode *JsonParser::parseNumber() {
}
JsonNode *JsonParser::parseNull() {
_ptr += 4; // strlen("null")
_ptr += 4; // strlen("null")
return _buffer->createStringNode(0);
}
@@ -125,41 +118,33 @@ JsonNode *JsonParser::parseObject() {
skip('{');
if (isEnd())
return 0; // premature ending
if (isEnd()) return 0; // premature ending
if (skip('}'))
return node; // empty object
if (skip('}')) return node; // empty object
for (;;) {
JsonNode *child = parseObjectKeyValue();
if (!child)
return 0; // child parsing failed
if (!child) return 0; // child parsing failed
node->addChild(child);
if (skip('}'))
return node; // end of the object
if (skip('}')) return node; // end of the object
if (!skip(','))
return 0; // comma is missing
if (!skip(',')) return 0; // comma is missing
}
}
JsonNode *JsonParser::parseObjectKeyValue() {
const char *key = QuotedString::extractFrom(_ptr, &_ptr);
if (!key)
return 0; // failed to extract key
if (!key) return 0; // failed to extract key
if (!skip(':'))
return 0; // colon is missing
if (!skip(':')) return 0; // colon is missing
JsonNode *value = parseAnything();
if (!value)
return 0; // value parsing failed
if (!value) return 0; // value parsing failed
return _buffer->createObjectKeyValueNode(key, value);
}
+5 -8
View File
@@ -27,8 +27,7 @@ static inline size_t printCharTo(char c, Print *p) {
}
size_t QuotedString::printTo(const char *s, Print *p) {
if (!s)
return p->print("null");
if (!s) return p->print("null");
size_t n = p->write('\"');
@@ -45,10 +44,8 @@ static char unescapeChar(char c) {
const char *p = "b\bf\fn\nr\rt\t";
for (;;) {
if (p[0] == 0)
return c;
if (p[0] == c)
return p[1];
if (p[0] == 0) return c;
if (p[0] == c) return p[1];
p += 2;
}
}
@@ -63,9 +60,9 @@ char *QuotedString::extractFrom(char *input, char **endPtr) {
return 0;
}
char stopChar = firstChar; // closing quote is the same as opening quote
char stopChar = firstChar; // closing quote is the same as opening quote
char *startPtr = input + 1; // skip the quote
char *startPtr = input + 1; // skip the quote
char *readPtr = startPtr;
char *writePtr = startPtr;
char c;
+1 -2
View File
@@ -8,8 +8,7 @@
using namespace ArduinoJson::Internals;
size_t StringBuilder::write(uint8_t c) {
if (length >= capacity)
return 0;
if (length >= capacity) return 0;
buffer[length++] = c;
buffer[length] = 0;