forked from bblanchon/ArduinoJson
Changed naming convention to avoid shadowing (issue #25)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -16,13 +16,13 @@ namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
JsonArray()
|
||||
: JsonArrayBase(items, N)
|
||||
: JsonArrayBase(_items, N)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
JsonValue items[N];
|
||||
JsonValue _items[N];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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++;
|
||||
|
@ -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<int DIGITS>
|
||||
void add(double value)
|
||||
{
|
||||
if (count >= capacity) return;
|
||||
if (_count >= _capacity) return;
|
||||
|
||||
JsonValue& v = items[count++];
|
||||
JsonValue& v = _items[_count++];
|
||||
v.set<DIGITS>(value);
|
||||
}
|
||||
|
||||
@ -65,14 +65,14 @@ namespace ArduinoJson
|
||||
using JsonPrintable::printTo;
|
||||
|
||||
private:
|
||||
JsonValue* items;
|
||||
int capacity, count;
|
||||
JsonValue* _items;
|
||||
int _capacity, _count;
|
||||
|
||||
template<typename T>
|
||||
void addIfPossible(T value)
|
||||
{
|
||||
if (count < capacity)
|
||||
items[count++] = value;
|
||||
if (_count < _capacity)
|
||||
_items[_count++] = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
JsonObject()
|
||||
: JsonObjectBase(items, N)
|
||||
: JsonObjectBase(_items, N)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
KeyValuePair items[N];
|
||||
KeyValuePair _items[N];
|
||||
};
|
||||
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 <int DIGITS>
|
||||
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&);
|
||||
|
@ -21,4 +21,3 @@ public:
|
||||
#include <Printable.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ namespace ArduinoJson
|
||||
{
|
||||
public:
|
||||
StringBuilder(char* buf, int size)
|
||||
: buffer(buf), capacity(size - 1), length(0)
|
||||
: _buffer(buf), _capacity(size - 1), _length(0)
|
||||
{
|
||||
buffer[0] = 0;
|
||||
_buffer[0] = 0;
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t c);
|
||||
|
||||
private:
|
||||
char* buffer;
|
||||
int capacity;
|
||||
int length;
|
||||
char* _buffer;
|
||||
int _capacity;
|
||||
int _length;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user