mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed compilation error when index is not an int (issue #381)
				
					
				
			This commit is contained in:
		| @@ -5,6 +5,7 @@ HEAD | ||||
| ---- | ||||
|  | ||||
| * Added support for PROGMEM (issue #76) | ||||
| * Fixed compilation error when index is not an `int` (issue #381) | ||||
|  | ||||
| v5.7.0 | ||||
| ------ | ||||
|   | ||||
| @@ -44,6 +44,7 @@ struct CharPtrFuncs { | ||||
|   } | ||||
|  | ||||
|   static const bool has_append = false; | ||||
|   static const bool has_equals = true; | ||||
|   static const bool should_duplicate = false; | ||||
| }; | ||||
|  | ||||
| @@ -56,6 +57,9 @@ struct StringFuncs<char*> : CharPtrFuncs {}; | ||||
| template <size_t N> | ||||
| struct StringFuncs<char[N]> : CharPtrFuncs {}; | ||||
|  | ||||
| template <size_t N> | ||||
| struct StringFuncs<const char[N]> : CharPtrFuncs {}; | ||||
|  | ||||
| template <typename TString> | ||||
| struct StdStringFuncs { | ||||
|   template <typename Buffer> | ||||
| @@ -76,6 +80,7 @@ struct StdStringFuncs { | ||||
|   } | ||||
|  | ||||
|   static const bool has_append = true; | ||||
|   static const bool has_equals = true; | ||||
|   static const bool should_duplicate = true; | ||||
| }; | ||||
|  | ||||
| @@ -108,6 +113,7 @@ struct StringFuncs<const __FlashStringHelper*> { | ||||
|   } | ||||
|  | ||||
|   static const bool has_append = false; | ||||
|   static const bool has_equals = true; | ||||
|   static const bool should_duplicate = true; | ||||
| }; | ||||
| #endif | ||||
|   | ||||
| @@ -84,13 +84,6 @@ template <typename TString> | ||||
| inline JsonObjectSubscript<TString> JsonObject::operator[](const TString& key) { | ||||
|   return JsonObjectSubscript<TString>(*this, key); | ||||
| } | ||||
|  | ||||
| template <typename TImplem> | ||||
| template <class TString> | ||||
| inline const JsonObjectSubscript<TString> JsonVariantBase<TImplem>::operator[]( | ||||
|     const TString& key) const { | ||||
|   return asObject()[key]; | ||||
| } | ||||
| }  // namespace ArduinoJson | ||||
|  | ||||
| #ifdef _MSC_VER | ||||
|   | ||||
| @@ -77,8 +77,12 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> { | ||||
|   // an object. | ||||
|   // Return JsonVariant::invalid() if the variant is not an object. | ||||
|   template <typename TString> | ||||
|   FORCE_INLINE const JsonObjectSubscript<TString> operator[]( | ||||
|       const TString &key) const; | ||||
|   FORCE_INLINE | ||||
|       typename TypeTraits::EnableIf<Internals::StringFuncs<TString>::has_equals, | ||||
|                                     const JsonObjectSubscript<TString> >::type | ||||
|       operator[](const TString &key) const { | ||||
|     return asObject()[key]; | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   const TImpl *impl() const { | ||||
|   | ||||
| @@ -5,8 +5,8 @@ | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
| // If you like this project, please add a star! | ||||
|  | ||||
| #include <gtest/gtest.h> | ||||
| #include <ArduinoJson.h> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| class JsonVariant_Subscript_Tests : public ::testing::Test { | ||||
|  protected: | ||||
| @@ -24,6 +24,9 @@ TEST_F(JsonVariant_Subscript_Tests, Array) { | ||||
|   EXPECT_EQ(2, _variant.size()); | ||||
|   EXPECT_STREQ("element at index 0", _variant[0].asString()); | ||||
|   EXPECT_STREQ("element at index 1", _variant[1].asString()); | ||||
|   EXPECT_STREQ( | ||||
|       "element at index 0", | ||||
|       _variant[static_cast<unsigned char>(0)].asString());  // issue #381 | ||||
|   EXPECT_FALSE(_variant[-1].success()); | ||||
|   EXPECT_FALSE(_variant[3].success()); | ||||
|   EXPECT_FALSE(_variant["0"].success()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user