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()
|
void IndentedPrint::indent()
|
||||||
{
|
{
|
||||||
if (level < MAX_LEVEL)
|
if (_level < MAX_LEVEL)
|
||||||
level++;
|
_level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndentedPrint::unindent()
|
void IndentedPrint::unindent()
|
||||||
{
|
{
|
||||||
if (level > 0)
|
if (_level > 0)
|
||||||
level--;
|
_level--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndentedPrint::setTabSize(uint8_t n)
|
void IndentedPrint::setTabSize(uint8_t n)
|
||||||
{
|
{
|
||||||
if (n < MAX_TAB_SIZE)
|
if (n < MAX_TAB_SIZE)
|
||||||
tabSize = n;
|
_tabSize = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IndentedPrint::write(uint8_t c)
|
size_t IndentedPrint::write(uint8_t c)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
if (isNewLine)
|
if (_isNewLine)
|
||||||
n += writeTabs();
|
n += writeTabs();
|
||||||
|
|
||||||
n += sink.write(c);
|
n += _sink.write(c);
|
||||||
|
|
||||||
isNewLine = c == '\n';
|
_isNewLine = c == '\n';
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -38,8 +38,8 @@ inline size_t IndentedPrint::writeTabs()
|
|||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
for (int i = 0; i < level*tabSize; i++)
|
for (int i = 0; i < _level*_tabSize; i++)
|
||||||
n += sink.write(' ');
|
n += _sink.write(' ');
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ namespace ArduinoJson
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
IndentedPrint(Print& p)
|
IndentedPrint(Print& p)
|
||||||
: sink(p)
|
: _sink(p)
|
||||||
{
|
{
|
||||||
level = 0;
|
_level = 0;
|
||||||
tabSize = 2;
|
_tabSize = 2;
|
||||||
isNewLine = true;
|
_isNewLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
@ -38,10 +38,10 @@ namespace ArduinoJson
|
|||||||
void setTabSize(uint8_t n);
|
void setTabSize(uint8_t n);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Print& sink;
|
Print& _sink;
|
||||||
uint8_t level : 4;
|
uint8_t _level : 4;
|
||||||
uint8_t tabSize : 3;
|
uint8_t _tabSize : 3;
|
||||||
bool isNewLine : 1;
|
bool _isNewLine : 1;
|
||||||
|
|
||||||
size_t writeTabs();
|
size_t writeTabs();
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonArray()
|
JsonArray()
|
||||||
: JsonArrayBase(items, N)
|
: JsonArrayBase(_items, N)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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
|
// NB: the code has been optimized for a small size on a 8-bit AVR
|
||||||
|
|
||||||
const JsonValue* current = items;
|
const JsonValue* current = _items;
|
||||||
for (int i = count; i > 0; i--)
|
for (int i = _count; i > 0; i--)
|
||||||
{
|
{
|
||||||
n += current->printTo(p);
|
n += current->printTo(p);
|
||||||
current++;
|
current++;
|
||||||
|
@ -16,7 +16,7 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonArrayBase(JsonValue* items, int capacity)
|
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>
|
template<int DIGITS>
|
||||||
void add(double value)
|
void add(double value)
|
||||||
{
|
{
|
||||||
if (count >= capacity) return;
|
if (_count >= _capacity) return;
|
||||||
|
|
||||||
JsonValue& v = items[count++];
|
JsonValue& v = _items[_count++];
|
||||||
v.set<DIGITS>(value);
|
v.set<DIGITS>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,14 +65,14 @@ namespace ArduinoJson
|
|||||||
using JsonPrintable::printTo;
|
using JsonPrintable::printTo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonValue* items;
|
JsonValue* _items;
|
||||||
int capacity, count;
|
int _capacity, _count;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void addIfPossible(T value)
|
void addIfPossible(T value)
|
||||||
{
|
{
|
||||||
if (count < capacity)
|
if (_count < _capacity)
|
||||||
items[count++] = value;
|
_items[_count++] = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,12 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonObject()
|
JsonObject()
|
||||||
: JsonObjectBase(items, N)
|
: JsonObjectBase(_items, N)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyValuePair items[N];
|
KeyValuePair _items[N];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
using namespace ArduinoJson::Generator;
|
using namespace ArduinoJson::Generator;
|
||||||
using namespace ArduinoJson::Internals;
|
using namespace ArduinoJson::Internals;
|
||||||
|
|
||||||
JsonValue JsonObjectBase::nullValue;
|
JsonValue JsonObjectBase::_nullValue;
|
||||||
|
|
||||||
size_t JsonObjectBase::printTo(Print& p) const
|
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
|
// NB: the code has been optimized for a small size on a 8-bit AVR
|
||||||
|
|
||||||
const KeyValuePair* current = items;
|
const KeyValuePair* current = _items;
|
||||||
for (int i = count; i > 0; i--)
|
for (int i = _count; i > 0; i--)
|
||||||
{
|
{
|
||||||
n += EscapedString::printTo(current->key, p);
|
n += EscapedString::printTo(current->key, p);
|
||||||
n += p.write(':');
|
n += p.write(':');
|
||||||
@ -41,9 +41,9 @@ size_t JsonObjectBase::printTo(Print& p) const
|
|||||||
|
|
||||||
JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(JsonKey key) 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))
|
if (!strcmp(p->key, key))
|
||||||
return p;
|
return p;
|
||||||
@ -63,15 +63,15 @@ JsonValue& JsonObjectBase::operator[](JsonKey key)
|
|||||||
|
|
||||||
JsonValue* value;
|
JsonValue* value;
|
||||||
|
|
||||||
if (count < capacity)
|
if (_count < _capacity)
|
||||||
{
|
{
|
||||||
items[count].key = key;
|
_items[_count].key = key;
|
||||||
value = &items[count].value;
|
value = &_items[_count].value;
|
||||||
count++;
|
_count++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = &nullValue;
|
value = &_nullValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
value->reset();
|
value->reset();
|
||||||
@ -88,5 +88,5 @@ void JsonObjectBase::remove(JsonKey key)
|
|||||||
KeyValuePair* match = getMatchingPair(key);
|
KeyValuePair* match = getMatchingPair(key);
|
||||||
if (match == 0) return;
|
if (match == 0) return;
|
||||||
|
|
||||||
*match = items[--count];
|
*match = _items[--_count];
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,14 @@ namespace ArduinoJson
|
|||||||
};
|
};
|
||||||
|
|
||||||
JsonObjectBase(KeyValuePair* items, int capacity)
|
JsonObjectBase(KeyValuePair* items, int capacity)
|
||||||
: items(items), capacity(capacity), count(0)
|
: _items(items), _capacity(capacity), _count(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeyValuePair* items;
|
KeyValuePair* _items;
|
||||||
int capacity, count;
|
int _capacity, _count;
|
||||||
static JsonValue nullValue;
|
static JsonValue _nullValue;
|
||||||
|
|
||||||
KeyValuePair* getMatchingPair(JsonKey key) const;
|
KeyValuePair* getMatchingPair(JsonKey key) const;
|
||||||
};
|
};
|
||||||
|
@ -9,18 +9,18 @@ using namespace ArduinoJson::Generator;
|
|||||||
|
|
||||||
size_t JsonPrettyPrint::write(uint8_t c)
|
size_t JsonPrettyPrint::write(uint8_t c)
|
||||||
{
|
{
|
||||||
size_t n = inString ? handleStringChar(c) : handleMarkupChar(c);
|
size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c);
|
||||||
previousChar = c;
|
_previousChar = c;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t JsonPrettyPrint::handleStringChar(uint8_t c)
|
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)
|
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)
|
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)
|
inline size_t JsonPrettyPrint::handleBlockClose(uint8_t c)
|
||||||
{
|
{
|
||||||
return unindentIfNeeded() + sink.write(c);
|
return unindentIfNeeded() + _sink.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t JsonPrettyPrint::handleColumn()
|
inline size_t JsonPrettyPrint::handleColumn()
|
||||||
{
|
{
|
||||||
return sink.write(':') + sink.write(' ');
|
return _sink.write(':') + _sink.write(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t JsonPrettyPrint::handleComma()
|
inline size_t JsonPrettyPrint::handleComma()
|
||||||
{
|
{
|
||||||
return sink.write(',') + sink.println();
|
return _sink.write(',') + _sink.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t JsonPrettyPrint::handleQuoteOpen()
|
inline size_t JsonPrettyPrint::handleQuoteOpen()
|
||||||
{
|
{
|
||||||
inString = true;
|
_inString = true;
|
||||||
return indentIfNeeded() + sink.write('"');
|
return indentIfNeeded() + _sink.write('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c)
|
inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c)
|
||||||
{
|
{
|
||||||
return indentIfNeeded() + sink.write(c);
|
return indentIfNeeded() + _sink.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonPrettyPrint::indentIfNeeded()
|
size_t JsonPrettyPrint::indentIfNeeded()
|
||||||
{
|
{
|
||||||
if (!inEmptyBlock()) return 0;
|
if (!inEmptyBlock()) return 0;
|
||||||
|
|
||||||
sink.indent();
|
_sink.indent();
|
||||||
return sink.println();
|
return _sink.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonPrettyPrint::unindentIfNeeded()
|
size_t JsonPrettyPrint::unindentIfNeeded()
|
||||||
{
|
{
|
||||||
if (inEmptyBlock()) return 0;
|
if (inEmptyBlock()) return 0;
|
||||||
|
|
||||||
sink.unindent();
|
_sink.unindent();
|
||||||
return sink.println();
|
return _sink.println();
|
||||||
}
|
}
|
||||||
|
@ -18,22 +18,22 @@ namespace ArduinoJson
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
JsonPrettyPrint(IndentedPrint& p)
|
JsonPrettyPrint(IndentedPrint& p)
|
||||||
: sink(p)
|
: _sink(p)
|
||||||
{
|
{
|
||||||
previousChar = 0;
|
_previousChar = 0;
|
||||||
inString = false;
|
_inString = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t previousChar;
|
uint8_t _previousChar;
|
||||||
IndentedPrint& sink;
|
IndentedPrint& _sink;
|
||||||
bool inString;
|
bool _inString;
|
||||||
|
|
||||||
bool inEmptyBlock()
|
bool inEmptyBlock()
|
||||||
{
|
{
|
||||||
return previousChar == '{' || previousChar == '[';
|
return _previousChar == '{' || _previousChar == '[';
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t handleStringChar(uint8_t);
|
size_t handleStringChar(uint8_t);
|
||||||
|
@ -19,32 +19,32 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
void operator=(bool value)
|
void operator=(bool value)
|
||||||
{
|
{
|
||||||
printToImpl = &printBoolTo;
|
_printToImpl = &printBoolTo;
|
||||||
content.asBool = value;
|
_content.asBool = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(long value)
|
void operator=(long value)
|
||||||
{
|
{
|
||||||
printToImpl = &printLongTo;
|
_printToImpl = &printLongTo;
|
||||||
content.asLong = value;
|
_content.asLong = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(int value)
|
void operator=(int value)
|
||||||
{
|
{
|
||||||
printToImpl = &printLongTo;
|
_printToImpl = &printLongTo;
|
||||||
content.asLong = value;
|
_content.asLong = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(const Printable& value)
|
void operator=(const Printable& value)
|
||||||
{
|
{
|
||||||
printToImpl = &printPrintableTo;
|
_printToImpl = &printPrintableTo;
|
||||||
content.asPrintable = &value;
|
_content.asPrintable = &value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(const char* value)
|
void operator=(const char* value)
|
||||||
{
|
{
|
||||||
printToImpl = &printStringTo;
|
_printToImpl = &printStringTo;
|
||||||
content.asString = value;
|
_content.asString = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(double value)
|
void operator=(double value)
|
||||||
@ -55,55 +55,55 @@ namespace ArduinoJson
|
|||||||
template <int DIGITS>
|
template <int DIGITS>
|
||||||
void set(double value)
|
void set(double value)
|
||||||
{
|
{
|
||||||
printToImpl = &printDoubleTo < DIGITS > ;
|
_printToImpl = &printDoubleTo < DIGITS > ;
|
||||||
content.asDouble = value;
|
_content.asDouble = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool()
|
operator bool()
|
||||||
{
|
{
|
||||||
return content.asBool;
|
return _content.asBool;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const char*()
|
operator const char*()
|
||||||
{
|
{
|
||||||
return content.asString;
|
return _content.asString;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator double()
|
operator double()
|
||||||
{
|
{
|
||||||
return content.asDouble;
|
return _content.asDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator float()
|
operator float()
|
||||||
{
|
{
|
||||||
return (float)content.asDouble;
|
return (float)_content.asDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator int()
|
operator int()
|
||||||
{
|
{
|
||||||
return content.asLong;
|
return _content.asLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator long()
|
operator long()
|
||||||
{
|
{
|
||||||
return content.asLong;
|
return _content.asLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const Printable&()
|
operator const Printable&()
|
||||||
{
|
{
|
||||||
return *content.asPrintable;
|
return *_content.asPrintable;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t printTo(Print& p) const
|
size_t printTo(Print& p) const
|
||||||
{
|
{
|
||||||
// handmade polymorphism
|
// handmade polymorphism
|
||||||
return printToImpl(content, p);
|
return _printToImpl(_content, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
content.asDouble = 0;
|
_content.asDouble = 0;
|
||||||
printToImpl = printStringTo;
|
_printToImpl = printStringTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -116,9 +116,9 @@ namespace ArduinoJson
|
|||||||
const char* asString;
|
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 printBoolTo(const Content&, Print&);
|
||||||
static size_t printLongTo(const Content&, Print&);
|
static size_t printLongTo(const Content&, Print&);
|
||||||
|
@ -21,4 +21,3 @@ public:
|
|||||||
#include <Printable.h>
|
#include <Printable.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ using namespace ArduinoJson::Internals;
|
|||||||
|
|
||||||
size_t StringBuilder::write(uint8_t c)
|
size_t StringBuilder::write(uint8_t c)
|
||||||
{
|
{
|
||||||
if (length >= capacity) return 0;
|
if (_length >= _capacity) return 0;
|
||||||
|
|
||||||
buffer[length++] = c;
|
_buffer[_length++] = c;
|
||||||
buffer[length] = 0;
|
_buffer[_length] = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
* Arduino JSON library
|
* Arduino JSON library
|
||||||
* Benoit Blanchon 2014 - MIT License
|
* Benoit Blanchon 2014 - MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
namespace ArduinoJson
|
namespace ArduinoJson
|
||||||
{
|
{
|
||||||
namespace Internals
|
namespace Internals
|
||||||
{
|
{
|
||||||
class StringBuilder : public Print
|
class StringBuilder : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringBuilder(char* buf, int size)
|
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);
|
virtual size_t write(uint8_t c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* buffer;
|
char* _buffer;
|
||||||
int capacity;
|
int _capacity;
|
||||||
int length;
|
int _length;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,12 @@ namespace ArduinoJson
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JsonParser()
|
JsonParser()
|
||||||
: JsonParserBase(tokens, MAX_TOKENS)
|
: JsonParserBase(_tokens, MAX_TOKENS)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
jsmntok_t tokens[MAX_TOKENS];
|
jsmntok_t _tokens[MAX_TOKENS];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ JsonValue JsonParserBase::parse(char* json)
|
|||||||
jsmn_parser parser;
|
jsmn_parser parser;
|
||||||
jsmn_init(&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::null();
|
||||||
|
|
||||||
return JsonToken(json, tokens);
|
return JsonToken(json, _tokens);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace ArduinoJson
|
|||||||
|
|
||||||
// Create a JSON parser using the provided buffer
|
// Create a JSON parser using the provided buffer
|
||||||
JsonParserBase(jsmntok_t* tokens, int maxTokens)
|
JsonParserBase(jsmntok_t* tokens, int maxTokens)
|
||||||
: tokens(tokens), maxTokens(maxTokens)
|
: _tokens(tokens), _maxTokens(maxTokens)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ namespace ArduinoJson
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
jsmntok_t* tokens;
|
jsmntok_t* _tokens;
|
||||||
int maxTokens;
|
int _maxTokens;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ using namespace ArduinoJson::Parser;
|
|||||||
|
|
||||||
char* JsonToken::getText()
|
char* JsonToken::getText()
|
||||||
{
|
{
|
||||||
char* s = json + token->start;
|
char* s = _json + _token->start;
|
||||||
json[token->end] = 0;
|
_json[_token->end] = 0;
|
||||||
|
|
||||||
unescapeString(s);
|
unescapeString(s);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ inline char JsonToken::unescapeChar(char c)
|
|||||||
JsonToken JsonToken::nextSibling() const
|
JsonToken JsonToken::nextSibling() const
|
||||||
{
|
{
|
||||||
// start with current token
|
// start with current token
|
||||||
jsmntok_t* t = token;
|
jsmntok_t* t = _token;
|
||||||
|
|
||||||
// count the number of token to skip
|
// count the number of token to skip
|
||||||
int yetToVisit = 1;
|
int yetToVisit = 1;
|
||||||
@ -67,5 +67,5 @@ JsonToken JsonToken::nextSibling() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build a JsonToken at the new location
|
// 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
|
// Create a "null" pointer
|
||||||
JsonToken()
|
JsonToken()
|
||||||
: token(0)
|
: _token(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a pointer to the specified JSON token
|
// Create a pointer to the specified JSON token
|
||||||
JsonToken(char* json, jsmntok_t* 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
|
// Get the number of children tokens
|
||||||
int childrenCount()
|
int childrenCount()
|
||||||
{
|
{
|
||||||
return token->size;
|
return _token->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a pointer to the first child of the current token
|
// Get a pointer to the first child of the current token
|
||||||
JsonToken firstChild() const
|
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)
|
// Get a pointer to the next sibling token (ie skiping the children tokens)
|
||||||
@ -49,37 +49,37 @@ namespace ArduinoJson
|
|||||||
// Test equality
|
// Test equality
|
||||||
bool operator!=(const JsonToken& other) const
|
bool operator!=(const JsonToken& other) const
|
||||||
{
|
{
|
||||||
return token != other.token;
|
return _token != other._token;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell if the pointer is "null"
|
// Tell if the pointer is "null"
|
||||||
bool isValid()
|
bool isValid()
|
||||||
{
|
{
|
||||||
return token != 0;
|
return _token != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell if the JSON token is a JSON object
|
// Tell if the JSON token is a JSON object
|
||||||
bool isObject()
|
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
|
// Tell if the JSON token is a JSON array
|
||||||
bool isArray()
|
bool isArray()
|
||||||
{
|
{
|
||||||
return token != 0 && token->type == JSMN_ARRAY;
|
return _token != 0 && _token->type == JSMN_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell if the JSON token is a primitive
|
// Tell if the JSON token is a primitive
|
||||||
bool isPrimitive()
|
bool isPrimitive()
|
||||||
{
|
{
|
||||||
return token != 0 && token->type == JSMN_PRIMITIVE;
|
return _token != 0 && _token->type == JSMN_PRIMITIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell if the JSON token is a string
|
// Tell if the JSON token is a string
|
||||||
bool isString()
|
bool isString()
|
||||||
{
|
{
|
||||||
return token != 0 && token->type == JSMN_STRING;
|
return _token != 0 && _token->type == JSMN_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit wait to create a "null" JsonToken
|
// Explicit wait to create a "null" JsonToken
|
||||||
@ -89,8 +89,8 @@ namespace ArduinoJson
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* json;
|
char* _json;
|
||||||
jsmntok_t* token;
|
jsmntok_t* _token;
|
||||||
|
|
||||||
static char unescapeChar(char c);
|
static char unescapeChar(char c);
|
||||||
static void unescapeString(char* s);
|
static void unescapeString(char* s);
|
||||||
|
Reference in New Issue
Block a user