mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Parse simple strings
This commit is contained in:
@ -70,6 +70,11 @@ bool JsonParser::isSpace()
|
||||
return *_ptr == ' ' || *_ptr == '\t' || *_ptr == '\n' || *_ptr == '\r';
|
||||
}
|
||||
|
||||
bool JsonParser::isString()
|
||||
{
|
||||
return *_ptr == '\"';
|
||||
}
|
||||
|
||||
void JsonParser::skipOneChar()
|
||||
{
|
||||
_ptr++;
|
||||
@ -99,6 +104,9 @@ JsonNode* JsonParser::parseAnything()
|
||||
if (isNull())
|
||||
return parseNull();
|
||||
|
||||
if (isString())
|
||||
return parseString();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -168,3 +176,15 @@ JsonNode* JsonParser::parseNull()
|
||||
|
||||
return _buffer->createStringNode(0);
|
||||
}
|
||||
|
||||
JsonNode* JsonParser::parseString()
|
||||
{
|
||||
const char* s = ++_ptr;
|
||||
|
||||
while (*_ptr != '\"')
|
||||
_ptr++;
|
||||
*_ptr = 0;
|
||||
_ptr++;
|
||||
|
||||
return _buffer->createStringNode(s);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ private:
|
||||
inline bool isLong();
|
||||
inline bool isNull();
|
||||
inline bool isSpace();
|
||||
inline bool isString();
|
||||
|
||||
inline void skipOneChar();
|
||||
inline void skipSpaces();
|
||||
@ -37,6 +38,7 @@ private:
|
||||
inline JsonNode* parseBoolean();
|
||||
inline JsonNode* parseLong();
|
||||
inline JsonNode* parseNull();
|
||||
inline JsonNode* parseString();
|
||||
|
||||
JsonNode *parseDouble();
|
||||
};
|
@ -45,6 +45,11 @@ protected:
|
||||
EXPECT_EQ(expected, static_cast<T>(_array[index]));
|
||||
}
|
||||
|
||||
void elementAtIndexMustBe(int index, const char* expected)
|
||||
{
|
||||
EXPECT_STREQ(expected, static_cast<const char*>(_array[index]));
|
||||
}
|
||||
|
||||
StaticJsonBuffer<42> _jsonBuffer;
|
||||
JsonArray _array;
|
||||
char _jsonString[256];
|
||||
@ -148,3 +153,13 @@ TEST_F(JsonArray_Parser_Tests, TwoNulls)
|
||||
firstElementMustBe(nullCharPtr);
|
||||
secondElementMustBe(nullCharPtr);
|
||||
}
|
||||
|
||||
TEST_F(JsonArray_Parser_Tests, TwoStrings)
|
||||
{
|
||||
whenInputIs("[\"hello\",\"world\"]");
|
||||
|
||||
parseMustSucceed();
|
||||
sizeMustBe(2);
|
||||
firstElementMustBe("hello");
|
||||
secondElementMustBe("world");
|
||||
}
|
Reference in New Issue
Block a user