Преглед изворни кода

Renamed `JsonArray::removeAt()` into `remove()`

Benoit Blanchon пре 8 година
родитељ
комит
f2ef338cb8

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@ HEAD
 
 * Added `JsonArray::remove(iterator)` (issue #479)
 * Added `JsonObject::remove(iterator)`
+* Renamed `JsonArray::removeAt(size_t)` into `remove(size_t)`
 
 v5.8.4
 ------

+ 2 - 0
include/ArduinoJson/Data/List.hpp

@@ -89,6 +89,8 @@ class List {
 
  protected:
   JsonBuffer *_buffer;
+
+ private:
   node_type *_firstNode;
 };
 }

+ 8 - 1
include/ArduinoJson/JsonArray.hpp

@@ -131,7 +131,7 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
   JsonObject &createNestedObject();
 
   // Removes element at specified index.
-  void removeAt(size_t index) {
+  void remove(size_t index) {
     remove(begin() += index);
   }
   using Internals::List<JsonVariant>::remove;
@@ -197,6 +197,13 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
     }
   }
 
+#if ARDUINOJSON_ENABLE_DEPRECATED
+  DEPRECATED("use remove() instead")
+  FORCE_INLINE void removeAt(size_t index) {
+    return remove(index);
+  }
+#endif
+
  private:
   template <typename TValueRef>
   bool set_impl(size_t index, TValueRef value) {

+ 1 - 1
test/JsonArray/CMakeLists.txt

@@ -14,7 +14,7 @@ add_executable(JsonArrayTests
 	iterator.cpp
 	prettyPrintTo.cpp
 	printTo.cpp
-	removeAt.cpp
+	remove.cpp
 	set.cpp
 	subscript.cpp
 )

+ 3 - 3
test/JsonArray/removeAt.cpp → test/JsonArray/remove.cpp

@@ -23,7 +23,7 @@ class JsonArray_Remove_Tests : public ::testing::Test {
 #define TEST_(name) TEST_F(JsonArray_Remove_Tests, name)
 
 TEST_(RemoveFirstByIndex) {
-  _array.removeAt(0);
+  _array.remove(0);
 
   EXPECT_EQ(2, _array.size());
   EXPECT_STREQ("two", _array[0]);
@@ -31,7 +31,7 @@ TEST_(RemoveFirstByIndex) {
 }
 
 TEST_(RemoveMiddleByIndex) {
-  _array.removeAt(1);
+  _array.remove(1);
 
   EXPECT_EQ(2, _array.size());
   EXPECT_STREQ("one", _array[0]);
@@ -39,7 +39,7 @@ TEST_(RemoveMiddleByIndex) {
 }
 
 TEST_(RemoveLastByIndex) {
-  _array.removeAt(2);
+  _array.remove(2);
 
   EXPECT_EQ(2, _array.size());
   EXPECT_STREQ("one", _array[0]);

+ 6 - 0
test/Misc/deprecated.cpp

@@ -34,3 +34,9 @@ TEST(Deprecated, asString) {
   JsonVariant variant = "hello";
   ASSERT_STREQ("hello", variant.asString());
 }
+
+TEST(Deprecated, removeAt) {
+  DynamicJsonBuffer jsonBuffer;
+  JsonArray& arr = jsonBuffer.createArray();
+  arr.removeAt(0);
+}