From 0814fc185f44b53aa3fa61f4bc9e5994a0edcb2e Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 16 Feb 2020 15:05:23 +0100 Subject: [PATCH] Added a line-break after each "if" to get more accurate coverage report --- .clang-format | 3 + src/ArduinoJson/Array/ArrayFunctions.hpp | 7 +- src/ArduinoJson/Array/ArrayRef.hpp | 15 +- src/ArduinoJson/Collection/CollectionImpl.hpp | 45 +++-- .../Deserialization/Readers/FlashReader.hpp | 3 +- .../Document/BasicJsonDocument.hpp | 6 +- src/ArduinoJson/Json/EscapeSequence.hpp | 6 +- src/ArduinoJson/Json/JsonDeserializer.hpp | 174 ++++++++++++------ src/ArduinoJson/Json/JsonSerializer.hpp | 6 +- src/ArduinoJson/Json/Latch.hpp | 3 +- src/ArduinoJson/Json/PrettyJsonSerializer.hpp | 6 +- src/ArduinoJson/Json/TextFormatter.hpp | 12 +- src/ArduinoJson/Memory/MemoryPool.hpp | 9 +- src/ArduinoJson/Memory/StringBuilder.hpp | 3 +- .../MsgPack/MsgPackDeserializer.hpp | 69 ++++--- src/ArduinoJson/MsgPack/MsgPackSerializer.hpp | 3 +- src/ArduinoJson/Numbers/FloatTraits.hpp | 12 +- src/ArduinoJson/Numbers/parseNumber.hpp | 21 ++- src/ArduinoJson/Object/ObjectFunctions.hpp | 21 ++- src/ArduinoJson/Object/ObjectRef.hpp | 15 +- src/ArduinoJson/Polyfills/pgmspace.hpp | 18 +- src/ArduinoJson/Polyfills/safe_strcmp.hpp | 18 +- .../Writers/ArduinoStringWriter.hpp | 3 +- .../Writers/StaticStringWriter.hpp | 3 +- .../Strings/ArduinoStringAdapter.hpp | 6 +- .../Strings/ConstRamStringAdapter.hpp | 3 +- .../Strings/FlashStringAdapter.hpp | 18 +- src/ArduinoJson/Strings/RamStringAdapter.hpp | 6 +- .../Strings/SizedFlashStringAdapter.hpp | 15 +- .../Strings/SizedRamStringAdapter.hpp | 6 +- src/ArduinoJson/Strings/StlStringAdapter.hpp | 9 +- src/ArduinoJson/Strings/String.hpp | 9 +- src/ArduinoJson/Variant/SlotFunctions.hpp | 6 +- src/ArduinoJson/Variant/VariantAsImpl.hpp | 3 +- src/ArduinoJson/Variant/VariantData.hpp | 24 ++- src/ArduinoJson/Variant/VariantFunctions.hpp | 39 ++-- src/ArduinoJson/Variant/VariantRef.hpp | 9 +- src/ArduinoJson/Variant/VariantSlot.hpp | 9 +- 38 files changed, 429 insertions(+), 214 deletions(-) diff --git a/.clang-format b/.clang-format index 36809363..b375ca28 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,6 @@ BasedOnStyle: Google Standard: Cpp03 AllowShortFunctionsOnASingleLine: Empty + +# Always break after if to get accurate coverage +AllowShortIfStatementsOnASingleLine: false diff --git a/src/ArduinoJson/Array/ArrayFunctions.hpp b/src/ArduinoJson/Array/ArrayFunctions.hpp index 8d29e6c4..b50fce7f 100644 --- a/src/ArduinoJson/Array/ArrayFunctions.hpp +++ b/src/ArduinoJson/Array/ArrayFunctions.hpp @@ -21,9 +21,10 @@ inline void arrayAccept(const CollectionData *arr, Visitor &visitor) { } inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) { - if (lhs == rhs) return true; - if (!lhs || !rhs) return false; - + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; return lhs->equalsArray(*rhs); } } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Array/ArrayRef.hpp b/src/ArduinoJson/Array/ArrayRef.hpp index e451066e..ff024652 100644 --- a/src/ArduinoJson/Array/ArrayRef.hpp +++ b/src/ArduinoJson/Array/ArrayRef.hpp @@ -66,7 +66,8 @@ class ArrayConstRef : public ArrayRefBase, typedef ArrayConstRefIterator iterator; FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_data->head()); } @@ -116,7 +117,8 @@ class ArrayRef : public ArrayRefBase, } FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_pool, _data->head()); } @@ -126,7 +128,8 @@ class ArrayRef : public ArrayRefBase, // Copy a ArrayRef FORCE_INLINE bool set(ArrayConstRef src) const { - if (!_data || !src._data) return false; + if (!_data || !src._data) + return false; return _data->copyFrom(*src._data, _pool); } @@ -141,13 +144,15 @@ class ArrayRef : public ArrayRefBase, // Removes element at specified position. FORCE_INLINE void remove(iterator it) const { - if (!_data) return; + if (!_data) + return; _data->remove(it.internal()); } // Removes element at specified index. FORCE_INLINE void remove(size_t index) const { - if (!_data) return; + if (!_data) + return; _data->remove(index); } diff --git a/src/ArduinoJson/Collection/CollectionImpl.hpp b/src/ArduinoJson/Collection/CollectionImpl.hpp index 1a7038cd..3f7e39b6 100644 --- a/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -11,7 +11,8 @@ namespace ARDUINOJSON_NAMESPACE { inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { VariantSlot* slot = pool->allocVariant(); - if (!slot) return 0; + if (!slot) + return 0; if (_tail) { _tail->setNextNotNull(slot); @@ -32,7 +33,8 @@ inline VariantData* CollectionData::add(MemoryPool* pool) { template inline VariantData* CollectionData::add(TAdaptedString key, MemoryPool* pool) { VariantSlot* slot = addSlot(pool); - if (!slotSetKey(slot, key, pool)) return 0; + if (!slotSetKey(slot, key, pool)) + return 0; return slot->data(); } @@ -59,8 +61,10 @@ inline bool CollectionData::copyFrom(const CollectionData& src, } else { var = add(pool); } - if (!var) return false; - if (!var->copyFrom(*s->data(), pool)) return false; + if (!var) + return false; + if (!var->copyFrom(*s->data(), pool)) + return false; } return true; } @@ -70,7 +74,8 @@ inline bool CollectionData::equalsObject(const CollectionData& other) const { for (VariantSlot* slot = _head; slot; slot = slot->next()) { VariantData* v1 = slot->data(); VariantData* v2 = other.get(adaptString(slot->key())); - if (!variantEquals(v1, v2)) return false; + if (!variantEquals(v1, v2)) + return false; count++; } return count == other.size(); @@ -80,9 +85,12 @@ inline bool CollectionData::equalsArray(const CollectionData& other) const { VariantSlot* s1 = _head; VariantSlot* s2 = other._head; for (;;) { - if (s1 == s2) return true; - if (!s1 || !s2) return false; - if (!variantEquals(s1->data(), s2->data())) return false; + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; + if (!variantEquals(s1->data(), s2->data())) + return false; s1 = s1->next(); s2 = s2->next(); } @@ -92,7 +100,8 @@ template inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { VariantSlot* slot = _head; while (slot) { - if (key.equals(slot->key())) break; + if (key.equals(slot->key())) + break; slot = slot->next(); } return slot; @@ -106,7 +115,8 @@ inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const { VariantSlot* current = _head; while (current) { VariantSlot* next = current->next(); - if (next == target) return current; + if (next == target) + return current; current = next; } return 0; @@ -124,14 +134,16 @@ inline VariantData* CollectionData::get(size_t index) const { } inline void CollectionData::remove(VariantSlot* slot) { - if (!slot) return; + if (!slot) + return; VariantSlot* prev = getPreviousSlot(slot); VariantSlot* next = slot->next(); if (prev) prev->setNext(next); else _head = next; - if (!next) _tail = prev; + if (!next) + _tail = prev; } inline void CollectionData::remove(size_t index) { @@ -142,7 +154,8 @@ inline size_t CollectionData::memoryUsage() const { size_t total = 0; for (VariantSlot* s = _head; s; s = s->next()) { total += sizeof(VariantSlot) + s->data()->memoryUsage(); - if (s->ownsKey()) total += strlen(s->key()) + 1; + if (s->ownsKey()) + total += strlen(s->key()) + 1; } return total; } @@ -151,7 +164,8 @@ inline size_t CollectionData::nesting() const { size_t maxChildNesting = 0; for (VariantSlot* s = _head; s; s = s->next()) { size_t childNesting = s->data()->nesting(); - if (childNesting > maxChildNesting) maxChildNesting = childNesting; + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; } return maxChildNesting + 1; } @@ -162,7 +176,8 @@ inline size_t CollectionData::size() const { template inline void movePointer(T*& p, ptrdiff_t offset) { - if (!p) return; + if (!p) + return; p = reinterpret_cast( reinterpret_cast(reinterpret_cast(p) + offset)); ARDUINOJSON_ASSERT(isAligned(p)); diff --git a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index f6cd0d55..36b7fde6 100644 --- a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -43,7 +43,8 @@ struct BoundedReader { size_t readBytes(char* buffer, size_t length) { size_t available = static_cast(_end - _ptr); - if (available < length) length = available; + if (available < length) + length = available; memcpy_P(buffer, _ptr, length); _ptr += length; return length; diff --git a/src/ArduinoJson/Document/BasicJsonDocument.hpp b/src/ArduinoJson/Document/BasicJsonDocument.hpp index 397a2b7a..0550168a 100644 --- a/src/ArduinoJson/Document/BasicJsonDocument.hpp +++ b/src/ArduinoJson/Document/BasicJsonDocument.hpp @@ -77,7 +77,8 @@ class BasicJsonDocument : AllocatorOwner, public JsonDocument { void shrinkToFit() { ptrdiff_t bytes_reclaimed = _pool.squash(); - if (bytes_reclaimed == 0) return; + if (bytes_reclaimed == 0) + return; void* old_ptr = _pool.buffer(); void* new_ptr = this->reallocate(old_ptr, _pool.capacity()); @@ -96,7 +97,8 @@ class BasicJsonDocument : AllocatorOwner, public JsonDocument { } void reallocPoolIfTooSmall(size_t requiredSize) { - if (requiredSize <= capacity()) return; + if (requiredSize <= capacity()) + return; freePool(); replacePool(allocPool(addPadding(requiredSize))); } diff --git a/src/ArduinoJson/Json/EscapeSequence.hpp b/src/ArduinoJson/Json/EscapeSequence.hpp index 0149bd39..90dee26c 100644 --- a/src/ArduinoJson/Json/EscapeSequence.hpp +++ b/src/ArduinoJson/Json/EscapeSequence.hpp @@ -23,8 +23,10 @@ class EscapeSequence { static char unescapeChar(char c) { const char *p = escapeTable(true); for (;;) { - if (p[0] == '\0') return c; - if (p[0] == c) return p[1]; + if (p[0] == '\0') + return c; + if (p[0] == c) + return p[1]; p += 2; } } diff --git a/src/ArduinoJson/Json/JsonDeserializer.hpp b/src/ArduinoJson/Json/JsonDeserializer.hpp index 12e78a6e..e4e31e04 100644 --- a/src/ArduinoJson/Json/JsonDeserializer.hpp +++ b/src/ArduinoJson/Json/JsonDeserializer.hpp @@ -52,7 +52,8 @@ class JsonDeserializer { } bool eat(char charToSkip) { - if (current() != charToSkip) return false; + if (current() != charToSkip) + return false; move(); return true; } @@ -61,7 +62,8 @@ class JsonDeserializer { DeserializationError parseVariant(VariantData &variant, TFilter filter, NestingLimit nestingLimit) { DeserializationError err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; switch (current()) { case '[': @@ -93,7 +95,8 @@ class JsonDeserializer { DeserializationError skipVariant(NestingLimit nestingLimit) { DeserializationError err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; switch (current()) { case '[': @@ -114,7 +117,8 @@ class JsonDeserializer { template DeserializationError parseArray(CollectionData &array, TFilter filter, NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; // Skip opening braket ARDUINOJSON_ASSERT(current() == '['); @@ -122,10 +126,12 @@ class JsonDeserializer { // Skip spaces DeserializationError err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // Empty array? - if (eat(']')) return DeserializationError::Ok; + if (eat(']')) + return DeserializationError::Ok; TFilter memberFilter = filter[0UL]; @@ -134,28 +140,35 @@ class JsonDeserializer { if (memberFilter.allow()) { // Allocate slot in array VariantData *value = array.add(_pool); - if (!value) return DeserializationError::NoMemory; + if (!value) + return DeserializationError::NoMemory; // 1 - Parse value err = parseVariant(*value, memberFilter, nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } else { err = skipVariant(nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } // 2 - Skip spaces err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // 3 - More values? - if (eat(']')) return DeserializationError::Ok; - if (!eat(',')) return DeserializationError::InvalidInput; + if (eat(']')) + return DeserializationError::Ok; + if (!eat(',')) + return DeserializationError::InvalidInput; } } DeserializationError skipArray(NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; // Skip opening braket ARDUINOJSON_ASSERT(current() == '['); @@ -165,22 +178,27 @@ class JsonDeserializer { for (;;) { // 1 - Skip value DeserializationError err = skipVariant(nestingLimit.decrement()); - if (err) return err; + if (err) + return err; // 2 - Skip spaces err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // 3 - More values? - if (eat(']')) return DeserializationError::Ok; - if (!eat(',')) return DeserializationError::InvalidInput; + if (eat(']')) + return DeserializationError::Ok; + if (!eat(',')) + return DeserializationError::InvalidInput; } } template DeserializationError parseObject(CollectionData &object, TFilter filter, NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; // Skip opening brace ARDUINOJSON_ASSERT(current() == '{'); @@ -188,22 +206,27 @@ class JsonDeserializer { // Skip spaces DeserializationError err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // Empty object? - if (eat('}')) return DeserializationError::Ok; + if (eat('}')) + return DeserializationError::Ok; // Read each key value pair for (;;) { // Parse key const char *key; err = parseKey(key); - if (err) return err; + if (err) + return err; // Skip spaces err = skipSpacesAndComments(); - if (err) return err; // Colon - if (!eat(':')) return DeserializationError::InvalidInput; + if (err) + return err; // Colon + if (!eat(':')) + return DeserializationError::InvalidInput; TFilter memberFilter = filter[key]; @@ -212,7 +235,8 @@ class JsonDeserializer { if (!variant) { // Allocate slot in object VariantSlot *slot = object.addSlot(_pool); - if (!slot) return DeserializationError::NoMemory; + if (!slot) + return DeserializationError::NoMemory; slot->setOwnedKey(make_not_null(key)); @@ -221,29 +245,36 @@ class JsonDeserializer { // Parse value err = parseVariant(*variant, memberFilter, nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } else { _stringStorage.reclaim(key); err = skipVariant(nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } // Skip spaces err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // More keys/values? - if (eat('}')) return DeserializationError::Ok; - if (!eat(',')) return DeserializationError::InvalidInput; + if (eat('}')) + return DeserializationError::Ok; + if (!eat(',')) + return DeserializationError::InvalidInput; // Skip spaces err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; } } DeserializationError skipObject(NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; // Skip opening brace ARDUINOJSON_ASSERT(current() == '{'); @@ -251,33 +282,42 @@ class JsonDeserializer { // Skip spaces DeserializationError err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // Empty object? - if (eat('}')) return DeserializationError::Ok; + if (eat('}')) + return DeserializationError::Ok; // Read each key value pair for (;;) { // Skip key err = skipVariant(nestingLimit.decrement()); - if (err) return err; + if (err) + return err; // Skip spaces err = skipSpacesAndComments(); - if (err) return err; // Colon - if (!eat(':')) return DeserializationError::InvalidInput; + if (err) + return err; // Colon + if (!eat(':')) + return DeserializationError::InvalidInput; // Skip value err = skipVariant(nestingLimit.decrement()); - if (err) return err; + if (err) + return err; // Skip spaces err = skipSpacesAndComments(); - if (err) return err; + if (err) + return err; // More keys/values? - if (eat('}')) return DeserializationError::Ok; - if (!eat(',')) return DeserializationError::InvalidInput; + if (eat('}')) + return DeserializationError::Ok; + if (!eat(',')) + return DeserializationError::InvalidInput; } } @@ -292,7 +332,8 @@ class JsonDeserializer { DeserializationError parseStringValue(VariantData &variant) { const char *value; DeserializationError err = parseQuotedString(value); - if (err) return err; + if (err) + return err; variant.setOwnedString(make_not_null(value)); return DeserializationError::Ok; } @@ -308,19 +349,23 @@ class JsonDeserializer { for (;;) { char c = current(); move(); - if (c == stopChar) break; + if (c == stopChar) + break; - if (c == '\0') return DeserializationError::IncompleteInput; + if (c == '\0') + return DeserializationError::IncompleteInput; if (c == '\\') { c = current(); - if (c == '\0') return DeserializationError::IncompleteInput; + if (c == '\0') + return DeserializationError::IncompleteInput; if (c == 'u') { #if ARDUINOJSON_DECODE_UNICODE move(); uint16_t codeunit; DeserializationError err = parseHex4(codeunit); - if (err) return err; + if (err) + return err; if (codepoint.append(codeunit)) Utf8::encodeCodepoint(codepoint.value(), builder); continue; @@ -330,7 +375,8 @@ class JsonDeserializer { } // replace char c = EscapeSequence::unescapeChar(c); - if (c == '\0') return DeserializationError::InvalidInput; + if (c == '\0') + return DeserializationError::InvalidInput; move(); } @@ -338,7 +384,8 @@ class JsonDeserializer { } result = builder.complete(); - if (!result) return DeserializationError::NoMemory; + if (!result) + return DeserializationError::NoMemory; return DeserializationError::Ok; } @@ -346,7 +393,8 @@ class JsonDeserializer { StringBuilder builder = _stringStorage.startString(); char c = current(); - if (c == '\0') return DeserializationError::IncompleteInput; + if (c == '\0') + return DeserializationError::IncompleteInput; if (canBeInNonQuotedString(c)) { // no quotes do { @@ -359,7 +407,8 @@ class JsonDeserializer { } result = builder.complete(); - if (!result) return DeserializationError::NoMemory; + if (!result) + return DeserializationError::NoMemory; return DeserializationError::Ok; } @@ -370,10 +419,13 @@ class JsonDeserializer { for (;;) { char c = current(); move(); - if (c == stopChar) break; - if (c == '\0') return DeserializationError::IncompleteInput; + if (c == stopChar) + break; + if (c == '\0') + return DeserializationError::IncompleteInput; if (c == '\\') { - if (current() != '\0') move(); + if (current() != '\0') + move(); } } @@ -441,9 +493,11 @@ class JsonDeserializer { result = 0; for (uint8_t i = 0; i < 4; ++i) { char digit = current(); - if (!digit) return DeserializationError::IncompleteInput; + if (!digit) + return DeserializationError::IncompleteInput; uint8_t value = decodeHex(digit); - if (value > 0x0F) return DeserializationError::InvalidInput; + if (value > 0x0F) + return DeserializationError::InvalidInput; result = uint16_t((result << 4) | value); move(); } @@ -464,7 +518,8 @@ class JsonDeserializer { } static inline uint8_t decodeHex(char c) { - if (c < 'A') return uint8_t(c - '0'); + if (c < 'A') + return uint8_t(c - '0'); c = char(c & ~0x20); // uppercase return uint8_t(c - 'A' + 10); } @@ -495,7 +550,8 @@ class JsonDeserializer { bool wasStar = false; for (;;) { char c = current(); - if (c == '\0') return DeserializationError::IncompleteInput; + if (c == '\0') + return DeserializationError::IncompleteInput; if (c == '/' && wasStar) { move(); break; @@ -512,8 +568,10 @@ class JsonDeserializer { for (;;) { move(); char c = current(); - if (c == '\0') return DeserializationError::IncompleteInput; - if (c == '\n') break; + if (c == '\0') + return DeserializationError::IncompleteInput; + if (c == '\n') + break; } break; diff --git a/src/ArduinoJson/Json/JsonSerializer.hpp b/src/ArduinoJson/Json/JsonSerializer.hpp index 94c50f9a..df0cac68 100644 --- a/src/ArduinoJson/Json/JsonSerializer.hpp +++ b/src/ArduinoJson/Json/JsonSerializer.hpp @@ -25,7 +25,8 @@ class JsonSerializer { slot->data()->accept(*this); slot = slot->next(); - if (slot == 0) break; + if (slot == 0) + break; write(','); } @@ -44,7 +45,8 @@ class JsonSerializer { slot->data()->accept(*this); slot = slot->next(); - if (slot == 0) break; + if (slot == 0) + break; write(','); } diff --git a/src/ArduinoJson/Json/Latch.hpp b/src/ArduinoJson/Json/Latch.hpp index 0fe5f5ec..1e46c913 100644 --- a/src/ArduinoJson/Json/Latch.hpp +++ b/src/ArduinoJson/Json/Latch.hpp @@ -37,7 +37,8 @@ class Latch { ARDUINOJSON_ASSERT(!_ended); int c = _reader.read(); #ifdef ARDUINOJSON_DEBUG - if (c <= 0) _ended = true; + if (c <= 0) + _ended = true; #endif _current = static_cast(c > 0 ? c : 0); _loaded = true; diff --git a/src/ArduinoJson/Json/PrettyJsonSerializer.hpp b/src/ArduinoJson/Json/PrettyJsonSerializer.hpp index 24db7cad..96315d81 100644 --- a/src/ArduinoJson/Json/PrettyJsonSerializer.hpp +++ b/src/ArduinoJson/Json/PrettyJsonSerializer.hpp @@ -20,7 +20,8 @@ class PrettyJsonSerializer : public JsonSerializer { void visitArray(const CollectionData &array) { VariantSlot *slot = array.head(); - if (!slot) return base::write("[]"); + if (!slot) + return base::write("[]"); base::write("[\r\n"); _nesting++; @@ -38,7 +39,8 @@ class PrettyJsonSerializer : public JsonSerializer { void visitObject(const CollectionData &object) { VariantSlot *slot = object.head(); - if (!slot) return base::write("{}"); + if (!slot) + return base::write("{}"); base::write("{\r\n"); _nesting++; diff --git a/src/ArduinoJson/Json/TextFormatter.hpp b/src/ArduinoJson/Json/TextFormatter.hpp index a7225a59..a1ef2899 100644 --- a/src/ArduinoJson/Json/TextFormatter.hpp +++ b/src/ArduinoJson/Json/TextFormatter.hpp @@ -53,7 +53,8 @@ class TextFormatter { template void writeFloat(T value) { - if (isnan(value)) return writeRaw(ARDUINOJSON_ENABLE_NAN ? "NaN" : "null"); + if (isnan(value)) + return writeRaw(ARDUINOJSON_ENABLE_NAN ? "NaN" : "null"); #if ARDUINOJSON_ENABLE_INFINITY if (value < 0.0) { @@ -61,9 +62,11 @@ class TextFormatter { value = -value; } - if (isinf(value)) return writeRaw("Infinity"); + if (isinf(value)) + return writeRaw("Infinity"); #else - if (isinf(value)) return writeRaw("null"); + if (isinf(value)) + return writeRaw("null"); if (value < 0.0) { writeRaw('-'); @@ -74,7 +77,8 @@ class TextFormatter { FloatParts parts(value); writePositiveInteger(parts.integral); - if (parts.decimalPlaces) writeDecimals(parts.decimal, parts.decimalPlaces); + if (parts.decimalPlaces) + writeDecimals(parts.decimal, parts.decimalPlaces); if (parts.exponent < 0) { writeRaw("e-"); diff --git a/src/ArduinoJson/Memory/MemoryPool.hpp b/src/ArduinoJson/Memory/MemoryPool.hpp index 465b9a00..7d3dbac5 100644 --- a/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/src/ArduinoJson/Memory/MemoryPool.hpp @@ -52,7 +52,8 @@ class MemoryPool { } char* allocFrozenString(size_t n) { - if (!canAlloc(n)) return 0; + if (!canAlloc(n)) + return 0; char* s = _left; _left += n; checkInvariants(); @@ -97,7 +98,8 @@ class MemoryPool { } void* allocRight(size_t bytes) { - if (!canAlloc(bytes)) return 0; + if (!canAlloc(bytes)) + return 0; _right -= bytes; return _right; } @@ -120,7 +122,8 @@ class MemoryPool { // This funcion is called before a realloc. ptrdiff_t squash() { char* new_right = addPadding(_left); - if (new_right >= _right) return 0; + if (new_right >= _right) + return 0; size_t right_size = static_cast(_end - _right); memmove(new_right, _right, right_size); diff --git a/src/ArduinoJson/Memory/StringBuilder.hpp b/src/ArduinoJson/Memory/StringBuilder.hpp index 45e91b0b..28ffa268 100644 --- a/src/ArduinoJson/Memory/StringBuilder.hpp +++ b/src/ArduinoJson/Memory/StringBuilder.hpp @@ -23,7 +23,8 @@ class StringBuilder { } void append(char c) { - if (!_slot.value) return; + if (!_slot.value) + return; if (_size >= _slot.size) { _slot.value = 0; diff --git a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp index aba92920..18e8eb27 100644 --- a/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp +++ b/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp @@ -31,7 +31,8 @@ class MsgPackDeserializer { DeserializationError parse(VariantData &variant, NestingLimit nestingLimit) { uint8_t code; - if (!readByte(code)) return DeserializationError::IncompleteInput; + if (!readByte(code)) + return DeserializationError::IncompleteInput; if ((code & 0x80) == 0) { variant.setUnsignedInteger(code); @@ -139,7 +140,8 @@ class MsgPackDeserializer { bool readByte(uint8_t &value) { int c = _reader.read(); - if (c < 0) return false; + if (c < 0) + return false; value = static_cast(c); return true; } @@ -163,7 +165,8 @@ class MsgPackDeserializer { template bool readInteger(T &value) { - if (!readBytes(value)) return false; + if (!readBytes(value)) + return false; fixEndianess(value); return true; } @@ -171,7 +174,8 @@ class MsgPackDeserializer { template DeserializationError readInteger(VariantData &variant) { T value; - if (!readInteger(value)) return DeserializationError::IncompleteInput; + if (!readInteger(value)) + return DeserializationError::IncompleteInput; variant.setInteger(value); return DeserializationError::Ok; } @@ -180,7 +184,8 @@ class MsgPackDeserializer { typename enable_if::type readFloat( VariantData &variant) { T value; - if (!readBytes(value)) return DeserializationError::IncompleteInput; + if (!readBytes(value)) + return DeserializationError::IncompleteInput; fixEndianess(value); variant.setFloat(value); return DeserializationError::Ok; @@ -190,7 +195,8 @@ class MsgPackDeserializer { typename enable_if::type readDouble( VariantData &variant) { T value; - if (!readBytes(value)) return DeserializationError::IncompleteInput; + if (!readBytes(value)) + return DeserializationError::IncompleteInput; fixEndianess(value); variant.setFloat(value); return DeserializationError::Ok; @@ -202,7 +208,8 @@ class MsgPackDeserializer { uint8_t i[8]; // input is 8 bytes T value; // output is 4 bytes uint8_t *o = reinterpret_cast(&value); - if (!readBytes(i, 8)) return DeserializationError::IncompleteInput; + if (!readBytes(i, 8)) + return DeserializationError::IncompleteInput; doubleToFloat(i, o); fixEndianess(value); variant.setFloat(value); @@ -212,21 +219,24 @@ class MsgPackDeserializer { template DeserializationError readString(VariantData &variant) { T size; - if (!readInteger(size)) return DeserializationError::IncompleteInput; + if (!readInteger(size)) + return DeserializationError::IncompleteInput; return readString(variant, size); } template DeserializationError readString(const char *&str) { T size; - if (!readInteger(size)) return DeserializationError::IncompleteInput; + if (!readInteger(size)) + return DeserializationError::IncompleteInput; return readString(str, size); } DeserializationError readString(VariantData &variant, size_t n) { const char *s; DeserializationError err = readString(s, n); - if (!err) variant.setOwnedString(make_not_null(s)); + if (!err) + variant.setOwnedString(make_not_null(s)); return err; } @@ -234,11 +244,13 @@ class MsgPackDeserializer { StringBuilder builder = _stringStorage.startString(); for (; n; --n) { uint8_t c; - if (!readBytes(c)) return DeserializationError::IncompleteInput; + if (!readBytes(c)) + return DeserializationError::IncompleteInput; builder.append(static_cast(c)); } result = builder.complete(); - if (!result) return DeserializationError::NoMemory; + if (!result) + return DeserializationError::NoMemory; return DeserializationError::Ok; } @@ -246,20 +258,24 @@ class MsgPackDeserializer { DeserializationError readArray(CollectionData &array, NestingLimit nestingLimit) { TSize size; - if (!readInteger(size)) return DeserializationError::IncompleteInput; + if (!readInteger(size)) + return DeserializationError::IncompleteInput; return readArray(array, size, nestingLimit); } DeserializationError readArray(CollectionData &array, size_t n, NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; for (; n; --n) { VariantData *value = array.add(_pool); - if (!value) return DeserializationError::NoMemory; + if (!value) + return DeserializationError::NoMemory; DeserializationError err = parse(*value, nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } return DeserializationError::Ok; @@ -269,25 +285,30 @@ class MsgPackDeserializer { DeserializationError readObject(CollectionData &object, NestingLimit nestingLimit) { TSize size; - if (!readInteger(size)) return DeserializationError::IncompleteInput; + if (!readInteger(size)) + return DeserializationError::IncompleteInput; return readObject(object, size, nestingLimit); } DeserializationError readObject(CollectionData &object, size_t n, NestingLimit nestingLimit) { - if (nestingLimit.reached()) return DeserializationError::TooDeep; + if (nestingLimit.reached()) + return DeserializationError::TooDeep; for (; n; --n) { VariantSlot *slot = object.addSlot(_pool); - if (!slot) return DeserializationError::NoMemory; + if (!slot) + return DeserializationError::NoMemory; const char *key; DeserializationError err = parseKey(key); - if (err) return err; + if (err) + return err; slot->setOwnedKey(make_not_null(key)); err = parse(*slot->data(), nestingLimit.decrement()); - if (err) return err; + if (err) + return err; } return DeserializationError::Ok; @@ -295,9 +316,11 @@ class MsgPackDeserializer { DeserializationError parseKey(const char *&key) { uint8_t code; - if (!readByte(code)) return DeserializationError::IncompleteInput; + if (!readByte(code)) + return DeserializationError::IncompleteInput; - if ((code & 0xe0) == 0xa0) return readString(key, code & 0x1f); + if ((code & 0xe0) == 0xa0) + return readString(key, code & 0x1f); switch (code) { case 0xd9: diff --git a/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp b/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp index 1089add6..d239f501 100644 --- a/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp +++ b/src/ArduinoJson/MsgPack/MsgPackSerializer.hpp @@ -70,7 +70,8 @@ class MsgPackSerializer { } void visitString(const char* value) { - if (!value) return writeByte(0xC0); // nil + if (!value) + return writeByte(0xC0); // nil size_t n = strlen(value); diff --git a/src/ArduinoJson/Numbers/FloatTraits.hpp b/src/ArduinoJson/Numbers/FloatTraits.hpp index 4d9d1de5..6f4df596 100644 --- a/src/ArduinoJson/Numbers/FloatTraits.hpp +++ b/src/ArduinoJson/Numbers/FloatTraits.hpp @@ -30,13 +30,15 @@ struct FloatTraits { static T make_float(T m, TExponent e) { if (e > 0) { for (uint8_t index = 0; e != 0; index++) { - if (e & 1) m *= positiveBinaryPowerOfTen(index); + if (e & 1) + m *= positiveBinaryPowerOfTen(index); e >>= 1; } } else { e = TExponent(-e); for (uint8_t index = 0; e != 0; index++) { - if (e & 1) m *= negativeBinaryPowerOfTen(index); + if (e & 1) + m *= negativeBinaryPowerOfTen(index); e >>= 1; } } @@ -126,13 +128,15 @@ struct FloatTraits { static T make_float(T m, TExponent e) { if (e > 0) { for (uint8_t index = 0; e != 0; index++) { - if (e & 1) m *= positiveBinaryPowerOfTen(index); + if (e & 1) + m *= positiveBinaryPowerOfTen(index); e >>= 1; } } else { e = -e; for (uint8_t index = 0; e != 0; index++) { - if (e & 1) m *= negativeBinaryPowerOfTen(index); + if (e & 1) + m *= negativeBinaryPowerOfTen(index); e >>= 1; } } diff --git a/src/ArduinoJson/Numbers/parseNumber.hpp b/src/ArduinoJson/Numbers/parseNumber.hpp index 418f656a..ad493a3c 100644 --- a/src/ArduinoJson/Numbers/parseNumber.hpp +++ b/src/ArduinoJson/Numbers/parseNumber.hpp @@ -73,7 +73,8 @@ inline ParsedNumber parseNumber(const char *s) { } #if ARDUINOJSON_ENABLE_NAN - if (*s == 'n' || *s == 'N') return traits::nan(); + if (*s == 'n' || *s == 'N') + return traits::nan(); #endif #if ARDUINOJSON_ENABLE_INFINITY @@ -81,7 +82,8 @@ inline ParsedNumber parseNumber(const char *s) { return is_negative ? -traits::inf() : traits::inf(); #endif - if (!isdigit(*s) && *s != '.') return return_type(); + if (!isdigit(*s) && *s != '.') + return return_type(); mantissa_t mantissa = 0; exponent_t exponent_offset = 0; @@ -89,14 +91,17 @@ inline ParsedNumber parseNumber(const char *s) { while (isdigit(*s)) { uint8_t digit = uint8_t(*s - '0'); - if (mantissa > maxUint / 10) break; + if (mantissa > maxUint / 10) + break; mantissa *= 10; - if (mantissa > maxUint - digit) break; + if (mantissa > maxUint - digit) + break; mantissa += digit; s++; } - if (*s == '\0') return return_type(TUInt(mantissa), is_negative); + if (*s == '\0') + return return_type(TUInt(mantissa), is_negative); // avoid mantissa overflow while (mantissa > traits::mantissa_max) { @@ -142,12 +147,14 @@ inline ParsedNumber parseNumber(const char *s) { } s++; } - if (negative_exponent) exponent = -exponent; + if (negative_exponent) + exponent = -exponent; } exponent += exponent_offset; // we should be at the end of the string, otherwise it's an error - if (*s != '\0') return return_type(); + if (*s != '\0') + return return_type(); TFloat result = traits::make_float(static_cast(mantissa), exponent); diff --git a/src/ArduinoJson/Object/ObjectFunctions.hpp b/src/ArduinoJson/Object/ObjectFunctions.hpp index 66d771cd..fd761a85 100644 --- a/src/ArduinoJson/Object/ObjectFunctions.hpp +++ b/src/ArduinoJson/Object/ObjectFunctions.hpp @@ -17,34 +17,41 @@ void objectAccept(const CollectionData *obj, Visitor &visitor) { } inline bool objectEquals(const CollectionData *lhs, const CollectionData *rhs) { - if (lhs == rhs) return true; - if (!lhs || !rhs) return false; + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; return lhs->equalsObject(*rhs); } template inline VariantData *objectGet(const CollectionData *obj, TAdaptedString key) { - if (!obj) return 0; + if (!obj) + return 0; return obj->get(key); } template void objectRemove(CollectionData *obj, TAdaptedString key) { - if (!obj) return; + if (!obj) + return; obj->remove(key); } template inline VariantData *objectGetOrCreate(CollectionData *obj, TAdaptedString key, MemoryPool *pool) { - if (!obj) return 0; + if (!obj) + return 0; // ignore null key - if (key.isNull()) return 0; + if (key.isNull()) + return 0; // search a matching key VariantData *var = obj->get(key); - if (var) return var; + if (var) + return var; return obj->add(key, pool); } diff --git a/src/ArduinoJson/Object/ObjectRef.hpp b/src/ArduinoJson/Object/ObjectRef.hpp index 47afb15e..5a826db3 100644 --- a/src/ArduinoJson/Object/ObjectRef.hpp +++ b/src/ArduinoJson/Object/ObjectRef.hpp @@ -64,7 +64,8 @@ class ObjectConstRef : public ObjectRefBase, ObjectConstRef(const CollectionData* data) : base_type(data) {} FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_data->head()); } @@ -154,7 +155,8 @@ class ObjectRef : public ObjectRefBase, } FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_pool, _data->head()); } @@ -163,12 +165,14 @@ class ObjectRef : public ObjectRefBase, } void clear() const { - if (!_data) return; + if (!_data) + return; _data->clear(); } FORCE_INLINE bool set(ObjectConstRef src) { - if (!_data || !src._data) return false; + if (!_data || !src._data) + return false; return _data->copyFrom(*src._data, _pool); } @@ -207,7 +211,8 @@ class ObjectRef : public ObjectRefBase, } FORCE_INLINE void remove(iterator it) const { - if (!_data) return; + if (!_data) + return; _data->remove(it.internal()); } diff --git a/src/ArduinoJson/Polyfills/pgmspace.hpp b/src/ArduinoJson/Polyfills/pgmspace.hpp index b20f3636..85997188 100644 --- a/src/ArduinoJson/Polyfills/pgmspace.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace.hpp @@ -30,9 +30,12 @@ inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) { while (n-- > 0) { char c1 = *s1++; char c2 = static_cast(pgm_read_byte(s2++)); - if (c1 < c2) return -1; - if (c1 > c2) return 1; - if (c1 == 0 /* and c2 as well */) return 0; + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + if (c1 == 0 /* and c2 as well */) + return 0; } return 0; } @@ -45,9 +48,12 @@ inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) { for (;;) { char c1 = *s1++; char c2 = static_cast(pgm_read_byte(s2++)); - if (c1 < c2) return -1; - if (c1 > c2) return 1; - if (c1 == 0 /* and c2 as well */) return 0; + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + if (c1 == 0 /* and c2 as well */) + return 0; } } #endif diff --git a/src/ArduinoJson/Polyfills/safe_strcmp.hpp b/src/ArduinoJson/Polyfills/safe_strcmp.hpp index db2eca2f..2c5f7d89 100644 --- a/src/ArduinoJson/Polyfills/safe_strcmp.hpp +++ b/src/ArduinoJson/Polyfills/safe_strcmp.hpp @@ -9,16 +9,22 @@ namespace ARDUINOJSON_NAMESPACE { inline int8_t safe_strcmp(const char* a, const char* b) { - if (a == b) return 0; - if (!a) return -1; - if (!b) return 1; + if (a == b) + return 0; + if (!a) + return -1; + if (!b) + return 1; return static_cast(strcmp(a, b)); } inline int8_t safe_strncmp(const char* a, const char* b, size_t n) { - if (a == b) return 0; - if (!a) return -1; - if (!b) return 1; + if (a == b) + return 0; + if (!a) + return -1; + if (!b) + return 1; return static_cast(strncmp(a, b, n)); } } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp b/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp index 121de1f0..1fac2602 100644 --- a/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp +++ b/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp @@ -24,7 +24,8 @@ class Writer< ::String, void> { size_t write(uint8_t c) { ARDUINOJSON_ASSERT(_size < bufferCapacity); _buffer[_size++] = static_cast(c); - if (_size + 1 >= bufferCapacity) flush(); + if (_size + 1 >= bufferCapacity) + flush(); return 1; } diff --git a/src/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp b/src/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp index 1abb8eee..3440be65 100644 --- a/src/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp +++ b/src/ArduinoJson/Serialization/Writers/StaticStringWriter.hpp @@ -16,7 +16,8 @@ class StaticStringWriter { } size_t write(uint8_t c) { - if (p >= end) return 0; + if (p >= end) + return 0; *p++ = static_cast(c); *p = '\0'; return 1; diff --git a/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp b/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp index 27a680c1..5850a3b0 100644 --- a/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp +++ b/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp @@ -15,10 +15,12 @@ class ArduinoStringAdapter { ArduinoStringAdapter(const ::String& str) : _str(&str) {} char* save(MemoryPool* pool) const { - if (isNull()) return NULL; + if (isNull()) + return NULL; size_t n = _str->length() + 1; char* dup = pool->allocFrozenString(n); - if (dup) memcpy(dup, _str->c_str(), n); + if (dup) + memcpy(dup, _str->c_str(), n); return dup; } diff --git a/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp b/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp index 4706107a..a7176b08 100644 --- a/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp @@ -33,7 +33,8 @@ class ConstRamStringAdapter { } size_t size() const { - if (!_str) return 0; + if (!_str) + return 0; return strlen(_str); } diff --git a/src/ArduinoJson/Strings/FlashStringAdapter.hpp b/src/ArduinoJson/Strings/FlashStringAdapter.hpp index 0ca38ab3..74bc3950 100644 --- a/src/ArduinoJson/Strings/FlashStringAdapter.hpp +++ b/src/ArduinoJson/Strings/FlashStringAdapter.hpp @@ -13,9 +13,12 @@ class FlashStringAdapter { FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {} int8_t compare(const char* other) const { - if (!other && !_str) return 0; - if (!_str) return -1; - if (!other) return 1; + if (!other && !_str) + return 0; + if (!_str) + return -1; + if (!other) + return 1; return int8_t(-strcmp_P(other, reinterpret_cast(_str))); } @@ -28,10 +31,12 @@ class FlashStringAdapter { } char* save(MemoryPool* pool) const { - if (!_str) return NULL; + if (!_str) + return NULL; size_t n = size() + 1; // copy the terminator char* dup = pool->allocFrozenString(n); - if (dup) memcpy_P(dup, reinterpret_cast(_str), n); + if (dup) + memcpy_P(dup, reinterpret_cast(_str), n); return dup; } @@ -40,7 +45,8 @@ class FlashStringAdapter { } size_t size() const { - if (!_str) return 0; + if (!_str) + return 0; return strlen_P(reinterpret_cast(_str)); } diff --git a/src/ArduinoJson/Strings/RamStringAdapter.hpp b/src/ArduinoJson/Strings/RamStringAdapter.hpp index 90cdde1a..6909bf98 100644 --- a/src/ArduinoJson/Strings/RamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/RamStringAdapter.hpp @@ -13,10 +13,12 @@ class RamStringAdapter : public ConstRamStringAdapter { RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {} char* save(MemoryPool* pool) const { - if (!_str) return NULL; + if (!_str) + return NULL; size_t n = size() + 1; char* dup = pool->allocFrozenString(n); - if (dup) memcpy(dup, _str, n); + if (dup) + memcpy(dup, _str, n); return dup; } diff --git a/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp b/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp index 9e5a636c..48fe2855 100644 --- a/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp +++ b/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp @@ -14,9 +14,12 @@ class SizedFlashStringAdapter { : _str(str), _size(sz) {} int8_t compare(const char* other) const { - if (!other && !_str) return 0; - if (!_str) return -1; - if (!other) return 1; + if (!other && !_str) + return 0; + if (!_str) + return -1; + if (!other) + return 1; return int8_t( -strncmp_P(other, reinterpret_cast(_str), _size)); } @@ -30,9 +33,11 @@ class SizedFlashStringAdapter { } char* save(MemoryPool* pool) const { - if (!_str) return NULL; + if (!_str) + return NULL; char* dup = pool->allocFrozenString(_size); - if (dup) memcpy_P(dup, reinterpret_cast(_str), _size); + if (dup) + memcpy_P(dup, reinterpret_cast(_str), _size); return dup; } diff --git a/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp b/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp index e2e3e3e9..04c5630b 100644 --- a/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp @@ -27,9 +27,11 @@ class SizedRamStringAdapter { } char* save(MemoryPool* pool) const { - if (!_str) return NULL; + if (!_str) + return NULL; char* dup = pool->allocFrozenString(_size); - if (dup) memcpy(dup, _str, _size); + if (dup) + memcpy(dup, _str, _size); return dup; } diff --git a/src/ArduinoJson/Strings/StlStringAdapter.hpp b/src/ArduinoJson/Strings/StlStringAdapter.hpp index 45b434ac..617e8231 100644 --- a/src/ArduinoJson/Strings/StlStringAdapter.hpp +++ b/src/ArduinoJson/Strings/StlStringAdapter.hpp @@ -18,7 +18,8 @@ class StlStringAdapter { char* save(MemoryPool* pool) const { size_t n = _str->length() + 1; char* dup = pool->allocFrozenString(n); - if (dup) memcpy(dup, _str->c_str(), n); + if (dup) + memcpy(dup, _str->c_str(), n); return dup; } @@ -27,12 +28,14 @@ class StlStringAdapter { } int8_t compare(const char* other) const { - if (!other) return 1; + if (!other) + return 1; return static_cast(_str->compare(other)); } bool equals(const char* expected) const { - if (!expected) return false; + if (!expected) + return false; return *_str == expected; } diff --git a/src/ArduinoJson/Strings/String.hpp b/src/ArduinoJson/Strings/String.hpp index e6940f65..1cc42068 100644 --- a/src/ArduinoJson/Strings/String.hpp +++ b/src/ArduinoJson/Strings/String.hpp @@ -27,9 +27,12 @@ class String { } friend bool operator==(String lhs, String rhs) { - if (lhs._data == rhs._data) return true; - if (!lhs._data) return false; - if (!rhs._data) return false; + if (lhs._data == rhs._data) + return true; + if (!lhs._data) + return false; + if (!rhs._data) + return false; return strcmp(lhs._data, rhs._data) == 0; } diff --git a/src/ArduinoJson/Variant/SlotFunctions.hpp b/src/ArduinoJson/Variant/SlotFunctions.hpp index aafc9fff..fb16177b 100644 --- a/src/ArduinoJson/Variant/SlotFunctions.hpp +++ b/src/ArduinoJson/Variant/SlotFunctions.hpp @@ -11,12 +11,14 @@ namespace ARDUINOJSON_NAMESPACE { template inline bool slotSetKey(VariantSlot* var, TAdaptedString key, MemoryPool* pool) { - if (!var) return false; + if (!var) + return false; if (key.isStatic()) { var->setLinkedKey(make_not_null(key.data())); } else { const char* dup = key.save(pool); - if (!dup) return false; + if (!dup) + return false; var->setOwnedKey(make_not_null(dup)); } return true; diff --git a/src/ArduinoJson/Variant/VariantAsImpl.hpp b/src/ArduinoJson/Variant/VariantAsImpl.hpp index c3b69a96..a24d837d 100644 --- a/src/ArduinoJson/Variant/VariantAsImpl.hpp +++ b/src/ArduinoJson/Variant/VariantAsImpl.hpp @@ -32,7 +32,8 @@ template inline typename enable_if::value, T>::type variantAs( const VariantData* _data) { const char* cstr = _data != 0 ? _data->asString() : 0; - if (cstr) return T(cstr); + if (cstr) + return T(cstr); T s; serializeJson(VariantConstRef(_data), s); return s; diff --git a/src/ArduinoJson/Variant/VariantData.hpp b/src/ArduinoJson/Variant/VariantData.hpp index 2e022477..bb05ce8b 100644 --- a/src/ArduinoJson/Variant/VariantData.hpp +++ b/src/ArduinoJson/Variant/VariantData.hpp @@ -185,12 +185,14 @@ class VariantData { } void remove(size_t index) { - if (isArray()) _content.asCollection.remove(index); + if (isArray()) + _content.asCollection.remove(index); } template void remove(TAdaptedString key) { - if (isObject()) _content.asCollection.remove(key); + if (isObject()) + _content.asCollection.remove(key); } void setBoolean(bool value) { @@ -329,8 +331,10 @@ class VariantData { } VariantData *addElement(MemoryPool *pool) { - if (isNull()) toArray(); - if (!isArray()) return 0; + if (isNull()) + toArray(); + if (!isArray()) + return 0; return _content.asCollection.add(pool); } @@ -345,15 +349,19 @@ class VariantData { template VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool) { - if (isNull()) toObject(); - if (!isObject()) return 0; + if (isNull()) + toObject(); + if (!isObject()) + return 0; VariantData *var = _content.asCollection.get(key); - if (var) return var; + if (var) + return var; return _content.asCollection.add(key, pool); } void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) { - if (_flags & VALUE_IS_OWNED) _content.asString += stringDistance; + if (_flags & VALUE_IS_OWNED) + _content.asString += stringDistance; if (_flags & COLLECTION_MASK) _content.asCollection.movePointers(stringDistance, variantDistance); } diff --git a/src/ArduinoJson/Variant/VariantFunctions.hpp b/src/ArduinoJson/Variant/VariantFunctions.hpp index 6c77635d..6a55797c 100644 --- a/src/ArduinoJson/Variant/VariantFunctions.hpp +++ b/src/ArduinoJson/Variant/VariantFunctions.hpp @@ -30,7 +30,8 @@ inline CollectionData *variantAsObject(VariantData *var) { inline bool variantCopyFrom(VariantData *dst, const VariantData *src, MemoryPool *pool) { - if (!dst) return false; + if (!dst) + return false; if (!src) { dst->setNull(); return true; @@ -39,8 +40,10 @@ inline bool variantCopyFrom(VariantData *dst, const VariantData *src, } inline bool variantEquals(const VariantData *a, const VariantData *b) { - if (a == b) return true; - if (!a || !b) return false; + if (a == b) + return true; + if (!a || !b) + return false; return a->equals(*b); } @@ -74,20 +77,23 @@ inline bool variantIsNull(const VariantData *var) { } inline bool variantSetBoolean(VariantData *var, bool value) { - if (!var) return false; + if (!var) + return false; var->setBoolean(value); return true; } inline bool variantSetFloat(VariantData *var, Float value) { - if (!var) return false; + if (!var) + return false; var->setFloat(value); return true; } inline bool variantSetLinkedRaw(VariantData *var, SerializedValue value) { - if (!var) return false; + if (!var) + return false; var->setLinkedRaw(value); return true; } @@ -100,24 +106,28 @@ inline bool variantSetOwnedRaw(VariantData *var, SerializedValue value, template inline bool variantSetSignedInteger(VariantData *var, T value) { - if (!var) return false; + if (!var) + return false; var->setSignedInteger(value); return true; } inline bool variantSetLinkedString(VariantData *var, const char *value) { - if (!var) return false; + if (!var) + return false; var->setLinkedString(value); return true; } inline void variantSetNull(VariantData *var) { - if (!var) return; + if (!var) + return; var->setNull(); } inline bool variantSetOwnedString(VariantData *var, char *value) { - if (!var) return false; + if (!var) + return false; var->setOwnedString(value); return true; } @@ -128,7 +138,8 @@ inline bool variantSetOwnedString(VariantData *var, T value, MemoryPool *pool) { } inline bool variantSetUnsignedInteger(VariantData *var, UInt value) { - if (!var) return false; + if (!var) + return false; var->setUnsignedInteger(value); return true; } @@ -138,12 +149,14 @@ inline size_t variantSize(const VariantData *var) { } inline CollectionData *variantToArray(VariantData *var) { - if (!var) return 0; + if (!var) + return 0; return &var->toArray(); } inline CollectionData *variantToObject(VariantData *var) { - if (!var) return 0; + if (!var) + return 0; return &var->toObject(); } diff --git a/src/ArduinoJson/Variant/VariantRef.hpp b/src/ArduinoJson/Variant/VariantRef.hpp index 1bef610a..9c9d1e91 100644 --- a/src/ArduinoJson/Variant/VariantRef.hpp +++ b/src/ArduinoJson/Variant/VariantRef.hpp @@ -324,7 +324,8 @@ class VariantRef : public VariantRefBase, FORCE_INLINE VariantRef getOrAddMember(const TString &) const; FORCE_INLINE void remove(size_t index) const { - if (_data) _data->remove(index); + if (_data) + _data->remove(index); } // remove(char*) const // remove(const char*) const @@ -332,14 +333,16 @@ class VariantRef : public VariantRefBase, template FORCE_INLINE typename enable_if::value>::type remove( TChar *key) const { - if (_data) _data->remove(adaptString(key)); + if (_data) + _data->remove(adaptString(key)); } // remove(const std::string&) const // remove(const String&) const template FORCE_INLINE typename enable_if::value>::type remove( const TString &key) const { - if (_data) _data->remove(adaptString(key)); + if (_data) + _data->remove(adaptString(key)); } private: diff --git a/src/ArduinoJson/Variant/VariantSlot.hpp b/src/ArduinoJson/Variant/VariantSlot.hpp index 22c84227..4af94dfa 100644 --- a/src/ArduinoJson/Variant/VariantSlot.hpp +++ b/src/ArduinoJson/Variant/VariantSlot.hpp @@ -49,7 +49,8 @@ class VariantSlot { VariantSlot* next(size_t distance) { VariantSlot* slot = this; while (distance--) { - if (!slot->_next) return 0; + if (!slot->_next) + return 0; slot += slot->_next; } return slot; @@ -93,8 +94,10 @@ class VariantSlot { } void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) { - if (_flags & KEY_IS_OWNED) _key += stringDistance; - if (_flags & VALUE_IS_OWNED) _content.asString += stringDistance; + if (_flags & KEY_IS_OWNED) + _key += stringDistance; + if (_flags & VALUE_IS_OWNED) + _content.asString += stringDistance; if (_flags & COLLECTION_MASK) _content.asCollection.movePointers(stringDistance, variantDistance); }