mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 12:32:17 +02:00
Replaced non-const references by pointer to follow Google style guide
This commit is contained in:
@ -5,39 +5,39 @@
|
|||||||
class CompactJsonWriter : public JsonWriter
|
class CompactJsonWriter : public JsonWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CompactJsonWriter(Print& sink)
|
explicit CompactJsonWriter(Print* sink)
|
||||||
: JsonWriter(sink)
|
: JsonWriter(sink)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void beginArray()
|
virtual void beginArray()
|
||||||
{
|
{
|
||||||
_length += _sink.write('[');
|
_length += _sink->write('[');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void endArray()
|
virtual void endArray()
|
||||||
{
|
{
|
||||||
_length += _sink.write(']');
|
_length += _sink->write(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeColon()
|
virtual void writeColon()
|
||||||
{
|
{
|
||||||
_length += _sink.write(':');
|
_length += _sink->write(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeComma()
|
virtual void writeComma()
|
||||||
{
|
{
|
||||||
_length += _sink.write(',');
|
_length += _sink->write(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void beginObject()
|
virtual void beginObject()
|
||||||
{
|
{
|
||||||
_length += _sink.write('{');
|
_length += _sink->write('{');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void endObject()
|
virtual void endObject()
|
||||||
{
|
{
|
||||||
_length += _sink.write('}');
|
_length += _sink->write('}');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,25 +21,25 @@ static inline char getSpecialChar(char c)
|
|||||||
return p[1];
|
return p[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline size_t printCharTo(char c, Print& p)
|
static inline size_t printCharTo(char c, Print* p)
|
||||||
{
|
{
|
||||||
char specialChar = getSpecialChar(c);
|
char specialChar = getSpecialChar(c);
|
||||||
|
|
||||||
return specialChar != 0
|
return specialChar != 0
|
||||||
? p.write('\\') + p.write(specialChar)
|
? p->write('\\') + p->write(specialChar)
|
||||||
: p.write(c);
|
: p->write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t EscapedString::printTo(const char* s, Print& p)
|
size_t EscapedString::printTo(const char* s, Print* p)
|
||||||
{
|
{
|
||||||
if (!s) return p.print("null");
|
if (!s) return p->print("null");
|
||||||
|
|
||||||
size_t n = p.write('\"');
|
size_t n = p->write('\"');
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
n += printCharTo(*s++, p);
|
n += printCharTo(*s++, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n + p.write('\"');
|
return n + p->write('\"');
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ namespace ArduinoJson
|
|||||||
class EscapedString
|
class EscapedString
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static size_t printTo(const char*, Print&);
|
static size_t printTo(const char*, Print*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ size_t IndentedPrint::write(uint8_t c)
|
|||||||
if (isNewLine)
|
if (isNewLine)
|
||||||
n += writeTabs();
|
n += writeTabs();
|
||||||
|
|
||||||
n += sink.write(c);
|
n += sink->write(c);
|
||||||
|
|
||||||
isNewLine = c == '\n';
|
isNewLine = c == '\n';
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ 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,7 +19,7 @@ namespace ArduinoJson
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
IndentedPrint(Print& p)
|
IndentedPrint(Print& p)
|
||||||
: sink(p)
|
: sink(&p)
|
||||||
{
|
{
|
||||||
level = 0;
|
level = 0;
|
||||||
tabSize = 2;
|
tabSize = 2;
|
||||||
@ -38,7 +38,7 @@ 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;
|
||||||
|
@ -11,15 +11,15 @@ void JsonWriter::writeString(char const* value)
|
|||||||
void JsonWriter::writeInteger(long value)
|
void JsonWriter::writeInteger(long value)
|
||||||
{
|
{
|
||||||
|
|
||||||
_length += _sink.print(value);
|
_length += _sink->print(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonWriter::writeBoolean(bool value)
|
void JsonWriter::writeBoolean(bool value)
|
||||||
{
|
{
|
||||||
_length += _sink.print(value ? "true" : "false");
|
_length += _sink->print(value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonWriter::writeDouble(double value, int decimals)
|
void JsonWriter::writeDouble(double value, int decimals)
|
||||||
{
|
{
|
||||||
_length += _sink.print(value, decimals);
|
_length += _sink->print(value, decimals);
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
class JsonWriter
|
class JsonWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit JsonWriter(Print& sink)
|
explicit JsonWriter(Print* sink)
|
||||||
: _sink(sink), _length(0)
|
: _sink(sink), _length(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -34,16 +34,16 @@ public:
|
|||||||
|
|
||||||
void writeEmptyArray()
|
void writeEmptyArray()
|
||||||
{
|
{
|
||||||
_length += _sink.print("[]");
|
_length += _sink->print("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEmptyObject()
|
void writeEmptyObject()
|
||||||
{
|
{
|
||||||
_length += _sink.print("{}");
|
_length += _sink->print("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Print& _sink;
|
Print* _sink;
|
||||||
size_t _length;
|
size_t _length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,58 +8,58 @@ using namespace ArduinoJson::Generator;
|
|||||||
class PrettyJsonWriter : public JsonWriter
|
class PrettyJsonWriter : public JsonWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PrettyJsonWriter(IndentedPrint& sink)
|
explicit PrettyJsonWriter(IndentedPrint* sink)
|
||||||
: JsonWriter(sink), _indenter(sink)
|
: JsonWriter(sink), _indenter(sink)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void beginArray()
|
virtual void beginArray()
|
||||||
{
|
{
|
||||||
_length += _sink.write('[');
|
_length += _sink->write('[');
|
||||||
indent();
|
indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void endArray()
|
virtual void endArray()
|
||||||
{
|
{
|
||||||
unindent();
|
unindent();
|
||||||
_length += _sink.write(']');
|
_length += _sink->write(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeColon()
|
virtual void writeColon()
|
||||||
{
|
{
|
||||||
_length += _sink.print(": ");
|
_length += _sink->print(": ");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void writeComma()
|
virtual void writeComma()
|
||||||
{
|
{
|
||||||
_length += _sink.write(',');
|
_length += _sink->write(',');
|
||||||
_length += _indenter.println();
|
_length += _indenter->println();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void beginObject()
|
virtual void beginObject()
|
||||||
{
|
{
|
||||||
_length += _sink.write('{');
|
_length += _sink->write('{');
|
||||||
indent();
|
indent();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void endObject()
|
virtual void endObject()
|
||||||
{
|
{
|
||||||
unindent();
|
unindent();
|
||||||
_length += _sink.write('}');
|
_length += _sink->write('}');
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IndentedPrint& _indenter;
|
IndentedPrint* _indenter;
|
||||||
|
|
||||||
void indent()
|
void indent()
|
||||||
{
|
{
|
||||||
_indenter.indent();
|
_indenter->indent();
|
||||||
_length += _indenter.println();
|
_length += _indenter->println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unindent()
|
void unindent()
|
||||||
{
|
{
|
||||||
_length += _indenter.println();
|
_length += _indenter->println();
|
||||||
_indenter.unindent();
|
_indenter->unindent();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ size_t JsonContainer::printTo(char* buffer, size_t bufferSize) const
|
|||||||
|
|
||||||
size_t JsonContainer::printTo(Print& p) const
|
size_t JsonContainer::printTo(Print& p) const
|
||||||
{
|
{
|
||||||
CompactJsonWriter writer(p);
|
CompactJsonWriter writer(&p);
|
||||||
_node->writeTo(writer);
|
_node->writeTo(writer);
|
||||||
return writer.bytesWritten();
|
return writer.bytesWritten();
|
||||||
}
|
}
|
||||||
@ -28,11 +28,17 @@ size_t JsonContainer::prettyPrintTo(char* buffer, size_t bufferSize) const
|
|||||||
|
|
||||||
size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const
|
size_t JsonContainer::prettyPrintTo(IndentedPrint& p) const
|
||||||
{
|
{
|
||||||
PrettyJsonWriter writer(p);
|
PrettyJsonWriter writer(&p);
|
||||||
_node->writeTo(writer);
|
_node->writeTo(writer);
|
||||||
return writer.bytesWritten();
|
return writer.bytesWritten();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t JsonContainer::prettyPrintTo(Print& print) const
|
||||||
|
{
|
||||||
|
IndentedPrint indentedPrint = IndentedPrint(print);
|
||||||
|
return prettyPrintTo(indentedPrint);
|
||||||
|
}
|
||||||
|
|
||||||
JsonNode* JsonContainer::createNode()
|
JsonNode* JsonContainer::createNode()
|
||||||
{
|
{
|
||||||
if (!_node) return 0;
|
if (!_node) return 0;
|
||||||
|
@ -33,10 +33,7 @@ public:
|
|||||||
|
|
||||||
size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
|
size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
|
||||||
size_t prettyPrintTo(ArduinoJson::Generator::IndentedPrint& print) const;
|
size_t prettyPrintTo(ArduinoJson::Generator::IndentedPrint& print) const;
|
||||||
size_t prettyPrintTo(Print& print) const
|
size_t prettyPrintTo(Print& print) const;
|
||||||
{
|
|
||||||
return prettyPrintTo(ArduinoJson::Generator::IndentedPrint(print));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
@ -60,7 +60,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
@ -11,7 +11,7 @@ protected:
|
|||||||
void whenInputIs(const char* input)
|
void whenInputIs(const char* input)
|
||||||
{
|
{
|
||||||
StringBuilder sb(buffer, sizeof(buffer));
|
StringBuilder sb(buffer, sizeof(buffer));
|
||||||
returnValue = EscapedString::printTo(input, sb);
|
returnValue = EscapedString::printTo(input, &sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void outputMustBe(const char* expected)
|
void outputMustBe(const char* expected)
|
||||||
|
Reference in New Issue
Block a user