forked from bblanchon/ArduinoJson
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 (").
|
||||
|
Reference in New Issue
Block a user