forked from bblanchon/ArduinoJson
Test an object with comma, quote and column in the value
This commit is contained in:
@ -11,33 +11,50 @@ size_t IndentedPrintDecorator::write(uint8_t c)
|
|||||||
{
|
{
|
||||||
case '{':
|
case '{':
|
||||||
indent++;
|
indent++;
|
||||||
emptyBlock = true;
|
previousChar = c;
|
||||||
return sink.write(c);
|
return sink.write(c);
|
||||||
|
|
||||||
case '}':
|
case '}':
|
||||||
indent--;
|
indent--;
|
||||||
|
|
||||||
if (emptyBlock)
|
if (previousChar == '{')
|
||||||
|
{
|
||||||
|
previousChar = c;
|
||||||
|
return sink.write(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
previousChar = c;
|
||||||
|
return writeln() + sink.write(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
case ',':
|
||||||
|
previousChar = c;
|
||||||
|
if (isInAString)
|
||||||
{
|
{
|
||||||
return sink.write(c);
|
return sink.write(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return writeln() + sink.write(c);
|
return sink.write(c) + writeln();
|
||||||
}
|
}
|
||||||
|
|
||||||
case ',':
|
case '\"':
|
||||||
return sink.write(c) + writeln();
|
if (previousChar != '\\')
|
||||||
|
{
|
||||||
|
isInAString = !isInAString;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if (emptyBlock)
|
if (previousChar == '{')
|
||||||
{
|
{
|
||||||
emptyBlock = false;
|
previousChar = c;
|
||||||
return writeln() + sink.write(c);
|
return writeln() + sink.write(c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
previousChar = c;
|
||||||
return sink.write(c);
|
return sink.write(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,19 @@ class IndentedPrintDecorator : public Print
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
IndentedPrintDecorator(Print& p)
|
IndentedPrintDecorator(Print& p)
|
||||||
: indent(0), sink(p), emptyBlock(false)
|
: indent(0), sink(p)
|
||||||
{
|
{
|
||||||
|
previousChar = 0;
|
||||||
|
isInAString = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int indent;
|
int indent;
|
||||||
bool emptyBlock;
|
uint8_t previousChar;
|
||||||
Print& sink;
|
Print& sink;
|
||||||
|
bool isInAString;
|
||||||
|
|
||||||
size_t writeln();
|
size_t writeln();
|
||||||
};
|
};
|
||||||
|
@ -56,6 +56,15 @@ namespace JsonGeneratorTests
|
|||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(ObjectTrickyCharacters)
|
||||||
|
{
|
||||||
|
whenInputIs("{\"key\":\":\\\"',\"}");
|
||||||
|
outputMustBe(
|
||||||
|
"{\n"
|
||||||
|
" \"key\":\":\\\"',\"\n"
|
||||||
|
"}");
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void whenInputIs(const char input[])
|
void whenInputIs(const char input[])
|
||||||
|
Reference in New Issue
Block a user