mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 12:32:17 +02:00
Use Print& instead of Print*
This commit is contained in:
@ -21,7 +21,7 @@ template <typename T>
|
||||
class JsonPrintable {
|
||||
public:
|
||||
size_t printTo(Print &print) const {
|
||||
JsonWriter writer(&print);
|
||||
JsonWriter writer(print);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
@ -32,7 +32,7 @@ class JsonPrintable {
|
||||
}
|
||||
|
||||
size_t prettyPrintTo(IndentedPrint &print) const {
|
||||
PrettyJsonWriter writer(&print);
|
||||
PrettyJsonWriter writer(print);
|
||||
downcast().writeTo(writer);
|
||||
return writer.bytesWritten();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace Internals {
|
||||
// indentation.
|
||||
class JsonWriter {
|
||||
public:
|
||||
explicit JsonWriter(Print *sink) : _sink(sink), _length(0) {}
|
||||
explicit JsonWriter(Print &sink) : _sink(sink), _length(0) {}
|
||||
|
||||
// Returns the number of bytes sent to the Print implementation.
|
||||
// This is very handy for implementations of printTo() that must return the
|
||||
@ -44,10 +44,10 @@ class JsonWriter {
|
||||
void writeComma() { write(','); }
|
||||
|
||||
protected:
|
||||
void write(char c) { _length += _sink->write(c); }
|
||||
void write(const char *s) { _length += _sink->print(s); }
|
||||
void write(char c) { _length += _sink.write(c); }
|
||||
void write(const char *s) { _length += _sink.print(s); }
|
||||
|
||||
Print *_sink;
|
||||
Print &_sink;
|
||||
size_t _length;
|
||||
};
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace Internals {
|
||||
// An indented version of JsonWriter.
|
||||
class PrettyJsonWriter : public JsonWriter {
|
||||
public:
|
||||
explicit PrettyJsonWriter(IndentedPrint *sink)
|
||||
explicit PrettyJsonWriter(IndentedPrint &sink)
|
||||
: JsonWriter(sink), _indenter(sink) {}
|
||||
|
||||
void beginArray() {
|
||||
@ -47,18 +47,18 @@ class PrettyJsonWriter : public JsonWriter {
|
||||
|
||||
private:
|
||||
void indent() {
|
||||
_indenter->indent();
|
||||
_indenter.indent();
|
||||
newline();
|
||||
}
|
||||
|
||||
void unindent() {
|
||||
newline();
|
||||
_indenter->unindent();
|
||||
_indenter.unindent();
|
||||
}
|
||||
|
||||
void newline() { _length += _indenter->println(); }
|
||||
void newline() { _length += _indenter.println(); }
|
||||
|
||||
IndentedPrint *_indenter;
|
||||
IndentedPrint &_indenter;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class QuotedString {
|
||||
// Writes a doubly-quote string to a Print implementation.
|
||||
// It adds the double quotes (") at the beginning and the end of the string.
|
||||
// It escapes the special characters as required by the JSON specifications.
|
||||
static size_t printTo(const char *, Print *);
|
||||
static size_t printTo(const char *, Print &);
|
||||
|
||||
// Reads a doubly-quoted string from a buffer.
|
||||
// It removes the double quotes (").
|
||||
|
@ -14,12 +14,12 @@ void JsonWriter::writeString(char const *value) {
|
||||
_length += QuotedString::printTo(value, _sink);
|
||||
}
|
||||
|
||||
void JsonWriter::writeInteger(long value) { _length += _sink->print(value); }
|
||||
void JsonWriter::writeInteger(long value) { _length += _sink.print(value); }
|
||||
|
||||
void JsonWriter::writeBoolean(bool value) {
|
||||
_length += _sink->print(value ? "true" : "false");
|
||||
_length += _sink.print(value ? "true" : "false");
|
||||
}
|
||||
|
||||
void JsonWriter::writeDouble(double value, uint8_t decimals) {
|
||||
_length += _sink->print(value, decimals);
|
||||
_length += _sink.print(value, decimals);
|
||||
}
|
||||
|
@ -20,22 +20,22 @@ static inline char getSpecialChar(char c) {
|
||||
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);
|
||||
|
||||
return specialChar ? p->write('\\') + p->write(specialChar) : p->write(c);
|
||||
return specialChar ? p.write('\\') + p.write(specialChar) : p.write(c);
|
||||
}
|
||||
|
||||
size_t QuotedString::printTo(const char *s, Print *p) {
|
||||
if (!s) return p->print("null");
|
||||
size_t QuotedString::printTo(const char *s, Print &p) {
|
||||
if (!s) return p.print("null");
|
||||
|
||||
size_t n = p->write('\"');
|
||||
size_t n = p.write('\"');
|
||||
|
||||
while (*s) {
|
||||
n += printCharTo(*s++, p);
|
||||
}
|
||||
|
||||
return n + p->write('\"');
|
||||
return n + p.write('\"');
|
||||
}
|
||||
|
||||
static char unescapeChar(char c) {
|
||||
|
Reference in New Issue
Block a user