From e7864c95666b6b8c3610e5b3d6b5e53829b9bc3c Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 6 Nov 2014 14:29:29 +0100 Subject: [PATCH] Use Print& instead of Print* --- include/ArduinoJson/Internals/JsonPrintable.hpp | 4 ++-- include/ArduinoJson/Internals/JsonWriter.hpp | 8 ++++---- include/ArduinoJson/Internals/PrettyJsonWriter.hpp | 10 +++++----- include/ArduinoJson/Internals/QuotedString.hpp | 2 +- src/Internals/JsonWriter.cpp | 6 +++--- src/Internals/QuotedString.cpp | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/ArduinoJson/Internals/JsonPrintable.hpp b/include/ArduinoJson/Internals/JsonPrintable.hpp index 1ed580ff..3553d2a7 100644 --- a/include/ArduinoJson/Internals/JsonPrintable.hpp +++ b/include/ArduinoJson/Internals/JsonPrintable.hpp @@ -21,7 +21,7 @@ template 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(); } diff --git a/include/ArduinoJson/Internals/JsonWriter.hpp b/include/ArduinoJson/Internals/JsonWriter.hpp index 4bfa64bf..629d2f16 100644 --- a/include/ArduinoJson/Internals/JsonWriter.hpp +++ b/include/ArduinoJson/Internals/JsonWriter.hpp @@ -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; }; } diff --git a/include/ArduinoJson/Internals/PrettyJsonWriter.hpp b/include/ArduinoJson/Internals/PrettyJsonWriter.hpp index ff357491..dfacd60a 100644 --- a/include/ArduinoJson/Internals/PrettyJsonWriter.hpp +++ b/include/ArduinoJson/Internals/PrettyJsonWriter.hpp @@ -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; }; } } diff --git a/include/ArduinoJson/Internals/QuotedString.hpp b/include/ArduinoJson/Internals/QuotedString.hpp index 96e11faf..9fb21a21 100644 --- a/include/ArduinoJson/Internals/QuotedString.hpp +++ b/include/ArduinoJson/Internals/QuotedString.hpp @@ -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 ("). diff --git a/src/Internals/JsonWriter.cpp b/src/Internals/JsonWriter.cpp index 9a60608b..3124ae01 100644 --- a/src/Internals/JsonWriter.cpp +++ b/src/Internals/JsonWriter.cpp @@ -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); } diff --git a/src/Internals/QuotedString.cpp b/src/Internals/QuotedString.cpp index 9f2f1aff..be93a12f 100644 --- a/src/Internals/QuotedString.cpp +++ b/src/Internals/QuotedString.cpp @@ -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) {