From ce788d96c444fecfb13b0128f59d1369ba865e63 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 28 Sep 2014 13:36:41 +0200 Subject: [PATCH] Changed naming convention to avoid shadowing (issue #25) --- JsonGenerator/IndentedPrint.cpp | 20 +++++------ JsonGenerator/IndentedPrint.h | 16 ++++----- JsonGenerator/JsonArray.h | 4 +-- JsonGenerator/JsonArrayBase.cpp | 4 +-- JsonGenerator/JsonArrayBase.h | 14 ++++---- JsonGenerator/JsonObject.h | 4 +-- JsonGenerator/JsonObjectBase.cpp | 22 ++++++------ JsonGenerator/JsonObjectBase.h | 8 ++--- JsonGenerator/JsonPrettyPrint.cpp | 32 +++++++++--------- JsonGenerator/JsonPrettyPrint.h | 14 ++++---- JsonGenerator/JsonValue.h | 48 +++++++++++++------------- JsonGenerator/Printable.h | 1 - JsonGenerator/StringBuilder.cpp | 6 ++-- JsonGenerator/StringBuilder.h | 56 +++++++++++++++---------------- JsonParser/JsonParser.h | 4 +-- JsonParser/JsonParserBase.cpp | 4 +-- JsonParser/JsonParserBase.h | 6 ++-- JsonParser/JsonToken.cpp | 8 ++--- JsonParser/JsonToken.h | 24 ++++++------- 19 files changed, 147 insertions(+), 148 deletions(-) diff --git a/JsonGenerator/IndentedPrint.cpp b/JsonGenerator/IndentedPrint.cpp index 97a5c51f..3f01dd58 100644 --- a/JsonGenerator/IndentedPrint.cpp +++ b/JsonGenerator/IndentedPrint.cpp @@ -4,32 +4,32 @@ using namespace ArduinoJson::Generator; 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; + _tabSize = n; } size_t IndentedPrint::write(uint8_t c) { size_t n = 0; - if (isNewLine) + if (_isNewLine) n += writeTabs(); - n += sink.write(c); + n += _sink.write(c); - isNewLine = c == '\n'; + _isNewLine = c == '\n'; return n; } @@ -38,8 +38,8 @@ 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; } diff --git a/JsonGenerator/IndentedPrint.h b/JsonGenerator/IndentedPrint.h index 35c0aef4..a1541a9e 100644 --- a/JsonGenerator/IndentedPrint.h +++ b/JsonGenerator/IndentedPrint.h @@ -19,11 +19,11 @@ namespace ArduinoJson public: IndentedPrint(Print& p) - : sink(p) + : _sink(p) { - level = 0; - tabSize = 2; - isNewLine = true; + _level = 0; + _tabSize = 2; + _isNewLine = true; } virtual size_t write(uint8_t); @@ -38,10 +38,10 @@ namespace ArduinoJson void setTabSize(uint8_t n); private: - Print& sink; - uint8_t level : 4; - uint8_t tabSize : 3; - bool isNewLine : 1; + Print& _sink; + uint8_t _level : 4; + uint8_t _tabSize : 3; + bool _isNewLine : 1; size_t writeTabs(); diff --git a/JsonGenerator/JsonArray.h b/JsonGenerator/JsonArray.h index 817e9019..1d44e5e9 100644 --- a/JsonGenerator/JsonArray.h +++ b/JsonGenerator/JsonArray.h @@ -16,13 +16,13 @@ namespace ArduinoJson { public: JsonArray() - : JsonArrayBase(items, N) + : JsonArrayBase(_items, N) { } private: - JsonValue items[N]; + JsonValue _items[N]; }; } } diff --git a/JsonGenerator/JsonArrayBase.cpp b/JsonGenerator/JsonArrayBase.cpp index b90b39ed..108d7dd9 100644 --- a/JsonGenerator/JsonArrayBase.cpp +++ b/JsonGenerator/JsonArrayBase.cpp @@ -16,8 +16,8 @@ size_t JsonArrayBase::printTo(Print& p) const // NB: the code has been optimized for a small size on a 8-bit AVR - const JsonValue* current = items; - for (int i = count; i > 0; i--) + const JsonValue* current = _items; + for (int i = _count; i > 0; i--) { n += current->printTo(p); current++; diff --git a/JsonGenerator/JsonArrayBase.h b/JsonGenerator/JsonArrayBase.h index 10bbc4e4..8ed10f27 100644 --- a/JsonGenerator/JsonArrayBase.h +++ b/JsonGenerator/JsonArrayBase.h @@ -16,7 +16,7 @@ namespace ArduinoJson { public: JsonArrayBase(JsonValue* items, int capacity) - : items(items), capacity(capacity), count(0) + : _items(items), _capacity(capacity), _count(0) { } @@ -54,9 +54,9 @@ namespace ArduinoJson template void add(double value) { - if (count >= capacity) return; + if (_count >= _capacity) return; - JsonValue& v = items[count++]; + JsonValue& v = _items[_count++]; v.set(value); } @@ -65,14 +65,14 @@ namespace ArduinoJson using JsonPrintable::printTo; private: - JsonValue* items; - int capacity, count; + JsonValue* _items; + int _capacity, _count; template void addIfPossible(T value) { - if (count < capacity) - items[count++] = value; + if (_count < _capacity) + _items[_count++] = value; } }; } diff --git a/JsonGenerator/JsonObject.h b/JsonGenerator/JsonObject.h index fadd0167..e201c38c 100644 --- a/JsonGenerator/JsonObject.h +++ b/JsonGenerator/JsonObject.h @@ -26,12 +26,12 @@ namespace ArduinoJson { public: JsonObject() - : JsonObjectBase(items, N) + : JsonObjectBase(_items, N) { } private: - KeyValuePair items[N]; + KeyValuePair _items[N]; }; diff --git a/JsonGenerator/JsonObjectBase.cpp b/JsonGenerator/JsonObjectBase.cpp index 79753b4d..c1a42c6f 100644 --- a/JsonGenerator/JsonObjectBase.cpp +++ b/JsonGenerator/JsonObjectBase.cpp @@ -9,7 +9,7 @@ using namespace ArduinoJson::Generator; using namespace ArduinoJson::Internals; -JsonValue JsonObjectBase::nullValue; +JsonValue JsonObjectBase::_nullValue; size_t JsonObjectBase::printTo(Print& p) const { @@ -19,8 +19,8 @@ size_t JsonObjectBase::printTo(Print& p) const // NB: the code has been optimized for a small size on a 8-bit AVR - const KeyValuePair* current = items; - for (int i = count; i > 0; i--) + const KeyValuePair* current = _items; + for (int i = _count; i > 0; i--) { n += EscapedString::printTo(current->key, p); n += p.write(':'); @@ -41,9 +41,9 @@ size_t JsonObjectBase::printTo(Print& p) const JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(JsonKey key) const { - KeyValuePair* p = items; + KeyValuePair* p = _items; - for (int i = count; i > 0; --i) + for (int i = _count; i > 0; --i) { if (!strcmp(p->key, key)) return p; @@ -63,15 +63,15 @@ JsonValue& JsonObjectBase::operator[](JsonKey key) JsonValue* value; - if (count < capacity) + if (_count < _capacity) { - items[count].key = key; - value = &items[count].value; - count++; + _items[_count].key = key; + value = &_items[_count].value; + _count++; } else { - value = &nullValue; + value = &_nullValue; } value->reset(); @@ -88,5 +88,5 @@ void JsonObjectBase::remove(JsonKey key) KeyValuePair* match = getMatchingPair(key); if (match == 0) return; - *match = items[--count]; + *match = _items[--_count]; } diff --git a/JsonGenerator/JsonObjectBase.h b/JsonGenerator/JsonObjectBase.h index d7eb7b64..3339838c 100644 --- a/JsonGenerator/JsonObjectBase.h +++ b/JsonGenerator/JsonObjectBase.h @@ -47,14 +47,14 @@ namespace ArduinoJson }; JsonObjectBase(KeyValuePair* items, int capacity) - : items(items), capacity(capacity), count(0) + : _items(items), _capacity(capacity), _count(0) { } private: - KeyValuePair* items; - int capacity, count; - static JsonValue nullValue; + KeyValuePair* _items; + int _capacity, _count; + static JsonValue _nullValue; KeyValuePair* getMatchingPair(JsonKey key) const; }; diff --git a/JsonGenerator/JsonPrettyPrint.cpp b/JsonGenerator/JsonPrettyPrint.cpp index efa11908..306d969a 100644 --- a/JsonGenerator/JsonPrettyPrint.cpp +++ b/JsonGenerator/JsonPrettyPrint.cpp @@ -9,18 +9,18 @@ using namespace ArduinoJson::Generator; size_t JsonPrettyPrint::write(uint8_t c) { - size_t n = inString ? handleStringChar(c) : handleMarkupChar(c); - previousChar = c; + size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); + _previousChar = c; return n; } inline size_t JsonPrettyPrint::handleStringChar(uint8_t c) { - bool isQuote = c == '"' && previousChar != '\\'; + bool isQuote = c == '"' && _previousChar != '\\'; - if (isQuote) inString = false; + if (isQuote) _inString = false; - return sink.write(c); + return _sink.write(c); } inline size_t JsonPrettyPrint::handleMarkupChar(uint8_t c) @@ -51,47 +51,47 @@ inline size_t JsonPrettyPrint::handleMarkupChar(uint8_t c) inline size_t JsonPrettyPrint::handleBlockOpen(uint8_t c) { - return indentIfNeeded() + sink.write(c); + return indentIfNeeded() + _sink.write(c); } inline size_t JsonPrettyPrint::handleBlockClose(uint8_t c) { - return unindentIfNeeded() + sink.write(c); + return unindentIfNeeded() + _sink.write(c); } inline size_t JsonPrettyPrint::handleColumn() { - return sink.write(':') + sink.write(' '); + return _sink.write(':') + _sink.write(' '); } inline size_t JsonPrettyPrint::handleComma() { - return sink.write(',') + sink.println(); + return _sink.write(',') + _sink.println(); } inline size_t JsonPrettyPrint::handleQuoteOpen() { - inString = true; - return indentIfNeeded() + sink.write('"'); + _inString = true; + return indentIfNeeded() + _sink.write('"'); } inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c) { - return indentIfNeeded() + sink.write(c); + return indentIfNeeded() + _sink.write(c); } size_t JsonPrettyPrint::indentIfNeeded() { if (!inEmptyBlock()) return 0; - sink.indent(); - return sink.println(); + _sink.indent(); + return _sink.println(); } size_t JsonPrettyPrint::unindentIfNeeded() { if (inEmptyBlock()) return 0; - sink.unindent(); - return sink.println(); + _sink.unindent(); + return _sink.println(); } diff --git a/JsonGenerator/JsonPrettyPrint.h b/JsonGenerator/JsonPrettyPrint.h index 6a4c5074..b19458e1 100644 --- a/JsonGenerator/JsonPrettyPrint.h +++ b/JsonGenerator/JsonPrettyPrint.h @@ -18,22 +18,22 @@ namespace ArduinoJson public: JsonPrettyPrint(IndentedPrint& p) - : sink(p) + : _sink(p) { - previousChar = 0; - inString = false; + _previousChar = 0; + _inString = false; } virtual size_t write(uint8_t); private: - uint8_t previousChar; - IndentedPrint& sink; - bool inString; + uint8_t _previousChar; + IndentedPrint& _sink; + bool _inString; bool inEmptyBlock() { - return previousChar == '{' || previousChar == '['; + return _previousChar == '{' || _previousChar == '['; } size_t handleStringChar(uint8_t); diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index b7671bbf..236d52c9 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -19,32 +19,32 @@ namespace ArduinoJson void operator=(bool value) { - printToImpl = &printBoolTo; - content.asBool = value; + _printToImpl = &printBoolTo; + _content.asBool = value; } void operator=(long value) { - printToImpl = &printLongTo; - content.asLong = value; + _printToImpl = &printLongTo; + _content.asLong = value; } void operator=(int value) { - printToImpl = &printLongTo; - content.asLong = value; + _printToImpl = &printLongTo; + _content.asLong = value; } void operator=(const Printable& value) { - printToImpl = &printPrintableTo; - content.asPrintable = &value; + _printToImpl = &printPrintableTo; + _content.asPrintable = &value; } void operator=(const char* value) { - printToImpl = &printStringTo; - content.asString = value; + _printToImpl = &printStringTo; + _content.asString = value; } void operator=(double value) @@ -55,55 +55,55 @@ namespace ArduinoJson template void set(double value) { - printToImpl = &printDoubleTo < DIGITS > ; - content.asDouble = value; + _printToImpl = &printDoubleTo < DIGITS > ; + _content.asDouble = value; } operator bool() { - return content.asBool; + return _content.asBool; } operator const char*() { - return content.asString; + return _content.asString; } operator double() { - return content.asDouble; + return _content.asDouble; } operator float() { - return (float)content.asDouble; + return (float)_content.asDouble; } operator int() { - return content.asLong; + return _content.asLong; } operator long() { - return content.asLong; + return _content.asLong; } operator const Printable&() { - return *content.asPrintable; + return *_content.asPrintable; } size_t printTo(Print& p) const { // handmade polymorphism - return printToImpl(content, p); + return _printToImpl(_content, p); } void reset() { - content.asDouble = 0; - printToImpl = printStringTo; + _content.asDouble = 0; + _printToImpl = printStringTo; } private: @@ -116,9 +116,9 @@ namespace ArduinoJson const char* asString; }; - Content content; + Content _content; - size_t(*printToImpl)(const Content&, Print&); + size_t(*_printToImpl)(const Content&, Print&); static size_t printBoolTo(const Content&, Print&); static size_t printLongTo(const Content&, Print&); diff --git a/JsonGenerator/Printable.h b/JsonGenerator/Printable.h index b0b8baa9..cd24e4a7 100644 --- a/JsonGenerator/Printable.h +++ b/JsonGenerator/Printable.h @@ -21,4 +21,3 @@ public: #include #endif - diff --git a/JsonGenerator/StringBuilder.cpp b/JsonGenerator/StringBuilder.cpp index ed372c43..374d0793 100644 --- a/JsonGenerator/StringBuilder.cpp +++ b/JsonGenerator/StringBuilder.cpp @@ -9,9 +9,9 @@ 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; + _buffer[_length++] = c; + _buffer[_length] = 0; return 1; } diff --git a/JsonGenerator/StringBuilder.h b/JsonGenerator/StringBuilder.h index 4523cdde..0126d377 100644 --- a/JsonGenerator/StringBuilder.h +++ b/JsonGenerator/StringBuilder.h @@ -1,31 +1,31 @@ /* * Arduino JSON library * Benoit Blanchon 2014 - MIT License - */ - -#pragma once - -#include "Print.h" - -namespace ArduinoJson -{ - namespace Internals - { - class StringBuilder : public Print - { - public: - StringBuilder(char* buf, int size) - : buffer(buf), capacity(size - 1), length(0) - { - buffer[0] = 0; - } - - virtual size_t write(uint8_t c); - - private: - char* buffer; - int capacity; - int length; - }; - } -} + */ + +#pragma once + +#include "Print.h" + +namespace ArduinoJson +{ + namespace Internals + { + class StringBuilder : public Print + { + public: + StringBuilder(char* buf, int size) + : _buffer(buf), _capacity(size - 1), _length(0) + { + _buffer[0] = 0; + } + + virtual size_t write(uint8_t c); + + private: + char* _buffer; + int _capacity; + int _length; + }; + } +} diff --git a/JsonParser/JsonParser.h b/JsonParser/JsonParser.h index c7d2b2f1..aa374769 100644 --- a/JsonParser/JsonParser.h +++ b/JsonParser/JsonParser.h @@ -24,12 +24,12 @@ namespace ArduinoJson { public: JsonParser() - : JsonParserBase(tokens, MAX_TOKENS) + : JsonParserBase(_tokens, MAX_TOKENS) { } private: - jsmntok_t tokens[MAX_TOKENS]; + jsmntok_t _tokens[MAX_TOKENS]; }; } } diff --git a/JsonParser/JsonParserBase.cpp b/JsonParser/JsonParserBase.cpp index fa168554..1a39d55d 100644 --- a/JsonParser/JsonParserBase.cpp +++ b/JsonParser/JsonParserBase.cpp @@ -13,8 +13,8 @@ JsonValue JsonParserBase::parse(char* json) jsmn_parser parser; jsmn_init(&parser); - if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens)) + if (JSMN_SUCCESS != jsmn_parse(&parser, json, _tokens, _maxTokens)) return JsonToken::null(); - return JsonToken(json, tokens); + return JsonToken(json, _tokens); } diff --git a/JsonParser/JsonParserBase.h b/JsonParser/JsonParserBase.h index a49cafd0..cd724b4b 100644 --- a/JsonParser/JsonParserBase.h +++ b/JsonParser/JsonParserBase.h @@ -19,7 +19,7 @@ namespace ArduinoJson // Create a JSON parser using the provided buffer JsonParserBase(jsmntok_t* tokens, int maxTokens) - : tokens(tokens), maxTokens(maxTokens) + : _tokens(tokens), _maxTokens(maxTokens) { } @@ -42,8 +42,8 @@ namespace ArduinoJson } private: - jsmntok_t* tokens; - int maxTokens; + jsmntok_t* _tokens; + int _maxTokens; }; } } diff --git a/JsonParser/JsonToken.cpp b/JsonParser/JsonToken.cpp index 2b4eac4c..ea88cb96 100644 --- a/JsonParser/JsonToken.cpp +++ b/JsonParser/JsonToken.cpp @@ -9,8 +9,8 @@ using namespace ArduinoJson::Parser; char* JsonToken::getText() { - char* s = json + token->start; - json[token->end] = 0; + char* s = _json + _token->start; + _json[_token->end] = 0; unescapeString(s); @@ -54,7 +54,7 @@ inline char JsonToken::unescapeChar(char c) JsonToken JsonToken::nextSibling() const { // start with current token - jsmntok_t* t = token; + jsmntok_t* t = _token; // count the number of token to skip int yetToVisit = 1; @@ -67,5 +67,5 @@ JsonToken JsonToken::nextSibling() const } // build a JsonToken at the new location - return JsonToken(json, t); + return JsonToken(_json, t); } diff --git a/JsonParser/JsonToken.h b/JsonParser/JsonToken.h index 6e492ba5..0e3e4f35 100644 --- a/JsonParser/JsonToken.h +++ b/JsonParser/JsonToken.h @@ -18,13 +18,13 @@ namespace ArduinoJson // Create a "null" pointer JsonToken() - : token(0) + : _token(0) { } // Create a pointer to the specified JSON token JsonToken(char* json, jsmntok_t* token) - : json(json), token(token) + : _json(json), _token(token) { } @@ -34,13 +34,13 @@ namespace ArduinoJson // Get the number of children tokens int childrenCount() { - return token->size; + return _token->size; } // Get a pointer to the first child of the current token JsonToken firstChild() const { - return JsonToken(json, token + 1); + return JsonToken(_json, _token + 1); } // Get a pointer to the next sibling token (ie skiping the children tokens) @@ -49,37 +49,37 @@ namespace ArduinoJson // Test equality bool operator!=(const JsonToken& other) const { - return token != other.token; + return _token != other._token; } // Tell if the pointer is "null" bool isValid() { - return token != 0; + return _token != 0; } // Tell if the JSON token is a JSON object bool isObject() { - return token != 0 && token->type == JSMN_OBJECT; + return _token != 0 && _token->type == JSMN_OBJECT; } // Tell if the JSON token is a JSON array bool isArray() { - return token != 0 && token->type == JSMN_ARRAY; + return _token != 0 && _token->type == JSMN_ARRAY; } // Tell if the JSON token is a primitive bool isPrimitive() { - return token != 0 && token->type == JSMN_PRIMITIVE; + return _token != 0 && _token->type == JSMN_PRIMITIVE; } // Tell if the JSON token is a string bool isString() { - return token != 0 && token->type == JSMN_STRING; + return _token != 0 && _token->type == JSMN_STRING; } // Explicit wait to create a "null" JsonToken @@ -89,8 +89,8 @@ namespace ArduinoJson } private: - char* json; - jsmntok_t* token; + char* _json; + jsmntok_t* _token; static char unescapeChar(char c); static void unescapeString(char* s);