Просмотр исходного кода

Added missing newline at end-of-file (issue #24)

Benoit Blanchon 11 лет назад
Родитель
Сommit
cc19266470
58 измененных файлов с 3699 добавлено и 3698 удалено
  1. 1 0
      FixEndOfFile.sh
  2. 15 15
      JsonGenerator.cpp
  3. 7 7
      JsonGenerator.h
  4. 41 41
      JsonGenerator/EscapedString.cpp
  5. 17 17
      JsonGenerator/EscapedString.h
  6. 45 45
      JsonGenerator/IndentedPrint.cpp
  7. 50 50
      JsonGenerator/IndentedPrint.h
  8. 28 28
      JsonGenerator/JsonArray.h
  9. 34 34
      JsonGenerator/JsonArrayBase.cpp
  10. 79 79
      JsonGenerator/JsonArrayBase.h
  11. 42 42
      JsonGenerator/JsonObject.h
  12. 89 89
      JsonGenerator/JsonObjectBase.cpp
  13. 62 62
      JsonGenerator/JsonObjectBase.h
  14. 93 93
      JsonGenerator/JsonPrettyPrint.cpp
  15. 49 49
      JsonGenerator/JsonPrettyPrint.h
  16. 32 32
      JsonGenerator/JsonPrintable.cpp
  17. 40 40
      JsonGenerator/JsonPrintable.h
  18. 29 29
      JsonGenerator/JsonValue.cpp
  19. 132 132
      JsonGenerator/JsonValue.h
  20. 49 49
      JsonGenerator/Print.cpp
  21. 26 26
      JsonGenerator/Print.h
  22. 20 20
      JsonGenerator/Printable.h
  23. 14 14
      JsonGenerator/StringBuilder.cpp
  24. 31 31
      JsonGenerator/StringBuilder.h
  25. 92 92
      JsonGeneratorTests/EscapedStringTests.cpp
  26. 73 73
      JsonGeneratorTests/Issue10.cpp
  27. 159 159
      JsonGeneratorTests/JsonArrayTests.cpp
  28. 70 70
      JsonGeneratorTests/JsonObject_Indexer_Tests.cpp
  29. 149 149
      JsonGeneratorTests/JsonObject_PrintTo_Tests.cpp
  30. 75 75
      JsonGeneratorTests/JsonValue_Cast_Tests.cpp
  31. 106 106
      JsonGeneratorTests/JsonValue_PrintTo_Tests.cpp
  32. 88 88
      JsonGeneratorTests/PrettyPrint_Array_Tests.cpp
  33. 86 86
      JsonGeneratorTests/PrettyPrint_Object_Tests.cpp
  34. 73 73
      JsonGeneratorTests/PrettyPrint_String_Tests.cpp
  35. 82 82
      JsonGeneratorTests/StringBuilderTests.cpp
  36. 13 13
      JsonParser.cpp
  37. 6 6
      JsonParser.h
  38. 10 10
      JsonParser/JsonArray.cpp
  39. 82 82
      JsonParser/JsonArray.h
  40. 42 42
      JsonParser/JsonArrayIterator.h
  41. 12 12
      JsonParser/JsonObject.cpp
  42. 98 98
      JsonParser/JsonObject.h
  43. 54 54
      JsonParser/JsonObjectIterator.h
  44. 34 34
      JsonParser/JsonPair.h
  45. 32 32
      JsonParser/JsonParser.h
  46. 17 17
      JsonParser/JsonParserBase.cpp
  47. 46 46
      JsonParser/JsonParserBase.h
  48. 68 68
      JsonParser/JsonToken.cpp
  49. 96 96
      JsonParser/JsonToken.h
  50. 107 107
      JsonParser/JsonValue.cpp
  51. 67 67
      JsonParser/JsonValue.h
  52. 241 241
      JsonParserTests/GbathreeBug.cpp
  53. 64 64
      JsonParserTests/JsonArrayIteratorTests.cpp
  54. 174 174
      JsonParserTests/JsonArrayTests.cpp
  55. 68 68
      JsonParserTests/JsonObjectIteratorTests.cpp
  56. 162 162
      JsonParserTests/JsonObjectTests.cpp
  57. 103 103
      JsonParserTests/JsonStringTests.cpp
  58. 25 25
      JsonParserTests/TestHashGenerator.cpp

+ 1 - 0
FixEndOfFile.sh

@@ -0,0 +1 @@
+find \( -iname '*.cpp' -o -iname '*.h' \) -exec sed -i -e '$a\' {} \;

+ 15 - 15
JsonGenerator.cpp

@@ -1,15 +1,15 @@
-/*
-* malloc-free JSON parser for Arduino
-* Benoit Blanchon 2014 - MIT License
-*/
-
-// This file is here to help the Arduino IDE find the .cpp files
-
-#include "JsonGenerator/EscapedString.cpp"
-#include "JsonGenerator/IndentedPrint.cpp"
-#include "JsonGenerator/JsonArrayBase.cpp"
-#include "JsonGenerator/JsonObjectBase.cpp"
-#include "JsonGenerator/JsonValue.cpp"
-#include "JsonGenerator/JsonPrettyPrint.cpp"
-#include "JsonGenerator/JsonPrintable.cpp"
-#include "JsonGenerator/StringBuilder.cpp"
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+// This file is here to help the Arduino IDE find the .cpp files
+
+#include "JsonGenerator/EscapedString.cpp"
+#include "JsonGenerator/IndentedPrint.cpp"
+#include "JsonGenerator/JsonArrayBase.cpp"
+#include "JsonGenerator/JsonObjectBase.cpp"
+#include "JsonGenerator/JsonValue.cpp"
+#include "JsonGenerator/JsonPrettyPrint.cpp"
+#include "JsonGenerator/JsonPrintable.cpp"
+#include "JsonGenerator/StringBuilder.cpp"

+ 7 - 7
JsonGenerator.h

@@ -1,7 +1,7 @@
-/*
-* malloc-free JSON parser for Arduino
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonGenerator/JsonArray.h"
-#include "JsonGenerator/JsonObject.h"
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#include "JsonGenerator/JsonArray.h"
+#include "JsonGenerator/JsonObject.h"

+ 41 - 41
JsonGenerator/EscapedString.cpp

@@ -2,44 +2,44 @@
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
  */
-
-#include "EscapedString.h"
-
-using namespace ArduinoJson::Internals;
-
-static inline char getSpecialChar(char c)
-{
-    // Optimized for code size on a 8-bit AVR
-
-    const char* p = "\"\"\\\\\bb\ff\nn\rr\tt\0";
-
-    while (p[0] && p[0] != c)
-    {
-        p += 2;
-    }
-
-    return p[1];
-}
-
-static inline size_t printCharTo(char c, Print& p)
-{
-    char specialChar = getSpecialChar(c);
-
-    return specialChar != 0
-        ? p.write('\\') + p.write(specialChar)
-        : p.write(c);
-}
-
-size_t EscapedString::printTo(const char* s, Print& p)
-{
-    if (!s) return p.print("null");
-    
-    size_t n = p.write('\"');
-
-    while (*s)
-    {
-        n += printCharTo(*s++, p);
-    }
-
-    return n + p.write('\"');
-}
+
+#include "EscapedString.h"
+
+using namespace ArduinoJson::Internals;
+
+static inline char getSpecialChar(char c)
+{
+    // Optimized for code size on a 8-bit AVR
+
+    const char* p = "\"\"\\\\\bb\ff\nn\rr\tt\0";
+
+    while (p[0] && p[0] != c)
+    {
+        p += 2;
+    }
+
+    return p[1];
+}
+
+static inline size_t printCharTo(char c, Print& p)
+{
+    char specialChar = getSpecialChar(c);
+
+    return specialChar != 0
+        ? p.write('\\') + p.write(specialChar)
+        : p.write(c);
+}
+
+size_t EscapedString::printTo(const char* s, Print& p)
+{
+    if (!s) return p.print("null");
+    
+    size_t n = p.write('\"');
+
+    while (*s)
+    {
+        n += printCharTo(*s++, p);
+    }
+
+    return n + p.write('\"');
+}

+ 17 - 17
JsonGenerator/EscapedString.h

@@ -1,20 +1,20 @@
 /*
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "Print.h"
-
-namespace ArduinoJson
-{
-    namespace Internals
-    {
-        class EscapedString
-        {
-        public:
-            static size_t printTo(const char*, Print&);
-        };
-    }
-}
+ */
+
+#pragma once
+
+#include "Print.h"
+
+namespace ArduinoJson
+{
+    namespace Internals
+    {
+        class EscapedString
+        {
+        public:
+            static size_t printTo(const char*, Print&);
+        };
+    }
+}

+ 45 - 45
JsonGenerator/IndentedPrint.cpp

@@ -1,45 +1,45 @@
-#include "IndentedPrint.h"
-
-using namespace ArduinoJson::Generator;
-
-void IndentedPrint::indent()
-{
-    if (level < MAX_LEVEL)
-        level++;
-}
-
-void IndentedPrint::unindent()
-{
-    if (level > 0)
-        level--;
-}
-
-void IndentedPrint::setTabSize(uint8_t n)
-{
-    if (n < MAX_TAB_SIZE)
-        tabSize = n;
-}
-
-size_t IndentedPrint::write(uint8_t c)
-{
-    size_t n = 0;
-
-    if (isNewLine)
-        n += writeTabs();
-
-    n += sink.write(c);
-
-    isNewLine = c == '\n';
-
-    return n;
-}
-
-inline size_t IndentedPrint::writeTabs()
-{
-    size_t n = 0;
-
-    for (int i = 0; i < level*tabSize; i++)
-        n += sink.write(' ');
-
-    return n;
-}
+#include "IndentedPrint.h"
+
+using namespace ArduinoJson::Generator;
+
+void IndentedPrint::indent()
+{
+    if (level < MAX_LEVEL)
+        level++;
+}
+
+void IndentedPrint::unindent()
+{
+    if (level > 0)
+        level--;
+}
+
+void IndentedPrint::setTabSize(uint8_t n)
+{
+    if (n < MAX_TAB_SIZE)
+        tabSize = n;
+}
+
+size_t IndentedPrint::write(uint8_t c)
+{
+    size_t n = 0;
+
+    if (isNewLine)
+        n += writeTabs();
+
+    n += sink.write(c);
+
+    isNewLine = c == '\n';
+
+    return n;
+}
+
+inline size_t IndentedPrint::writeTabs()
+{
+    size_t n = 0;
+
+    for (int i = 0; i < level*tabSize; i++)
+        n += sink.write(' ');
+
+    return n;
+}

+ 50 - 50
JsonGenerator/IndentedPrint.h

@@ -1,53 +1,53 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "Print.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        // Decorator on top of Print to allow indented output.
-        // This class is used by JsonPrintable::prettyPrintTo() but can also be used
-        // for your own purpose, like logging.
-        class IndentedPrint : public Print
-        {
-        public:
-
-            IndentedPrint(Print& p)
-                : sink(p)
-            {
-                level = 0;
-                tabSize = 2;
-                isNewLine = true;
-            }
-
-            virtual size_t write(uint8_t);
-
-            // Adds one level of indentation
-            void indent();
-
-            // Removes one level of indentation
-            void unindent();
-
-            // Set the number of space printed for each level of indentation
-            void setTabSize(uint8_t n);
-
-        private:
-            Print& sink;
-            uint8_t level : 4;
-            uint8_t tabSize : 3;
-            bool isNewLine : 1;
-            
-            size_t writeTabs();
-
-            static const int MAX_LEVEL = 15; // because it's only 4 bits
-            static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
-        };
-    }
-}
-
+*/
+
+#pragma once
+
+#include "Print.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        // Decorator on top of Print to allow indented output.
+        // This class is used by JsonPrintable::prettyPrintTo() but can also be used
+        // for your own purpose, like logging.
+        class IndentedPrint : public Print
+        {
+        public:
+
+            IndentedPrint(Print& p)
+                : sink(p)
+            {
+                level = 0;
+                tabSize = 2;
+                isNewLine = true;
+            }
+
+            virtual size_t write(uint8_t);
+
+            // Adds one level of indentation
+            void indent();
+
+            // Removes one level of indentation
+            void unindent();
+
+            // Set the number of space printed for each level of indentation
+            void setTabSize(uint8_t n);
+
+        private:
+            Print& sink;
+            uint8_t level : 4;
+            uint8_t tabSize : 3;
+            bool isNewLine : 1;
+            
+            size_t writeTabs();
+
+            static const int MAX_LEVEL = 15; // because it's only 4 bits
+            static const int MAX_TAB_SIZE = 7; // because it's only 3 bits
+        };
+    }
+}
+

+ 28 - 28
JsonGenerator/JsonArray.h

@@ -1,28 +1,28 @@
-/*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "JsonArrayBase.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        template<int N>
-        class JsonArray : public JsonArrayBase
-        {
-        public:
-            JsonArray()
-                : JsonArrayBase(items, N)
-            {
-
-            }         
-
-        private:
-            JsonValue items[N];
-        };
-    }
-}
+/*
+ * Arduino JSON library
+ * Benoit Blanchon 2014 - MIT License
+ */
+
+#pragma once
+
+#include "JsonArrayBase.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        template<int N>
+        class JsonArray : public JsonArrayBase
+        {
+        public:
+            JsonArray()
+                : JsonArrayBase(items, N)
+            {
+
+            }         
+
+        private:
+            JsonValue items[N];
+        };
+    }
+}

+ 34 - 34
JsonGenerator/JsonArrayBase.cpp

@@ -1,34 +1,34 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonArrayBase.h"
-
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-size_t JsonArrayBase::printTo(Print& p) const
-{
-    size_t n = 0;
-
-    n += p.write('[');
-
-    // NB: the code has been optimized for a small size on a 8-bit AVR
-
-    const JsonValue* current = items;
-    for (int i = count; i > 0; i--)
-    {       
-        n += current->printTo(p);
-        current++;
-
-        if (i > 1)
-        {
-            n += p.write(',');
-        }
-    }
-
-    n += p.write(']');
-
-    return n;
-}
+/*
+* Arduino JSON library
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#include "JsonArrayBase.h"
+
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+size_t JsonArrayBase::printTo(Print& p) const
+{
+    size_t n = 0;
+
+    n += p.write('[');
+
+    // NB: the code has been optimized for a small size on a 8-bit AVR
+
+    const JsonValue* current = items;
+    for (int i = count; i > 0; i--)
+    {       
+        n += current->printTo(p);
+        current++;
+
+        if (i > 1)
+        {
+            n += p.write(',');
+        }
+    }
+
+    n += p.write(']');
+
+    return n;
+}

+ 79 - 79
JsonGenerator/JsonArrayBase.h

@@ -1,79 +1,79 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "JsonPrintable.h"
-#include "JsonValue.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        class JsonArrayBase : public JsonPrintable
-        {
-        public:
-            JsonArrayBase(JsonValue* items, int capacity)
-                : items(items), capacity(capacity), count(0)
-            {
-
-            }
-
-            void add(const Printable& value)
-            {
-                addIfPossible<const Printable&>(value);
-            }
-
-            void add(bool value)
-            {
-                addIfPossible<bool>(value);
-            }
-
-            void add(int value)
-            {
-                addIfPossible<long>(value);
-            }
-
-            void add(long value)
-            {
-                addIfPossible<long>(value);
-            }
-
-            void add(double value)
-            {
-                addIfPossible<double>(value);
-            }
-
-            void add(const char* value)
-            {
-                addIfPossible<const char*>(value);
-            }
-
-            template<int DIGITS>
-            void add(double value)
-            {
-                if (count >= capacity) return;
-
-                JsonValue& v = items[count++];
-                v.set<DIGITS>(value);
-            }
-
-            virtual size_t printTo(Print& p) const;
-
-            using JsonPrintable::printTo;
-
-        private:
-            JsonValue* items;
-            int capacity, count;
-
-            template<typename T>
-            void addIfPossible(T value)
-            {
-                if (count < capacity)
-                    items[count++] = value;
-            }
-        };
-    }
-}
+/*
+* Arduino JSON library
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#pragma once
+
+#include "JsonPrintable.h"
+#include "JsonValue.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        class JsonArrayBase : public JsonPrintable
+        {
+        public:
+            JsonArrayBase(JsonValue* items, int capacity)
+                : items(items), capacity(capacity), count(0)
+            {
+
+            }
+
+            void add(const Printable& value)
+            {
+                addIfPossible<const Printable&>(value);
+            }
+
+            void add(bool value)
+            {
+                addIfPossible<bool>(value);
+            }
+
+            void add(int value)
+            {
+                addIfPossible<long>(value);
+            }
+
+            void add(long value)
+            {
+                addIfPossible<long>(value);
+            }
+
+            void add(double value)
+            {
+                addIfPossible<double>(value);
+            }
+
+            void add(const char* value)
+            {
+                addIfPossible<const char*>(value);
+            }
+
+            template<int DIGITS>
+            void add(double value)
+            {
+                if (count >= capacity) return;
+
+                JsonValue& v = items[count++];
+                v.set<DIGITS>(value);
+            }
+
+            virtual size_t printTo(Print& p) const;
+
+            using JsonPrintable::printTo;
+
+        private:
+            JsonValue* items;
+            int capacity, count;
+
+            template<typename T>
+            void addIfPossible(T value)
+            {
+                if (count < capacity)
+                    items[count++] = value;
+            }
+        };
+    }
+}

+ 42 - 42
JsonGenerator/JsonObject.h

@@ -1,44 +1,44 @@
-/*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "JsonObjectBase.h"
-
-#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING
-#ifdef __GNUC__
-#define DEPRECATED __attribute__((deprecated))
-#elif defined(_MSC_VER)
-#define DEPRECATED __declspec(deprecated)
-#endif
+/*
+ * Arduino JSON library
+ * Benoit Blanchon 2014 - MIT License
+ */
+
+#pragma once
+
+#include "JsonObjectBase.h"
+
+#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING
+#ifdef __GNUC__
+#define DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#define DEPRECATED __declspec(deprecated)
+#endif
 #else
 #define DEPRECATED
-#endif
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        template <int N>
-        class JsonObject : public JsonObjectBase
-        {
-        public:
-            JsonObject()
-                : JsonObjectBase(items, N)
-            {
-            }
-
-        private:
-            KeyValuePair items[N];
-        };
-
-        
-        // Obsolete: use JsonObject instead
-        template <int N>
-        class DEPRECATED JsonHashTable : public JsonObject<N>
-        {            
-        };
-    }
-}
+#endif
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        template <int N>
+        class JsonObject : public JsonObjectBase
+        {
+        public:
+            JsonObject()
+                : JsonObjectBase(items, N)
+            {
+            }
+
+        private:
+            KeyValuePair items[N];
+        };
+
+        
+        // Obsolete: use JsonObject instead
+        template <int N>
+        class DEPRECATED JsonHashTable : public JsonObject<N>
+        {            
+        };
+    }
+}

+ 89 - 89
JsonGenerator/JsonObjectBase.cpp

@@ -1,92 +1,92 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonObjectBase.h"
-#include <string.h> // for strcmp
-
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-JsonValue JsonObjectBase::nullValue;
-
-size_t JsonObjectBase::printTo(Print& p) const
-{
-    size_t n = 0;
-
-    n += p.write('{');
-
-    // NB: the code has been optimized for a small size on a 8-bit AVR
-
-    const KeyValuePair* current = items;
-    for (int i = count; i > 0; i--)
-    {       
-        n += EscapedString::printTo(current->key, p);
-        n += p.write(':');
-        n += current->value.printTo(p);
-
-        current++;
-
-        if (i > 1)
-        {
-            n += p.write(',');
-        }
-    }
-
-    n += p.write('}');
-
-    return n;
-}
-
-JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(JsonKey key) const
-{
-    KeyValuePair* p = items;
-
-    for (int i = count; i > 0; --i)
-    {
-        if (!strcmp(p->key, key))
-            return p;
-
-        p++;
-    }
-
-    return 0;
-}
-
-JsonValue& JsonObjectBase::operator[](JsonKey key)
-{
-    KeyValuePair* match = getMatchingPair(key);
-
-    if (match)
-        return match->value;
-
-    JsonValue* value;
-
-    if (count < capacity)
-    {
-        items[count].key = key;
-        value = &items[count].value;
-        count++;
-    }
-    else
-    {
-        value = &nullValue;
-    }
-
-    value->reset();
-    return *value;
-}
-
-bool JsonObjectBase::containsKey(JsonKey key) const
-{
-    return getMatchingPair(key) != 0;
-}
-
-void JsonObjectBase::remove(JsonKey key)
-{
-    KeyValuePair* match = getMatchingPair(key);    
-    if (match == 0) return;
-
-    *match = items[--count];
-}
+*/
+
+#include "JsonObjectBase.h"
+#include <string.h> // for strcmp
+
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+JsonValue JsonObjectBase::nullValue;
+
+size_t JsonObjectBase::printTo(Print& p) const
+{
+    size_t n = 0;
+
+    n += p.write('{');
+
+    // NB: the code has been optimized for a small size on a 8-bit AVR
+
+    const KeyValuePair* current = items;
+    for (int i = count; i > 0; i--)
+    {       
+        n += EscapedString::printTo(current->key, p);
+        n += p.write(':');
+        n += current->value.printTo(p);
+
+        current++;
+
+        if (i > 1)
+        {
+            n += p.write(',');
+        }
+    }
+
+    n += p.write('}');
+
+    return n;
+}
+
+JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(JsonKey key) const
+{
+    KeyValuePair* p = items;
+
+    for (int i = count; i > 0; --i)
+    {
+        if (!strcmp(p->key, key))
+            return p;
+
+        p++;
+    }
+
+    return 0;
+}
+
+JsonValue& JsonObjectBase::operator[](JsonKey key)
+{
+    KeyValuePair* match = getMatchingPair(key);
+
+    if (match)
+        return match->value;
+
+    JsonValue* value;
+
+    if (count < capacity)
+    {
+        items[count].key = key;
+        value = &items[count].value;
+        count++;
+    }
+    else
+    {
+        value = &nullValue;
+    }
+
+    value->reset();
+    return *value;
+}
+
+bool JsonObjectBase::containsKey(JsonKey key) const
+{
+    return getMatchingPair(key) != 0;
+}
+
+void JsonObjectBase::remove(JsonKey key)
+{
+    KeyValuePair* match = getMatchingPair(key);    
+    if (match == 0) return;
+
+    *match = items[--count];
+}

+ 62 - 62
JsonGenerator/JsonObjectBase.h

@@ -1,62 +1,62 @@
-/*
-* Arduino JSON library
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "JsonPrintable.h"
-#include "JsonValue.h"
-#include "EscapedString.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        typedef const char* JsonKey;
-
-        class JsonObjectBase : public JsonPrintable
-        {
-        public:
-            JsonValue& operator[](JsonKey);
-            bool containsKey(JsonKey) const;
-            void remove(JsonKey key);
-
-            template<typename T>
-            void add(JsonKey key, T value)
-            {
-                operator[](key) = value;
-            }
-
-            template<int DIGITS>
-            void add(JsonKey key, double value)
-            {
-                operator[](key).set<DIGITS>(value);
-            }
-
-            using JsonPrintable::printTo;
-
-            virtual size_t printTo(Print& p) const;
-
-        protected:
-
-            struct KeyValuePair
-            {
-                JsonKey     key;
-                JsonValue   value;
-            };
-
-            JsonObjectBase(KeyValuePair* items, int capacity)
-                : items(items), capacity(capacity), count(0)
-            {
-            }
-
-        private:
-            KeyValuePair* items;
-            int capacity, count;
-            static JsonValue nullValue;
-
-            KeyValuePair* getMatchingPair(JsonKey key) const;
-        };
-    }
-}
+/*
+* Arduino JSON library
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#pragma once
+
+#include "JsonPrintable.h"
+#include "JsonValue.h"
+#include "EscapedString.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        typedef const char* JsonKey;
+
+        class JsonObjectBase : public JsonPrintable
+        {
+        public:
+            JsonValue& operator[](JsonKey);
+            bool containsKey(JsonKey) const;
+            void remove(JsonKey key);
+
+            template<typename T>
+            void add(JsonKey key, T value)
+            {
+                operator[](key) = value;
+            }
+
+            template<int DIGITS>
+            void add(JsonKey key, double value)
+            {
+                operator[](key).set<DIGITS>(value);
+            }
+
+            using JsonPrintable::printTo;
+
+            virtual size_t printTo(Print& p) const;
+
+        protected:
+
+            struct KeyValuePair
+            {
+                JsonKey     key;
+                JsonValue   value;
+            };
+
+            JsonObjectBase(KeyValuePair* items, int capacity)
+                : items(items), capacity(capacity), count(0)
+            {
+            }
+
+        private:
+            KeyValuePair* items;
+            int capacity, count;
+            static JsonValue nullValue;
+
+            KeyValuePair* getMatchingPair(JsonKey key) const;
+        };
+    }
+}

+ 93 - 93
JsonGenerator/JsonPrettyPrint.cpp

@@ -2,96 +2,96 @@
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
 */
-
-#include "JsonPrettyPrint.h"
-
-using namespace ArduinoJson::Generator;
-
-size_t JsonPrettyPrint::write(uint8_t c)
-{
-    size_t n = inString ? handleStringChar(c) : handleMarkupChar(c);    
-    previousChar = c;
-    return n;
-}
-
-inline size_t JsonPrettyPrint::handleStringChar(uint8_t c)
-{
-    bool isQuote = c == '"' && previousChar != '\\';
-
-    if (isQuote) inString = false;
-
-    return sink.write(c);
-}
-
-inline size_t JsonPrettyPrint::handleMarkupChar(uint8_t c)
-{
-    switch (c)
-    {
-    case '{':
-    case '[':
-        return handleBlockOpen(c);
-
-    case '}':
-    case ']':
-        return handleBlockClose(c);
-
-    case ':':
-        return handleColumn();
-
-    case ',':
-        return handleComma();
-
-    case '"':
-        return handleQuoteOpen();
-
-    default:
-        return handleNormalChar(c);
-    }
-}
-
-inline size_t JsonPrettyPrint::handleBlockOpen(uint8_t c)
-{
-    return indentIfNeeded() + sink.write(c);
-}
-
-inline size_t JsonPrettyPrint::handleBlockClose(uint8_t c)
-{  
-    return unindentIfNeeded() + sink.write(c);
-}
-
-inline size_t JsonPrettyPrint::handleColumn()
-{
-    return sink.write(':') + sink.write(' ');
-}
-
-inline size_t JsonPrettyPrint::handleComma() 
-{
-    return sink.write(',') + sink.println();
-}
-
-inline size_t JsonPrettyPrint::handleQuoteOpen()
-{
-    inString = true;
-    return indentIfNeeded() + sink.write('"');
-}
-
-inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c)
-{
-    return indentIfNeeded() + sink.write(c);
-}
-
-size_t JsonPrettyPrint::indentIfNeeded()
-{
-    if (!inEmptyBlock()) return 0;
-
-    sink.indent();
-    return sink.println();
-}
-
-size_t JsonPrettyPrint::unindentIfNeeded()
-{
-    if (inEmptyBlock()) return 0;
-
-    sink.unindent();
-    return sink.println();
-}
+
+#include "JsonPrettyPrint.h"
+
+using namespace ArduinoJson::Generator;
+
+size_t JsonPrettyPrint::write(uint8_t c)
+{
+    size_t n = inString ? handleStringChar(c) : handleMarkupChar(c);    
+    previousChar = c;
+    return n;
+}
+
+inline size_t JsonPrettyPrint::handleStringChar(uint8_t c)
+{
+    bool isQuote = c == '"' && previousChar != '\\';
+
+    if (isQuote) inString = false;
+
+    return sink.write(c);
+}
+
+inline size_t JsonPrettyPrint::handleMarkupChar(uint8_t c)
+{
+    switch (c)
+    {
+    case '{':
+    case '[':
+        return handleBlockOpen(c);
+
+    case '}':
+    case ']':
+        return handleBlockClose(c);
+
+    case ':':
+        return handleColumn();
+
+    case ',':
+        return handleComma();
+
+    case '"':
+        return handleQuoteOpen();
+
+    default:
+        return handleNormalChar(c);
+    }
+}
+
+inline size_t JsonPrettyPrint::handleBlockOpen(uint8_t c)
+{
+    return indentIfNeeded() + sink.write(c);
+}
+
+inline size_t JsonPrettyPrint::handleBlockClose(uint8_t c)
+{  
+    return unindentIfNeeded() + sink.write(c);
+}
+
+inline size_t JsonPrettyPrint::handleColumn()
+{
+    return sink.write(':') + sink.write(' ');
+}
+
+inline size_t JsonPrettyPrint::handleComma() 
+{
+    return sink.write(',') + sink.println();
+}
+
+inline size_t JsonPrettyPrint::handleQuoteOpen()
+{
+    inString = true;
+    return indentIfNeeded() + sink.write('"');
+}
+
+inline size_t JsonPrettyPrint::handleNormalChar(uint8_t c)
+{
+    return indentIfNeeded() + sink.write(c);
+}
+
+size_t JsonPrettyPrint::indentIfNeeded()
+{
+    if (!inEmptyBlock()) return 0;
+
+    sink.indent();
+    return sink.println();
+}
+
+size_t JsonPrettyPrint::unindentIfNeeded()
+{
+    if (inEmptyBlock()) return 0;
+
+    sink.unindent();
+    return sink.println();
+}

+ 49 - 49
JsonGenerator/JsonPrettyPrint.h

@@ -1,52 +1,52 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "Print.h"
-#include "IndentedPrint.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        // Converts a compact JSON string into an indented one.
-        class JsonPrettyPrint : public Print
-        {
-        public:
-
-            JsonPrettyPrint(IndentedPrint& p)
-                : sink(p)
-            {
-                previousChar = 0;
-                inString = false;
-            }
-
-            virtual size_t write(uint8_t);
-
-        private:            
-            uint8_t previousChar;
-            IndentedPrint& sink;
-            bool inString;
-
-            bool inEmptyBlock()
-            {
-                return previousChar == '{' || previousChar == '[';
-            }
-
-            size_t handleStringChar(uint8_t);
-            size_t handleMarkupChar(uint8_t);
-
-            size_t handleBlockClose(uint8_t);
-            size_t handleBlockOpen(uint8_t);
-            size_t handleColumn();
-            size_t handleComma();
-            size_t handleQuoteOpen();
-            size_t handleNormalChar(uint8_t);
-            size_t indentIfNeeded();
-            size_t unindentIfNeeded();
-        };
-    }
-}
+*/
+
+#pragma once
+
+#include "Print.h"
+#include "IndentedPrint.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        // Converts a compact JSON string into an indented one.
+        class JsonPrettyPrint : public Print
+        {
+        public:
+
+            JsonPrettyPrint(IndentedPrint& p)
+                : sink(p)
+            {
+                previousChar = 0;
+                inString = false;
+            }
+
+            virtual size_t write(uint8_t);
+
+        private:            
+            uint8_t previousChar;
+            IndentedPrint& sink;
+            bool inString;
+
+            bool inEmptyBlock()
+            {
+                return previousChar == '{' || previousChar == '[';
+            }
+
+            size_t handleStringChar(uint8_t);
+            size_t handleMarkupChar(uint8_t);
+
+            size_t handleBlockClose(uint8_t);
+            size_t handleBlockOpen(uint8_t);
+            size_t handleColumn();
+            size_t handleComma();
+            size_t handleQuoteOpen();
+            size_t handleNormalChar(uint8_t);
+            size_t indentIfNeeded();
+            size_t unindentIfNeeded();
+        };
+    }
+}

+ 32 - 32
JsonGenerator/JsonPrintable.cpp

@@ -1,35 +1,35 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonPrintable.h"
-#include "JsonPrettyPrint.h"
-#include "StringBuilder.h"
-
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-size_t JsonPrintable::printTo(char* buffer, size_t bufferSize) const
-{
-    StringBuilder sb(buffer, bufferSize);
-    return printTo(sb);
-}
-
-size_t JsonPrintable::prettyPrintTo(char* buffer, size_t bufferSize) const
-{
-    StringBuilder sb(buffer, bufferSize);
-    return prettyPrintTo(sb);
-}
-
-size_t JsonPrintable::prettyPrintTo(IndentedPrint& p) const
-{
-    JsonPrettyPrint prettyPrint(p);
-    return printTo(prettyPrint);
-}
-
-size_t JsonPrintable::prettyPrintTo(Print& p) const
-{
-    IndentedPrint indentedPrint(p);
-    return prettyPrintTo(indentedPrint);
-}
+*/
+
+#include "JsonPrintable.h"
+#include "JsonPrettyPrint.h"
+#include "StringBuilder.h"
+
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+size_t JsonPrintable::printTo(char* buffer, size_t bufferSize) const
+{
+    StringBuilder sb(buffer, bufferSize);
+    return printTo(sb);
+}
+
+size_t JsonPrintable::prettyPrintTo(char* buffer, size_t bufferSize) const
+{
+    StringBuilder sb(buffer, bufferSize);
+    return prettyPrintTo(sb);
+}
+
+size_t JsonPrintable::prettyPrintTo(IndentedPrint& p) const
+{
+    JsonPrettyPrint prettyPrint(p);
+    return printTo(prettyPrint);
+}
+
+size_t JsonPrintable::prettyPrintTo(Print& p) const
+{
+    IndentedPrint indentedPrint(p);
+    return prettyPrintTo(indentedPrint);
+}

+ 40 - 40
JsonGenerator/JsonPrintable.h

@@ -1,40 +1,40 @@
-/*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "Print.h"
-#include "Printable.h"
-#include "IndentedPrint.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        // Contains methods to generate a JSON string.
-        // Implemented by both JsonObject and JsonArray
-        class JsonPrintable : public Printable
-        {
-        public:
-
-            // Generates the compact JSON string and sends it to a Print stream 
-            virtual size_t printTo(Print& p) const = 0;
-
-            // Generates the compact JSON string and writes it in a buffer
-            size_t printTo(char* buffer, size_t bufferSize) const;
-
-            // Generates the indented JSON string and sends it to a Print stream
-            size_t prettyPrintTo(Print& p) const;
-
-            // Generates the indented JSON string and sends it to a IndentedPrint stream
-            // This overload allows a finer control of the output because you can customize
-            // the IndentedPrint.
-            size_t prettyPrintTo(IndentedPrint& p) const;
-
-            // Generates the indented JSON string and writes it in a buffer
-            size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
-        };
-    }
-}
+/*
+ * Arduino JSON library
+ * Benoit Blanchon 2014 - MIT License
+ */
+
+#pragma once
+
+#include "Print.h"
+#include "Printable.h"
+#include "IndentedPrint.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        // Contains methods to generate a JSON string.
+        // Implemented by both JsonObject and JsonArray
+        class JsonPrintable : public Printable
+        {
+        public:
+
+            // Generates the compact JSON string and sends it to a Print stream 
+            virtual size_t printTo(Print& p) const = 0;
+
+            // Generates the compact JSON string and writes it in a buffer
+            size_t printTo(char* buffer, size_t bufferSize) const;
+
+            // Generates the indented JSON string and sends it to a Print stream
+            size_t prettyPrintTo(Print& p) const;
+
+            // Generates the indented JSON string and sends it to a IndentedPrint stream
+            // This overload allows a finer control of the output because you can customize
+            // the IndentedPrint.
+            size_t prettyPrintTo(IndentedPrint& p) const;
+
+            // Generates the indented JSON string and writes it in a buffer
+            size_t prettyPrintTo(char* buffer, size_t bufferSize) const;
+        };
+    }
+}

+ 29 - 29
JsonGenerator/JsonValue.cpp

@@ -2,32 +2,32 @@
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
  */
-
-#include "EscapedString.h"
-#include "JsonValue.h"
-
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-size_t JsonValue::printBoolTo(const Content& c, Print& p)
-{
-    return p.print(c.asBool ? "true" : "false");
-}
-
-size_t JsonValue::printLongTo(const Content& c, Print& p)
-{
-    return p.print(c.asLong);
-}
-
-size_t JsonValue::printPrintableTo(const Content& c, Print& p)
-{
-    if (c.asPrintable)
-        return c.asPrintable->printTo(p);
-    else
-        return p.print("null");
-}
-
-size_t JsonValue::printStringTo(const Content& c, Print& p)
-{
-    return EscapedString::printTo(c.asString, p);
-}
+
+#include "EscapedString.h"
+#include "JsonValue.h"
+
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+size_t JsonValue::printBoolTo(const Content& c, Print& p)
+{
+    return p.print(c.asBool ? "true" : "false");
+}
+
+size_t JsonValue::printLongTo(const Content& c, Print& p)
+{
+    return p.print(c.asLong);
+}
+
+size_t JsonValue::printPrintableTo(const Content& c, Print& p)
+{
+    if (c.asPrintable)
+        return c.asPrintable->printTo(p);
+    else
+        return p.print("null");
+}
+
+size_t JsonValue::printStringTo(const Content& c, Print& p)
+{
+    return EscapedString::printTo(c.asString, p);
+}

+ 132 - 132
JsonGenerator/JsonValue.h

@@ -1,135 +1,135 @@
 /*
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "EscapedString.h"
-#include "Printable.h"
-#include "StringBuilder.h"
-
-namespace ArduinoJson
-{
-    namespace Generator
-    {
-        class JsonValue
-        {
-        public:
-
-            void operator=(bool value)
-            {
-                printToImpl = &printBoolTo;
-                content.asBool = value;
-            }
-
-            void operator=(long value)
-            {
-                printToImpl = &printLongTo;
-                content.asLong = value;
-            }
-
-            void operator=(int value)
-            {
-                printToImpl = &printLongTo;
-                content.asLong = value;
-            }
-
-            void operator=(const Printable& value)
-            {
-                printToImpl = &printPrintableTo;
-                content.asPrintable = &value;
-            }
-
-            void operator=(const char* value)
-            {
-                printToImpl = &printStringTo;
-                content.asString = value;
-            }
-
-            void operator=(double value)
-            {
-                set<2>(value);
-            }
-
-            template <int DIGITS>
-            void set(double value)
-            {
-                printToImpl = &printDoubleTo < DIGITS > ;
-                content.asDouble = value;
-            }
-
-            operator bool()
-            {
-                return content.asBool;
-            }
-
-            operator const char*()
-            {
-                return content.asString;
-            }
-
-            operator double()
-            {
-                return content.asDouble;
-            }
-
-            operator float()
-            {
-                return (float)content.asDouble;
-            }
-
-            operator int()
-            {
-                return content.asLong;
-            }
-
-            operator long()
-            {
-                return content.asLong;
-            }
-
-            operator const Printable&()
-            {
-                return *content.asPrintable;
-            }
-
-            size_t printTo(Print& p) const
-            {
-                // handmade polymorphism
-                return printToImpl(content, p);
-            }
-
-            void reset()
-            {
-                content.asDouble = 0;
-                printToImpl = printStringTo;
-            }
-
-        private:
-            union Content
-            {
-                bool                asBool;
-                double              asDouble;
-                long                asLong;
-                const Printable*    asPrintable;
-                const char*         asString;
-            };
-
-            Content content;
-
-            size_t(*printToImpl)(const Content&, Print&);
-
-            static size_t printBoolTo(const Content&, Print&);
-            static size_t printLongTo(const Content&, Print&);
-            static size_t printPrintableTo(const Content&, Print&);
-            static size_t printStringTo(const Content&, Print&);
-
-            template <int DIGITS>
-            static size_t printDoubleTo(const Content& c, Print& p)
-            {
-                return p.print(c.asDouble, DIGITS);
-            }
-        };
-    }
-}
+ */
+
+#pragma once
+
+#include "EscapedString.h"
+#include "Printable.h"
+#include "StringBuilder.h"
+
+namespace ArduinoJson
+{
+    namespace Generator
+    {
+        class JsonValue
+        {
+        public:
+
+            void operator=(bool value)
+            {
+                printToImpl = &printBoolTo;
+                content.asBool = value;
+            }
+
+            void operator=(long value)
+            {
+                printToImpl = &printLongTo;
+                content.asLong = value;
+            }
+
+            void operator=(int value)
+            {
+                printToImpl = &printLongTo;
+                content.asLong = value;
+            }
+
+            void operator=(const Printable& value)
+            {
+                printToImpl = &printPrintableTo;
+                content.asPrintable = &value;
+            }
+
+            void operator=(const char* value)
+            {
+                printToImpl = &printStringTo;
+                content.asString = value;
+            }
+
+            void operator=(double value)
+            {
+                set<2>(value);
+            }
+
+            template <int DIGITS>
+            void set(double value)
+            {
+                printToImpl = &printDoubleTo < DIGITS > ;
+                content.asDouble = value;
+            }
+
+            operator bool()
+            {
+                return content.asBool;
+            }
+
+            operator const char*()
+            {
+                return content.asString;
+            }
+
+            operator double()
+            {
+                return content.asDouble;
+            }
+
+            operator float()
+            {
+                return (float)content.asDouble;
+            }
+
+            operator int()
+            {
+                return content.asLong;
+            }
+
+            operator long()
+            {
+                return content.asLong;
+            }
+
+            operator const Printable&()
+            {
+                return *content.asPrintable;
+            }
+
+            size_t printTo(Print& p) const
+            {
+                // handmade polymorphism
+                return printToImpl(content, p);
+            }
+
+            void reset()
+            {
+                content.asDouble = 0;
+                printToImpl = printStringTo;
+            }
+
+        private:
+            union Content
+            {
+                bool                asBool;
+                double              asDouble;
+                long                asLong;
+                const Printable*    asPrintable;
+                const char*         asString;
+            };
+
+            Content content;
+
+            size_t(*printToImpl)(const Content&, Print&);
+
+            static size_t printBoolTo(const Content&, Print&);
+            static size_t printLongTo(const Content&, Print&);
+            static size_t printPrintableTo(const Content&, Print&);
+            static size_t printStringTo(const Content&, Print&);
+
+            template <int DIGITS>
+            static size_t printDoubleTo(const Content& c, Print& p)
+            {
+                return p.print(c.asDouble, DIGITS);
+            }
+        };
+    }
+}

+ 49 - 49
JsonGenerator/Print.cpp

@@ -5,52 +5,52 @@
 
 #ifndef ARDUINO
 
-#include "Print.h"
-#include <string> // for sprintf, strchr and strcat
-
-size_t Print::print(const char s[])
-{
-    size_t n = 0;
-    while (*s)
-    {
-        n += write(*s++);
-    }
-    return n;
-}
-
-static inline void ensureStringContainsPoint(char* s)
-{
-    // Ensures that the decimal point is present.
-    // For example, we don't want "0" but "0.0".
-    // Otherwise, the value would be considered as an integer by some parsers
-    // See issue #22
-
-    if (!strchr(s, '.'))
-        strcat(s, ".0");
-}
-
-size_t Print::print(double value, int digits)
-{
-    char tmp[32];
-
-    sprintf(tmp, "%.*lg", digits+1, value);
-
-    if (digits>0)
-        ensureStringContainsPoint(tmp);
-
-    return print(tmp);
-}
-
-size_t Print::print(long value)
-{
-    char tmp[32];
-    sprintf(tmp, "%ld", value);
-    return print(tmp);
-}
-
-size_t Print::println()
-{
-    return write('\r') + write('\n');
-}
-
-#endif
+#include "Print.h"
+#include <string> // for sprintf, strchr and strcat
+
+size_t Print::print(const char s[])
+{
+    size_t n = 0;
+    while (*s)
+    {
+        n += write(*s++);
+    }
+    return n;
+}
+
+static inline void ensureStringContainsPoint(char* s)
+{
+    // Ensures that the decimal point is present.
+    // For example, we don't want "0" but "0.0".
+    // Otherwise, the value would be considered as an integer by some parsers
+    // See issue #22
+
+    if (!strchr(s, '.'))
+        strcat(s, ".0");
+}
+
+size_t Print::print(double value, int digits)
+{
+    char tmp[32];
+
+    sprintf(tmp, "%.*lg", digits+1, value);
+
+    if (digits>0)
+        ensureStringContainsPoint(tmp);
+
+    return print(tmp);
+}
+
+size_t Print::print(long value)
+{
+    char tmp[32];
+    sprintf(tmp, "%ld", value);
+    return print(tmp);
+}
+
+size_t Print::println()
+{
+    return write('\r') + write('\n');
+}
+
+#endif

+ 26 - 26
JsonGenerator/Print.h

@@ -2,29 +2,29 @@
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
  */
-
-#pragma once
-
-#ifndef ARDUINO
-
-#include <stddef.h>
-#include <stdint.h>
-
-// This class reproduces Arduino's Print
-class Print
-{
-public:
-
-    virtual size_t write(uint8_t) = 0;
-
-    size_t print(const char[]);
-    size_t print(double, int = 2);
-    size_t print(long);
-    size_t println();
-};
-
-#else
-
-#include <Print.h>
-
-#endif
+
+#pragma once
+
+#ifndef ARDUINO
+
+#include <stddef.h>
+#include <stdint.h>
+
+// This class reproduces Arduino's Print
+class Print
+{
+public:
+
+    virtual size_t write(uint8_t) = 0;
+
+    size_t print(const char[]);
+    size_t print(double, int = 2);
+    size_t print(long);
+    size_t println();
+};
+
+#else
+
+#include <Print.h>
+
+#endif

+ 20 - 20
JsonGenerator/Printable.h

@@ -2,23 +2,23 @@
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
  */
-
-#pragma once
-
-#ifndef ARDUINO
-
-class Print;
-
-class Printable
-{
-public:
-
-    virtual size_t printTo(Print& p) const = 0;
-};
-
-#else
-
-#include <Printable.h>
-
-#endif
-
+
+#pragma once
+
+#ifndef ARDUINO
+
+class Print;
+
+class Printable
+{
+public:
+
+    virtual size_t printTo(Print& p) const = 0;
+};
+
+#else
+
+#include <Printable.h>
+
+#endif
+

+ 14 - 14
JsonGenerator/StringBuilder.cpp

@@ -1,17 +1,17 @@
 /*
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
- */
-
-#include "StringBuilder.h"
-
-using namespace ArduinoJson::Internals;
-
-size_t StringBuilder::write(uint8_t c)
-{
-    if (length >= capacity) return 0;
-
-    buffer[length++] = c;
-    buffer[length] = 0;
-    return 1;
-}
+ */
+
+#include "StringBuilder.h"
+
+using namespace ArduinoJson::Internals;
+
+size_t StringBuilder::write(uint8_t c)
+{
+    if (length >= capacity) return 0;
+
+    buffer[length++] = c;
+    buffer[length] = 0;
+    return 1;
+}

+ 31 - 31
JsonGenerator/StringBuilder.h

@@ -1,31 +1,31 @@
-/*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "Print.h"
-
-namespace ArduinoJson
-{
-    namespace Internals
-    {
-        class StringBuilder : public Print
-        {
-        public:
-            StringBuilder(char* buf, int size)
-                : buffer(buf), capacity(size - 1), length(0)
-            {
-                buffer[0] = 0;
-            }
-
-            virtual size_t write(uint8_t c);
-
-        private:
-            char* buffer;
-            int capacity;
-            int length;
-        };
-    }
-}
+/*
+ * Arduino JSON library
+ * Benoit Blanchon 2014 - MIT License
+ */
+
+#pragma once
+
+#include "Print.h"
+
+namespace ArduinoJson
+{
+    namespace Internals
+    {
+        class StringBuilder : public Print
+        {
+        public:
+            StringBuilder(char* buf, int size)
+                : buffer(buf), capacity(size - 1), length(0)
+            {
+                buffer[0] = 0;
+            }
+
+            virtual size_t write(uint8_t c);
+
+        private:
+            char* buffer;
+            int capacity;
+            int length;
+        };
+    }
+}

+ 92 - 92
JsonGeneratorTests/EscapedStringTests.cpp

@@ -1,95 +1,95 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "EscapedString.h"
-#include "StringBuilder.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Internals;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(EscapedStringTests)
-    {
-        char buffer[1024];
-        size_t returnValue;
-        
-    public:
-
-        TEST_METHOD(Null)
-        {
-            whenInputIs(0);
-            outputMustBe("null");
-        }
-
-        TEST_METHOD(EmptyString)
-        {
-            whenInputIs("");
-            outputMustBe("\"\"");
-        }
-
-        TEST_METHOD(QuotationMark)
-        {
-            whenInputIs("\"");
-            outputMustBe("\"\\\"\"");
-        }
-
-        TEST_METHOD(ReverseSolidus)
-        {
-            whenInputIs("\\");
-            outputMustBe("\"\\\\\"");
-        }
-
-        TEST_METHOD(Solidus)
-        {
-            whenInputIs("/");
-            outputMustBe("\"/\""); // but the JSON format allows \/
-        }
-
-        TEST_METHOD(Backspace)
-        {
-            whenInputIs("\b");
-            outputMustBe("\"\\b\"");
-        }
-
-        TEST_METHOD(Formfeed)
-        {
-            whenInputIs("\f");
-            outputMustBe("\"\\f\"");
-        }
-
-        TEST_METHOD(Newline)
-        {
-            whenInputIs("\n");
-            outputMustBe("\"\\n\"");
-        }
-
-        TEST_METHOD(CarriageReturn)
-        {
-            whenInputIs("\r");
-            outputMustBe("\"\\r\"");
-        }
-
-        TEST_METHOD(HorizontalTab)
-        {
-            whenInputIs("\t");
-            outputMustBe("\"\\t\"");
-        }
-
-    private:
-        void whenInputIs(const char* input)
-        {
-            StringBuilder sb(buffer, sizeof(buffer));  
-            returnValue = EscapedString::printTo(input, sb);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "EscapedString.h"
+#include "StringBuilder.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Internals;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(EscapedStringTests)
+    {
+        char buffer[1024];
+        size_t returnValue;
+        
+    public:
+
+        TEST_METHOD(Null)
+        {
+            whenInputIs(0);
+            outputMustBe("null");
+        }
+
+        TEST_METHOD(EmptyString)
+        {
+            whenInputIs("");
+            outputMustBe("\"\"");
+        }
+
+        TEST_METHOD(QuotationMark)
+        {
+            whenInputIs("\"");
+            outputMustBe("\"\\\"\"");
+        }
+
+        TEST_METHOD(ReverseSolidus)
+        {
+            whenInputIs("\\");
+            outputMustBe("\"\\\\\"");
+        }
+
+        TEST_METHOD(Solidus)
+        {
+            whenInputIs("/");
+            outputMustBe("\"/\""); // but the JSON format allows \/
+        }
+
+        TEST_METHOD(Backspace)
+        {
+            whenInputIs("\b");
+            outputMustBe("\"\\b\"");
+        }
+
+        TEST_METHOD(Formfeed)
+        {
+            whenInputIs("\f");
+            outputMustBe("\"\\f\"");
+        }
+
+        TEST_METHOD(Newline)
+        {
+            whenInputIs("\n");
+            outputMustBe("\"\\n\"");
+        }
+
+        TEST_METHOD(CarriageReturn)
+        {
+            whenInputIs("\r");
+            outputMustBe("\"\\r\"");
+        }
+
+        TEST_METHOD(HorizontalTab)
+        {
+            whenInputIs("\t");
+            outputMustBe("\"\\t\"");
+        }
+
+    private:
+        void whenInputIs(const char* input)
+        {
+            StringBuilder sb(buffer, sizeof(buffer));  
+            returnValue = EscapedString::printTo(input, sb);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), returnValue);
+        }
+    };
+}

+ 73 - 73
JsonGeneratorTests/Issue10.cpp

@@ -1,73 +1,73 @@
-#include "CppUnitTest.h"
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-using namespace ArduinoJson::Generator;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(Issue10)
-    {
-        struct Person {
-            int id;
-            char name[32];
-        };
-
-        Person persons[2];
-
-    public:
-
-        TEST_METHOD_INITIALIZE(Initialize)
-        {
-            Person boss;
-            boss.id = 1;
-            strcpy(boss.name, "Jeff");
-            Person employee;
-            employee.id = 2;
-            strcpy(employee.name, "John");
-            persons[0] = boss;
-            persons[1] = employee;
-        }
-
-        TEST_METHOD(WrongWayToAddObjectInAnArray)
-        {
-            JsonArray<2> json;
-
-            for (int i = 0; i < 2; i++)
-            {
-                JsonObject<2> object;
-                
-                object["id"] = persons[i].id;
-                object["name"] = persons[i].name;
-
-                json.add(object); // <- Adding a reference to a temporary variable
-            }
-
-            char buffer[256];
-            json.printTo(buffer, sizeof(buffer));
-
-            // the same values are repeated, that's normal
-            Assert::AreEqual("[{\"id\":2,\"name\":\"John\"},{\"id\":2,\"name\":\"John\"}]", buffer);  
-        }
-
-        TEST_METHOD(RightWayToAddObjectInAnArray)
-        {
-            JsonArray<2> json;
-            JsonObject<2> object[2];
-
-            for (int i = 0; i < 2; i++) 
-            {
-                object[i]["id"] = persons[i].id;
-                object[i]["name"] = persons[i].name;
-
-                json.add(object[i]);
-            }
-
-            char buffer[256];
-            json.printTo(buffer, sizeof(buffer));
-
-            Assert::AreEqual("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer);
-        }
-    };
-}
+#include "CppUnitTest.h"
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace ArduinoJson::Generator;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(Issue10)
+    {
+        struct Person {
+            int id;
+            char name[32];
+        };
+
+        Person persons[2];
+
+    public:
+
+        TEST_METHOD_INITIALIZE(Initialize)
+        {
+            Person boss;
+            boss.id = 1;
+            strcpy(boss.name, "Jeff");
+            Person employee;
+            employee.id = 2;
+            strcpy(employee.name, "John");
+            persons[0] = boss;
+            persons[1] = employee;
+        }
+
+        TEST_METHOD(WrongWayToAddObjectInAnArray)
+        {
+            JsonArray<2> json;
+
+            for (int i = 0; i < 2; i++)
+            {
+                JsonObject<2> object;
+                
+                object["id"] = persons[i].id;
+                object["name"] = persons[i].name;
+
+                json.add(object); // <- Adding a reference to a temporary variable
+            }
+
+            char buffer[256];
+            json.printTo(buffer, sizeof(buffer));
+
+            // the same values are repeated, that's normal
+            Assert::AreEqual("[{\"id\":2,\"name\":\"John\"},{\"id\":2,\"name\":\"John\"}]", buffer);  
+        }
+
+        TEST_METHOD(RightWayToAddObjectInAnArray)
+        {
+            JsonArray<2> json;
+            JsonObject<2> object[2];
+
+            for (int i = 0; i < 2; i++) 
+            {
+                object[i]["id"] = persons[i].id;
+                object[i]["name"] = persons[i].name;
+
+                json.add(object[i]);
+            }
+
+            char buffer[256];
+            json.printTo(buffer, sizeof(buffer));
+
+            Assert::AreEqual("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]", buffer);
+        }
+    };
+}

+ 159 - 159
JsonGeneratorTests/JsonArrayTests.cpp

@@ -1,162 +1,162 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Generator;
-
-namespace JsonGeneratorTests
-{		
-    TEST_CLASS(JsonArrayTests)
-    {
-        JsonArray<2> array;
-        char buffer[256];
-
-    public:
-        
-        TEST_METHOD(Empty)
-        {
-            outputMustBe("[]");
-        }
-
-        TEST_METHOD(Null)
-        {
-            array.add((char*) 0);
-
-            outputMustBe("[null]");
-        }
-
-        TEST_METHOD(OneString)
-        {
-            array.add("hello");
-
-            outputMustBe("[\"hello\"]");
-        }
-
-        TEST_METHOD(TwoStrings)
-        {
-            array.add("hello");
-            array.add("world");
-
-            outputMustBe("[\"hello\",\"world\"]");
-        }
-
-        TEST_METHOD(OneStringOverCapacity)
-        {
-            array.add("hello");
-            array.add("world");
-            array.add("lost");
-
-            outputMustBe("[\"hello\",\"world\"]");
-        }
-
-        TEST_METHOD(OneDoubleDefaultDigits)
-        {
-            array.add(3.14159265358979323846);
-            outputMustBe("[3.14]");
-        }
-
-        TEST_METHOD(OneDoubleFourDigits)
-        {
-            array.add<4>(3.14159265358979323846);
-            outputMustBe("[3.1416]");
-        }
-
-        TEST_METHOD(OneInteger)
-        {
-            array.add(1);
-
-            outputMustBe("[1]");
-        }
-
-        TEST_METHOD(TwoIntegers)
-        {
-            array.add(1);
-            array.add(2);
-
-            outputMustBe("[1,2]");
-        }
-
-        TEST_METHOD(OneIntegerOverCapacity)
-        {
-            array.add(1);
-            array.add(2);
-            array.add(3);
-
-            outputMustBe("[1,2]");
-        }
-
-        TEST_METHOD(OneTrue)
-        {
-            array.add(true);
-
-            outputMustBe("[true]");
-        }
-
-        TEST_METHOD(OneFalse)
-        {
-            array.add(false);
-
-            outputMustBe("[false]");
-        }
-
-        TEST_METHOD(TwoBooleans)
-        {
-            array.add(false);
-            array.add(true);
-
-            outputMustBe("[false,true]");
-        }
-
-        TEST_METHOD(OneBooleanOverCapacity)
-        {
-            array.add(false);
-            array.add(true);
-            array.add(false);
-
-            outputMustBe("[false,true]");
-        }
-
-        TEST_METHOD(OneEmptyNestedArray)
-        {
-            JsonArray<1> nestedArray;
-            
-            array.add(nestedArray);
-
-            outputMustBe("[[]]");
-        }
-
-        TEST_METHOD(OneEmptyNestedHash)
-        {
-            JsonObject<1> nestedObject;
-
-            array.add(nestedObject);
-
-            outputMustBe("[{}]");
-        }
-
-        TEST_METHOD(OneNestedArrayWithOneInteger)
-        {
-            JsonArray<1> nestedArray;
-            nestedArray.add(1);
-
-            array.add(nestedArray);
-
-            outputMustBe("[[1]]");
-        }
-
-    private:
-
-        void outputMustBe(const char* expected)
-        {      
-            size_t n = array.printTo(buffer, sizeof(buffer));
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), n);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+
+namespace JsonGeneratorTests
+{		
+    TEST_CLASS(JsonArrayTests)
+    {
+        JsonArray<2> array;
+        char buffer[256];
+
+    public:
+        
+        TEST_METHOD(Empty)
+        {
+            outputMustBe("[]");
+        }
+
+        TEST_METHOD(Null)
+        {
+            array.add((char*) 0);
+
+            outputMustBe("[null]");
+        }
+
+        TEST_METHOD(OneString)
+        {
+            array.add("hello");
+
+            outputMustBe("[\"hello\"]");
+        }
+
+        TEST_METHOD(TwoStrings)
+        {
+            array.add("hello");
+            array.add("world");
+
+            outputMustBe("[\"hello\",\"world\"]");
+        }
+
+        TEST_METHOD(OneStringOverCapacity)
+        {
+            array.add("hello");
+            array.add("world");
+            array.add("lost");
+
+            outputMustBe("[\"hello\",\"world\"]");
+        }
+
+        TEST_METHOD(OneDoubleDefaultDigits)
+        {
+            array.add(3.14159265358979323846);
+            outputMustBe("[3.14]");
+        }
+
+        TEST_METHOD(OneDoubleFourDigits)
+        {
+            array.add<4>(3.14159265358979323846);
+            outputMustBe("[3.1416]");
+        }
+
+        TEST_METHOD(OneInteger)
+        {
+            array.add(1);
+
+            outputMustBe("[1]");
+        }
+
+        TEST_METHOD(TwoIntegers)
+        {
+            array.add(1);
+            array.add(2);
+
+            outputMustBe("[1,2]");
+        }
+
+        TEST_METHOD(OneIntegerOverCapacity)
+        {
+            array.add(1);
+            array.add(2);
+            array.add(3);
+
+            outputMustBe("[1,2]");
+        }
+
+        TEST_METHOD(OneTrue)
+        {
+            array.add(true);
+
+            outputMustBe("[true]");
+        }
+
+        TEST_METHOD(OneFalse)
+        {
+            array.add(false);
+
+            outputMustBe("[false]");
+        }
+
+        TEST_METHOD(TwoBooleans)
+        {
+            array.add(false);
+            array.add(true);
+
+            outputMustBe("[false,true]");
+        }
+
+        TEST_METHOD(OneBooleanOverCapacity)
+        {
+            array.add(false);
+            array.add(true);
+            array.add(false);
+
+            outputMustBe("[false,true]");
+        }
+
+        TEST_METHOD(OneEmptyNestedArray)
+        {
+            JsonArray<1> nestedArray;
+            
+            array.add(nestedArray);
+
+            outputMustBe("[[]]");
+        }
+
+        TEST_METHOD(OneEmptyNestedHash)
+        {
+            JsonObject<1> nestedObject;
+
+            array.add(nestedObject);
+
+            outputMustBe("[{}]");
+        }
+
+        TEST_METHOD(OneNestedArrayWithOneInteger)
+        {
+            JsonArray<1> nestedArray;
+            nestedArray.add(1);
+
+            array.add(nestedArray);
+
+            outputMustBe("[[1]]");
+        }
+
+    private:
+
+        void outputMustBe(const char* expected)
+        {      
+            size_t n = array.printTo(buffer, sizeof(buffer));
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), n);
+        }
+    };
+}

+ 70 - 70
JsonGeneratorTests/JsonObject_Indexer_Tests.cpp

@@ -1,73 +1,73 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Generator;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(JsonObject_Indexer_Tests)
-    {
-        JsonObject<2> object;
-
-    public:
-
-        TEST_METHOD(Empty)
-        {
-            mustNotContain("key");
-        }
-        
-        TEST_METHOD(TwoStrings)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-
-            mustContain("key1", "value1");
-            mustContain("key2", "value2");
-        }
-
-        TEST_METHOD(RemoveFirst)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object.remove("key1");
-
-            mustNotContain("key1");
-            mustContain("key2", "value2");
-        }
-
-        TEST_METHOD(RemoveLast)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object.remove("key2");
-
-            mustContain("key1", "value1");
-            mustNotContain("key2");
-        }
-
-    private:
-
-        void mustContain(const char* key, const char* expected)
-        {
-            Assert::IsTrue(object.containsKey(key));
-
-            const char* actual = object[key];
-            Assert::AreEqual(expected, actual);
-        }
-
-        void mustNotContain(const char* key)
-        {
-            Assert::IsFalse(object.containsKey(key));
-
-            const char* actual = object[key];
-            Assert::IsNull(actual);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(JsonObject_Indexer_Tests)
+    {
+        JsonObject<2> object;
+
+    public:
+
+        TEST_METHOD(Empty)
+        {
+            mustNotContain("key");
+        }
+        
+        TEST_METHOD(TwoStrings)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+
+            mustContain("key1", "value1");
+            mustContain("key2", "value2");
+        }
+
+        TEST_METHOD(RemoveFirst)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object.remove("key1");
+
+            mustNotContain("key1");
+            mustContain("key2", "value2");
+        }
+
+        TEST_METHOD(RemoveLast)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object.remove("key2");
+
+            mustContain("key1", "value1");
+            mustNotContain("key2");
+        }
+
+    private:
+
+        void mustContain(const char* key, const char* expected)
+        {
+            Assert::IsTrue(object.containsKey(key));
+
+            const char* actual = object[key];
+            Assert::AreEqual(expected, actual);
+        }
+
+        void mustNotContain(const char* key)
+        {
+            Assert::IsFalse(object.containsKey(key));
+
+            const char* actual = object[key];
+            Assert::IsNull(actual);
+        }
+    };
+}

+ 149 - 149
JsonGeneratorTests/JsonObject_PrintTo_Tests.cpp

@@ -1,152 +1,152 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Generator;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(JsonObject_PrintTo_Tests)
-    {
-        JsonObject<2> object;
-
-    public:
-
-        TEST_METHOD(Empty)
-        {
-            outputMustBe("{}");
-        }
-
-        TEST_METHOD(OneString)
-        {
-            object["key"] = "value";
-
-            outputMustBe("{\"key\":\"value\"}");
-        }
-
-        TEST_METHOD(TwoStrings)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-
-            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
-        }
-
-        TEST_METHOD(RemoveFirst)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object.remove("key1");
-
-            outputMustBe("{\"key2\":\"value2\"}");
-        }
-
-        TEST_METHOD(RemoveLast)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object.remove("key2");
-
-            outputMustBe("{\"key1\":\"value1\"}");
-        }
-
-        TEST_METHOD(RemoveUnexistingKey)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object.remove("key3");
-
-            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
-        }
-
-        TEST_METHOD(ReplaceExistingKey)
-        {
-            object["key"] = "value1";
-            object["key"] = "value2";
-
-            outputMustBe("{\"key\":\"value2\"}");
-        }
-
-        TEST_METHOD(OneStringOverCapacity)
-        {
-            object["key1"] = "value1";
-            object["key2"] = "value2";
-            object["key3"] = "value3";
-
-            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
-        }
-
-        TEST_METHOD(OneInteger)
-        {
-            object["key"] = 1;
-            outputMustBe("{\"key\":1}");
-        }
-
-        TEST_METHOD(OneDoubleFourDigits)
-        {
-            object["key"].set<4>(3.14159265358979323846);
-            outputMustBe("{\"key\":3.1416}");
-        }
-
-        TEST_METHOD(OneDoubleDefaultDigits)
-        {
-            object["key"] = 3.14159265358979323846;
-            outputMustBe("{\"key\":3.14}");
-        }
-
-        TEST_METHOD(OneNull)
-        {
-            object["key"] = (char*) 0;
-            outputMustBe("{\"key\":null}");
-        }
-
-        TEST_METHOD(OneTrue)
-        {
-            object["key"] = true;
-            outputMustBe("{\"key\":true}");
-        }
-
-        TEST_METHOD(OneFalse)
-        {
-            object["key"] = false;
-            outputMustBe("{\"key\":false}");
-        }
-
-        TEST_METHOD(OneEmptyNestedArray)
-        {
-            auto nestedArray = JsonArray<1>();
-
-            object["key"] = nestedArray;
-            
-            outputMustBe("{\"key\":[]}");
-        }
-
-        TEST_METHOD(OneEmptyNestedObject)
-        {
-            auto nestedObject = JsonObject<1>();
-
-            object["key"] = nestedObject;
-
-            outputMustBe("{\"key\":{}}");
-        }
-
-    private:
-
-        void outputMustBe(const char* expected)
-        {
-            char buffer[256];
-            size_t result;
-            
-            result = object.printTo(buffer, sizeof(buffer));
-            
-            Assert::AreEqual(strlen(expected), result);
-            Assert::AreEqual(expected, buffer);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(JsonObject_PrintTo_Tests)
+    {
+        JsonObject<2> object;
+
+    public:
+
+        TEST_METHOD(Empty)
+        {
+            outputMustBe("{}");
+        }
+
+        TEST_METHOD(OneString)
+        {
+            object["key"] = "value";
+
+            outputMustBe("{\"key\":\"value\"}");
+        }
+
+        TEST_METHOD(TwoStrings)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+
+            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
+        }
+
+        TEST_METHOD(RemoveFirst)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object.remove("key1");
+
+            outputMustBe("{\"key2\":\"value2\"}");
+        }
+
+        TEST_METHOD(RemoveLast)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object.remove("key2");
+
+            outputMustBe("{\"key1\":\"value1\"}");
+        }
+
+        TEST_METHOD(RemoveUnexistingKey)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object.remove("key3");
+
+            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
+        }
+
+        TEST_METHOD(ReplaceExistingKey)
+        {
+            object["key"] = "value1";
+            object["key"] = "value2";
+
+            outputMustBe("{\"key\":\"value2\"}");
+        }
+
+        TEST_METHOD(OneStringOverCapacity)
+        {
+            object["key1"] = "value1";
+            object["key2"] = "value2";
+            object["key3"] = "value3";
+
+            outputMustBe("{\"key1\":\"value1\",\"key2\":\"value2\"}");
+        }
+
+        TEST_METHOD(OneInteger)
+        {
+            object["key"] = 1;
+            outputMustBe("{\"key\":1}");
+        }
+
+        TEST_METHOD(OneDoubleFourDigits)
+        {
+            object["key"].set<4>(3.14159265358979323846);
+            outputMustBe("{\"key\":3.1416}");
+        }
+
+        TEST_METHOD(OneDoubleDefaultDigits)
+        {
+            object["key"] = 3.14159265358979323846;
+            outputMustBe("{\"key\":3.14}");
+        }
+
+        TEST_METHOD(OneNull)
+        {
+            object["key"] = (char*) 0;
+            outputMustBe("{\"key\":null}");
+        }
+
+        TEST_METHOD(OneTrue)
+        {
+            object["key"] = true;
+            outputMustBe("{\"key\":true}");
+        }
+
+        TEST_METHOD(OneFalse)
+        {
+            object["key"] = false;
+            outputMustBe("{\"key\":false}");
+        }
+
+        TEST_METHOD(OneEmptyNestedArray)
+        {
+            auto nestedArray = JsonArray<1>();
+
+            object["key"] = nestedArray;
+            
+            outputMustBe("{\"key\":[]}");
+        }
+
+        TEST_METHOD(OneEmptyNestedObject)
+        {
+            auto nestedObject = JsonObject<1>();
+
+            object["key"] = nestedObject;
+
+            outputMustBe("{\"key\":{}}");
+        }
+
+    private:
+
+        void outputMustBe(const char* expected)
+        {
+            char buffer[256];
+            size_t result;
+            
+            result = object.printTo(buffer, sizeof(buffer));
+            
+            Assert::AreEqual(strlen(expected), result);
+            Assert::AreEqual(expected, buffer);
+        }
+    };
+}

+ 75 - 75
JsonGeneratorTests/JsonValue_Cast_Tests.cpp

@@ -1,78 +1,78 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "StringBuilder.h"
-#include "JsonValue.h"
-#include "JsonArray.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(JsonValue_Cast_Tests)
-    {
-        JsonValue value;
-
-    public:
-
-        TEST_METHOD(Bool)
-        {
-            setValueAndCheckCast(true);
-            setValueAndCheckCast(false);
-        }
-
-        TEST_METHOD(Double)
-        {
-            setValueAndCheckCast(3.14156);
-        }
-
-        TEST_METHOD(Float)
-        {
-            setValueAndCheckCast(3.14f);
-        }
-
-        TEST_METHOD(Integer)
-        {
-            setValueAndCheckCast(42);
-        }
-
-        TEST_METHOD(Long)
-        {
-            setValueAndCheckCast(42L);
-        }
-
-        TEST_METHOD(Array)
-        {
-            JsonArray<2> array;
-            setValueAndCheckCast(array);
-        }
-
-        TEST_METHOD(String)
-        {
-            setValueAndCheckCast("hello");
-        }
-
-    private:
-
-        template<typename T>
-        void setValueAndCheckCast(T expected)
-        {
-            value = expected;
-            T actual = value;
-            Assert::AreEqual(expected, actual);
-        }
-
-        template<int N>
-        void setValueAndCheckCast(JsonArray<N>& expected)
-        {
-            value = expected;
-            const Printable& actual = value;
-            Assert::AreEqual((void*) &expected, (void*) &actual);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "StringBuilder.h"
+#include "JsonValue.h"
+#include "JsonArray.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(JsonValue_Cast_Tests)
+    {
+        JsonValue value;
+
+    public:
+
+        TEST_METHOD(Bool)
+        {
+            setValueAndCheckCast(true);
+            setValueAndCheckCast(false);
+        }
+
+        TEST_METHOD(Double)
+        {
+            setValueAndCheckCast(3.14156);
+        }
+
+        TEST_METHOD(Float)
+        {
+            setValueAndCheckCast(3.14f);
+        }
+
+        TEST_METHOD(Integer)
+        {
+            setValueAndCheckCast(42);
+        }
+
+        TEST_METHOD(Long)
+        {
+            setValueAndCheckCast(42L);
+        }
+
+        TEST_METHOD(Array)
+        {
+            JsonArray<2> array;
+            setValueAndCheckCast(array);
+        }
+
+        TEST_METHOD(String)
+        {
+            setValueAndCheckCast("hello");
+        }
+
+    private:
+
+        template<typename T>
+        void setValueAndCheckCast(T expected)
+        {
+            value = expected;
+            T actual = value;
+            Assert::AreEqual(expected, actual);
+        }
+
+        template<int N>
+        void setValueAndCheckCast(JsonArray<N>& expected)
+        {
+            value = expected;
+            const Printable& actual = value;
+            Assert::AreEqual((void*) &expected, (void*) &actual);
+        }
+    };
+}

+ 106 - 106
JsonGeneratorTests/JsonValue_PrintTo_Tests.cpp

@@ -1,109 +1,109 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "StringBuilder.h"
-#include "JsonValue.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Generator;
-using namespace ArduinoJson::Internals;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(JsonValue_PrintTo_Tests)
-    {
-        char buffer[1024];
-        size_t returnValue;
-
-    public:
-
-        TEST_METHOD(String)
-        {
-            setValueTo("hello");
-            outputMustBe("\"hello\"");
-        }
-
-        TEST_METHOD(ZeroFloat)
-        {
-            setValueTo(0.0f);
-            outputMustBe("0.0");
-        }
-
-        TEST_METHOD(Float)
-        {
-            setValueTo(3.1415f);
-            outputMustBe("3.14");
-        }
-
-        TEST_METHOD(DoubleZeroDigits)
-        {
-            setValueTo<0>(3.14159265358979323846);
-            outputMustBe("3");
-        }
-
-        TEST_METHOD(DoubleOneDigit)
-        {
-            setValueTo<1>(3.14159265358979323846);
-            outputMustBe("3.1");
-        }
-
-        TEST_METHOD(DoubleTwoDigits)
-        {
-            setValueTo<2>(3.14159265358979323846);
-            outputMustBe("3.14");
-        }
-        
-        TEST_METHOD(Integer)
-        {
-            setValueTo(314);
-            outputMustBe("314");
-        }
-
-        TEST_METHOD(Char)
-        {
-            setValueTo('A');
-            outputMustBe("65");
-        }
-
-        TEST_METHOD(Short)
-        {
-            setValueTo((short)314);
-            outputMustBe("314");
-        }
-
-        TEST_METHOD(Long)
-        {
-            setValueTo(314159265L);
-            outputMustBe("314159265");
-        }
-
-    private:
-
-        template<int DIGITS>
-        void setValueTo(double value)
-        {
-            StringBuilder sb(buffer, sizeof(buffer));
-            JsonValue jsonValue;
-            jsonValue.set<DIGITS>(value);
-            returnValue = jsonValue.printTo(sb);
-        }
-
-        template<typename T>
-        void setValueTo(T value)
-        {
-            StringBuilder sb(buffer, sizeof(buffer));
-            JsonValue jsonValue;
-            jsonValue = value;
-            returnValue = jsonValue.printTo(sb);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "StringBuilder.h"
+#include "JsonValue.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+using namespace ArduinoJson::Internals;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(JsonValue_PrintTo_Tests)
+    {
+        char buffer[1024];
+        size_t returnValue;
+
+    public:
+
+        TEST_METHOD(String)
+        {
+            setValueTo("hello");
+            outputMustBe("\"hello\"");
+        }
+
+        TEST_METHOD(ZeroFloat)
+        {
+            setValueTo(0.0f);
+            outputMustBe("0.0");
+        }
+
+        TEST_METHOD(Float)
+        {
+            setValueTo(3.1415f);
+            outputMustBe("3.14");
+        }
+
+        TEST_METHOD(DoubleZeroDigits)
+        {
+            setValueTo<0>(3.14159265358979323846);
+            outputMustBe("3");
+        }
+
+        TEST_METHOD(DoubleOneDigit)
+        {
+            setValueTo<1>(3.14159265358979323846);
+            outputMustBe("3.1");
+        }
+
+        TEST_METHOD(DoubleTwoDigits)
+        {
+            setValueTo<2>(3.14159265358979323846);
+            outputMustBe("3.14");
+        }
+        
+        TEST_METHOD(Integer)
+        {
+            setValueTo(314);
+            outputMustBe("314");
+        }
+
+        TEST_METHOD(Char)
+        {
+            setValueTo('A');
+            outputMustBe("65");
+        }
+
+        TEST_METHOD(Short)
+        {
+            setValueTo((short)314);
+            outputMustBe("314");
+        }
+
+        TEST_METHOD(Long)
+        {
+            setValueTo(314159265L);
+            outputMustBe("314159265");
+        }
+
+    private:
+
+        template<int DIGITS>
+        void setValueTo(double value)
+        {
+            StringBuilder sb(buffer, sizeof(buffer));
+            JsonValue jsonValue;
+            jsonValue.set<DIGITS>(value);
+            returnValue = jsonValue.printTo(sb);
+        }
+
+        template<typename T>
+        void setValueTo(T value)
+        {
+            StringBuilder sb(buffer, sizeof(buffer));
+            JsonValue jsonValue;
+            jsonValue = value;
+            returnValue = jsonValue.printTo(sb);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), returnValue);
+        }
+    };
+}

+ 88 - 88
JsonGeneratorTests/PrettyPrint_Array_Tests.cpp

@@ -1,91 +1,91 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonPrettyPrint.h"
-#include "StringBuilder.h"
-
-using namespace ArduinoJson::Internals;
-using namespace ArduinoJson::Generator;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(PrettyPrint_Array_Tests)
-    {
-        char buffer[1024];
-        size_t returnValue;
-
-    public:
-        
-        TEST_METHOD(EmptyArray)
-        {
-            whenInputIs("[]");
-            outputMustBe("[]");
-        }
-
-        TEST_METHOD(OneElement)
-        {
-            whenInputIs("[1]");
-            outputMustBe(
-                "[\r\n"
-                "  1\r\n"
-                "]");
-        }
-
-        TEST_METHOD(TwoElements)
-        {
-            whenInputIs("[1,2]");
-            outputMustBe(
-                "[\r\n"
-                "  1,\r\n"
-                "  2\r\n"
-                "]");
-        }
-
-        TEST_METHOD(EmptyNestedArrays)
-        {
-            whenInputIs("[[],[]]");
-            outputMustBe(
-                "[\r\n"
-                "  [],\r\n"
-                "  []\r\n"
-                "]");
-        }
-
-        TEST_METHOD(NestedArrays)
-        {
-            whenInputIs("[[1,2],[3,4]]");
-            outputMustBe(
-                "[\r\n"
-                "  [\r\n"
-                "    1,\r\n"
-                "    2\r\n"
-                "  ],\r\n"
-                "  [\r\n"
-                "    3,\r\n"
-                "    4\r\n"
-                "  ]\r\n"
-                "]");
-        }
-
-    private:
-
-        void whenInputIs(const char input[])
-        {
-            StringBuilder sb(buffer, sizeof(buffer));
-            IndentedPrint indentedPrint(sb);
-            JsonPrettyPrint decorator(indentedPrint);
-
-            returnValue = decorator.print(input);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonPrettyPrint.h"
+#include "StringBuilder.h"
+
+using namespace ArduinoJson::Internals;
+using namespace ArduinoJson::Generator;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(PrettyPrint_Array_Tests)
+    {
+        char buffer[1024];
+        size_t returnValue;
+
+    public:
+        
+        TEST_METHOD(EmptyArray)
+        {
+            whenInputIs("[]");
+            outputMustBe("[]");
+        }
+
+        TEST_METHOD(OneElement)
+        {
+            whenInputIs("[1]");
+            outputMustBe(
+                "[\r\n"
+                "  1\r\n"
+                "]");
+        }
+
+        TEST_METHOD(TwoElements)
+        {
+            whenInputIs("[1,2]");
+            outputMustBe(
+                "[\r\n"
+                "  1,\r\n"
+                "  2\r\n"
+                "]");
+        }
+
+        TEST_METHOD(EmptyNestedArrays)
+        {
+            whenInputIs("[[],[]]");
+            outputMustBe(
+                "[\r\n"
+                "  [],\r\n"
+                "  []\r\n"
+                "]");
+        }
+
+        TEST_METHOD(NestedArrays)
+        {
+            whenInputIs("[[1,2],[3,4]]");
+            outputMustBe(
+                "[\r\n"
+                "  [\r\n"
+                "    1,\r\n"
+                "    2\r\n"
+                "  ],\r\n"
+                "  [\r\n"
+                "    3,\r\n"
+                "    4\r\n"
+                "  ]\r\n"
+                "]");
+        }
+
+    private:
+
+        void whenInputIs(const char input[])
+        {
+            StringBuilder sb(buffer, sizeof(buffer));
+            IndentedPrint indentedPrint(sb);
+            JsonPrettyPrint decorator(indentedPrint);
+
+            returnValue = decorator.print(input);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), returnValue);
+        }
+    };
+}

+ 86 - 86
JsonGeneratorTests/PrettyPrint_Object_Tests.cpp

@@ -1,89 +1,89 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonPrettyPrint.h"
-#include "StringBuilder.h"
-
-using namespace ArduinoJson::Internals;
-using namespace ArduinoJson::Generator;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(PrettyPrint_Object_Tests)
-    {
-        char buffer[1024];
-        size_t returnValue;
-
-    public:
-
-        TEST_METHOD(EmptyObject)
-        {
-            whenInputIs("{}");
-            outputMustBe("{}");
-        }
-
-        TEST_METHOD(OneMember)
-        {
-            whenInputIs("{\"key\":\"value\"}");
-            outputMustBe(
-                "{\r\n"
-                "  \"key\": \"value\"\r\n"
-                "}");
-        }
-
-        TEST_METHOD(TwoMembers)
-        {
-            whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
-            outputMustBe(
-                "{\r\n"
-                "  \"key1\": \"value1\",\r\n"
-                "  \"key2\": \"value2\"\r\n"
-                "}");
-        }
-
-        TEST_METHOD(EmptyNestedObjects)
-        {
-            whenInputIs("{\"key1\":{},\"key2\":{}}");
-            outputMustBe(
-                "{\r\n"
-                "  \"key1\": {},\r\n"
-                "  \"key2\": {}\r\n"
-                "}");
-        }
-
-        TEST_METHOD(NestedObjects)
-        {
-            whenInputIs("{\"key1\":{\"a\":1},\"key2\":{\"b\":2}}");
-            outputMustBe(
-                "{\r\n"
-                "  \"key1\": {\r\n"
-                "    \"a\": 1\r\n"
-                "  },\r\n"
-                "  \"key2\": {\r\n"
-                "    \"b\": 2\r\n"
-                "  }\r\n"
-                "}");
-        }
-
-    private:
-
-        void whenInputIs(const char input[])
-        {
-            StringBuilder sb(buffer, sizeof(buffer));
-            IndentedPrint indentedPrint(sb);
-            JsonPrettyPrint decorator(indentedPrint);
-
-            returnValue = decorator.print(input);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonPrettyPrint.h"
+#include "StringBuilder.h"
+
+using namespace ArduinoJson::Internals;
+using namespace ArduinoJson::Generator;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(PrettyPrint_Object_Tests)
+    {
+        char buffer[1024];
+        size_t returnValue;
+
+    public:
+
+        TEST_METHOD(EmptyObject)
+        {
+            whenInputIs("{}");
+            outputMustBe("{}");
+        }
+
+        TEST_METHOD(OneMember)
+        {
+            whenInputIs("{\"key\":\"value\"}");
+            outputMustBe(
+                "{\r\n"
+                "  \"key\": \"value\"\r\n"
+                "}");
+        }
+
+        TEST_METHOD(TwoMembers)
+        {
+            whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
+            outputMustBe(
+                "{\r\n"
+                "  \"key1\": \"value1\",\r\n"
+                "  \"key2\": \"value2\"\r\n"
+                "}");
+        }
+
+        TEST_METHOD(EmptyNestedObjects)
+        {
+            whenInputIs("{\"key1\":{},\"key2\":{}}");
+            outputMustBe(
+                "{\r\n"
+                "  \"key1\": {},\r\n"
+                "  \"key2\": {}\r\n"
+                "}");
+        }
+
+        TEST_METHOD(NestedObjects)
+        {
+            whenInputIs("{\"key1\":{\"a\":1},\"key2\":{\"b\":2}}");
+            outputMustBe(
+                "{\r\n"
+                "  \"key1\": {\r\n"
+                "    \"a\": 1\r\n"
+                "  },\r\n"
+                "  \"key2\": {\r\n"
+                "    \"b\": 2\r\n"
+                "  }\r\n"
+                "}");
+        }
+
+    private:
+
+        void whenInputIs(const char input[])
+        {
+            StringBuilder sb(buffer, sizeof(buffer));
+            IndentedPrint indentedPrint(sb);
+            JsonPrettyPrint decorator(indentedPrint);
+
+            returnValue = decorator.print(input);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), returnValue);
+        }
+    };
+}

+ 73 - 73
JsonGeneratorTests/PrettyPrint_String_Tests.cpp

@@ -1,76 +1,76 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonPrettyPrint.h"
-#include "StringBuilder.h"
-
-using namespace ArduinoJson::Internals;
-using namespace ArduinoJson::Generator;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(PrettyPrint_String_Tests)
-    {
-        char buffer[1024];
-        size_t returnValue;
-
-    public:
-        
-        TEST_METHOD(EmptyString)
-        {
-            whenInputIs("");
-            outputMustBe("");
-        }
-
-        TEST_METHOD(TrickyCharacters)
-        {
-            whenInputIs ("\":\\\"',\"");
-            outputMustBe("\":\\\"',\"");
-        }
-
-        TEST_METHOD(OpeningCurlyBrace)
-        {
-            whenInputIs ("\"{\"");
-            outputMustBe("\"{\"");
-        }
-
-        TEST_METHOD(OpeningSquareBrace)
-        {
-            whenInputIs("\"[\"");
-            outputMustBe("\"[\"");
-        }
-
-        TEST_METHOD(ClosingCurlyBrace)
-        {
-            whenInputIs("\"}\"");
-            outputMustBe("\"}\"");
-        }
-
-        TEST_METHOD(ClosingSquareBrace)
-        {
-            whenInputIs("\"]\"");
-            outputMustBe("\"]\"");
-        }
-               
-    private:
-
-        void whenInputIs(const char input[])
-        {
-            StringBuilder sb(buffer, sizeof(buffer));
-            IndentedPrint indentedPrint(sb);
-            JsonPrettyPrint decorator(indentedPrint);
-
-            returnValue = decorator.print(input);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-            Assert::AreEqual(strlen(expected), returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonPrettyPrint.h"
+#include "StringBuilder.h"
+
+using namespace ArduinoJson::Internals;
+using namespace ArduinoJson::Generator;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(PrettyPrint_String_Tests)
+    {
+        char buffer[1024];
+        size_t returnValue;
+
+    public:
+        
+        TEST_METHOD(EmptyString)
+        {
+            whenInputIs("");
+            outputMustBe("");
+        }
+
+        TEST_METHOD(TrickyCharacters)
+        {
+            whenInputIs ("\":\\\"',\"");
+            outputMustBe("\":\\\"',\"");
+        }
+
+        TEST_METHOD(OpeningCurlyBrace)
+        {
+            whenInputIs ("\"{\"");
+            outputMustBe("\"{\"");
+        }
+
+        TEST_METHOD(OpeningSquareBrace)
+        {
+            whenInputIs("\"[\"");
+            outputMustBe("\"[\"");
+        }
+
+        TEST_METHOD(ClosingCurlyBrace)
+        {
+            whenInputIs("\"}\"");
+            outputMustBe("\"}\"");
+        }
+
+        TEST_METHOD(ClosingSquareBrace)
+        {
+            whenInputIs("\"]\"");
+            outputMustBe("\"]\"");
+        }
+               
+    private:
+
+        void whenInputIs(const char input[])
+        {
+            StringBuilder sb(buffer, sizeof(buffer));
+            IndentedPrint indentedPrint(sb);
+            JsonPrettyPrint decorator(indentedPrint);
+
+            returnValue = decorator.print(input);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+            Assert::AreEqual(strlen(expected), returnValue);
+        }
+    };
+}

+ 82 - 82
JsonGeneratorTests/StringBuilderTests.cpp

@@ -1,85 +1,85 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "StringBuilder.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Internals;
-
-namespace JsonGeneratorTests
-{
-    TEST_CLASS(StringBuilderTests)
-    {
-        char buffer[20];
-        Print* sb;
-        size_t returnValue;
-
-    public:
-        
-        TEST_METHOD_INITIALIZE(Initialize)
-        {
-            sb = new StringBuilder(buffer, sizeof(buffer));
-        }
-
-        TEST_METHOD(InitialState)
-        {
-            outputMustBe("");
-        }
-
-        TEST_METHOD(OverCapacity)
-        {
-            print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
-            resultMustBe(19);
-
-            print("ABC");
-            resultMustBe(0);
-
-            outputMustBe("ABCDEFGHIJKLMNOPQRS");
-        }
-
-        TEST_METHOD(EmptyString)
-        {
-            print("");
-            resultMustBe(0);
-            outputMustBe("");
-        }
-
-        TEST_METHOD(OneString)
-        {
-            print("ABCD");
-            resultMustBe(4);
-            outputMustBe("ABCD");
-        }
-
-        TEST_METHOD(TwoStrings)
-        {
-            print("ABCD");
-            resultMustBe(4);
-
-            print("EFGH");
-            resultMustBe(4);
-
-            outputMustBe("ABCDEFGH");
-        }
-
-    private:
-
-        void print(const char* value)
-        {
-            returnValue = sb->print(value);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, buffer);
-        }
-
-        void resultMustBe(size_t expected)
-        {
-            Assert::AreEqual(expected, returnValue);
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "StringBuilder.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Internals;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(StringBuilderTests)
+    {
+        char buffer[20];
+        Print* sb;
+        size_t returnValue;
+
+    public:
+        
+        TEST_METHOD_INITIALIZE(Initialize)
+        {
+            sb = new StringBuilder(buffer, sizeof(buffer));
+        }
+
+        TEST_METHOD(InitialState)
+        {
+            outputMustBe("");
+        }
+
+        TEST_METHOD(OverCapacity)
+        {
+            print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+            resultMustBe(19);
+
+            print("ABC");
+            resultMustBe(0);
+
+            outputMustBe("ABCDEFGHIJKLMNOPQRS");
+        }
+
+        TEST_METHOD(EmptyString)
+        {
+            print("");
+            resultMustBe(0);
+            outputMustBe("");
+        }
+
+        TEST_METHOD(OneString)
+        {
+            print("ABCD");
+            resultMustBe(4);
+            outputMustBe("ABCD");
+        }
+
+        TEST_METHOD(TwoStrings)
+        {
+            print("ABCD");
+            resultMustBe(4);
+
+            print("EFGH");
+            resultMustBe(4);
+
+            outputMustBe("ABCDEFGH");
+        }
+
+    private:
+
+        void print(const char* value)
+        {
+            returnValue = sb->print(value);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, buffer);
+        }
+
+        void resultMustBe(size_t expected)
+        {
+            Assert::AreEqual(expected, returnValue);
+        }
+    };
+}

+ 13 - 13
JsonParser.cpp

@@ -1,13 +1,13 @@
-/*
- * Arduino JSON library
- * Benoit Blanchon 2014 - MIT License
- */
-
-// This file is here to help the Arduino IDE find the .cpp files
-
-#include "JsonParser/JsonArray.cpp"
-#include "JsonParser/JsonObject.cpp"
-#include "JsonParser/JsonParserBase.cpp"
-#include "JsonParser/JsonValue.cpp"
-#include "JsonParser/JsonToken.cpp"
-#include "JsonParser/jsmn.cpp"
+/*
+ * Arduino JSON library
+ * Benoit Blanchon 2014 - MIT License
+ */
+
+// This file is here to help the Arduino IDE find the .cpp files
+
+#include "JsonParser/JsonArray.cpp"
+#include "JsonParser/JsonObject.cpp"
+#include "JsonParser/JsonParserBase.cpp"
+#include "JsonParser/JsonValue.cpp"
+#include "JsonParser/JsonToken.cpp"
+#include "JsonParser/jsmn.cpp"

+ 6 - 6
JsonParser.h

@@ -1,6 +1,6 @@
-/*
-* malloc-free JSON parser for Arduino
-* Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonParser/JsonParser.h"
+/*
+* malloc-free JSON parser for Arduino
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#include "JsonParser/JsonParser.h"

+ 10 - 10
JsonParser/JsonArray.cpp

@@ -2,13 +2,13 @@
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
 */
-
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-using namespace ArduinoJson::Parser;
-
-DEPRECATED JsonObject JsonArray::getHashTable(int index)
-{
-    return operator[](index);
-}
+
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace ArduinoJson::Parser;
+
+DEPRECATED JsonObject JsonArray::getHashTable(int index)
+{
+    return operator[](index);
+}

+ 82 - 82
JsonParser/JsonArray.h

@@ -2,102 +2,102 @@
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
  */
-
-#pragma once
-
-#include "JsonValue.h"
-#include "JsonArrayIterator.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        class JsonObject;
+
+#pragma once
+
+#include "JsonValue.h"
+#include "JsonArrayIterator.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        class JsonObject;
                 
         // A JSON array
-        class JsonArray : JsonValue
-        {          
-        public:
-
+        class JsonArray : JsonValue
+        {          
+        public:
+
             // Create an invalid array
-            JsonArray() 
-            {            
-            }
+            JsonArray() 
+            {            
+            }
 
             // Convert a JsonValue into a JsonArray
-            JsonArray(JsonValue value)
-                : JsonValue(value)
-            {
-            }
+            JsonArray(JsonValue value)
+                : JsonValue(value)
+            {
+            }
 
             // Tell if the array is valid
-            bool success()
-            {
-                return isArray();
-            }
+            bool success()
+            {
+                return isArray();
+            }
 
             // Get the JsonValue at specified index
-            JsonValue operator[](int index)
-            {
-                return JsonValue::operator[](index);
-            }
+            JsonValue operator[](int index)
+            {
+                return JsonValue::operator[](index);
+            }
 
             // Get the size of the array
-            int size()
-            {
-                return isArray() ? childrenCount() : 0;
-            }
+            int size()
+            {
+                return isArray() ? childrenCount() : 0;
+            }
 
             // Get an iterator pointing to the beginning of the array
-            JsonArrayIterator begin()
-            {
-                return isArray() ? firstChild() : null();
-            }
+            JsonArrayIterator begin()
+            {
+                return isArray() ? firstChild() : null();
+            }
 
             // Gets an iterator pointing to the end of the array
-            JsonArrayIterator end()
-            {
-                return isArray() ? nextSibling() : null();
-            }
+            JsonArrayIterator end()
+            {
+                return isArray() ? nextSibling() : null();
+            }
 
             // Obsolete: Use size() instead
-            DEPRECATED int getLength()
-            {
-                return size();
-            }
-                   
-            // Obsolete: Use operator[] instead
-            DEPRECATED JsonArray getArray(int index)
-            {
-                return operator[](index);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED bool getBool(int index)
-            {
-                return operator[](index);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED double getDouble(int index)
-            {
-                return operator[](index);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED JsonObject getHashTable(int index);
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED long getLong(int index)
-            {
-                return operator[](index);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED char* getString(int index)
-            {
-                return operator[](index);
-            }
-        };
-    }
-}
+            DEPRECATED int getLength()
+            {
+                return size();
+            }
+                   
+            // Obsolete: Use operator[] instead
+            DEPRECATED JsonArray getArray(int index)
+            {
+                return operator[](index);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED bool getBool(int index)
+            {
+                return operator[](index);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED double getDouble(int index)
+            {
+                return operator[](index);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED JsonObject getHashTable(int index);
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED long getLong(int index)
+            {
+                return operator[](index);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED char* getString(int index)
+            {
+                return operator[](index);
+            }
+        };
+    }
+}

+ 42 - 42
JsonParser/JsonArrayIterator.h

@@ -2,45 +2,45 @@
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
 */
-
-#pragma once
-
-#include "JsonValue.h"
-#include "JsonToken.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // An iterator for JsonArray
-        class JsonArrayIterator : JsonToken
-        {
-        public:
-
-            // Create an iterator pointing at the specified JsonToken
-            JsonArrayIterator(JsonToken token)
-                : JsonToken(token)
-            {
-
-            }
-
-            // Move iterator forward
-            void operator++()
-            {
-                *this = JsonArrayIterator(nextSibling());
-            }
-
-            // Get the value pointed by the iterator
-            JsonValue operator*() const
-            {
-                return JsonValue(*this);
-            }
-
-            // Test iterator equality
-            bool operator!= (const JsonArrayIterator& other) const
-            {
-                return JsonToken::operator!=(other);
-            }
-        };
-    }
-}
+
+#pragma once
+
+#include "JsonValue.h"
+#include "JsonToken.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // An iterator for JsonArray
+        class JsonArrayIterator : JsonToken
+        {
+        public:
+
+            // Create an iterator pointing at the specified JsonToken
+            JsonArrayIterator(JsonToken token)
+                : JsonToken(token)
+            {
+
+            }
+
+            // Move iterator forward
+            void operator++()
+            {
+                *this = JsonArrayIterator(nextSibling());
+            }
+
+            // Get the value pointed by the iterator
+            JsonValue operator*() const
+            {
+                return JsonValue(*this);
+            }
+
+            // Test iterator equality
+            bool operator!= (const JsonArrayIterator& other) const
+            {
+                return JsonToken::operator!=(other);
+            }
+        };
+    }
+}

+ 12 - 12
JsonParser/JsonObject.cpp

@@ -1,15 +1,15 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonArray.h"
-#include "JsonObject.h"
-#include "JsonValue.h"
-
-using namespace ArduinoJson::Parser;
-
-DEPRECATED JsonArray JsonObject::getArray(const char* key)
-{
-    return operator[](key);
-}
+*/
+
+#include "JsonArray.h"
+#include "JsonObject.h"
+#include "JsonValue.h"
+
+using namespace ArduinoJson::Parser;
+
+DEPRECATED JsonArray JsonObject::getArray(const char* key)
+{
+    return operator[](key);
+}

+ 98 - 98
JsonParser/JsonObject.h

@@ -2,101 +2,101 @@
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
 */
-
-#pragma once
-
-#include "JsonValue.h"
-#include "JsonObjectIterator.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        class JsonArray;
-
-        // A JSON Object (ie hash-table/dictionary)
-        class JsonObject : JsonValue
-        {
-        public:
-
-            // Create an invalid JsonObject
-            JsonObject()
-            {
-
-            }
-
-            // Convert a JsonValue into a JsonObject
-            JsonObject(JsonValue value)
-                : JsonValue(value)
-            {
-
-            }
-
-            // Tell if the object is valid
-            bool success()
-            {
-                return isObject();
-            }           
-
-            // Get the value associated with the specified key.
-            JsonValue operator[](const char* key)
-            {
-                return JsonValue::operator[](key);
-            }
-
-            // Tell if the specified key exists in the object.
-            bool containsKey(const char* key)
-            {
-                return operator[](key).success();
-            }
-
-            // Get an iterator pointing at the beginning of the object
-            JsonObjectIterator begin()
-            {
-                return isObject() ? firstChild() : null();
-            }
-
-            // Get an iterator pointing at the end of the object
-            JsonObjectIterator end()
-            {
-                return isObject() ? nextSibling() : null();
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED JsonArray getArray(const char* key);
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED bool getBool(const char* key)
-            {
-                return operator[](key);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED double getDouble(const char* key)
-            {
-                return operator[](key);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED JsonObject getHashTable(const char* key)
-            {
-                return operator[](key);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED long getLong(const char* key)
-            {
-                return operator[](key);
-            }
-
-            // Obsolete: Use operator[] instead
-            DEPRECATED char* getString(const char* key)
-            {
-                return operator[](key);
-            }
-        };
-
-        // Obsolete: Use JsonObject instead
-        DEPRECATED typedef JsonObject JsonHashTable;
-    }
-}
+
+#pragma once
+
+#include "JsonValue.h"
+#include "JsonObjectIterator.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        class JsonArray;
+
+        // A JSON Object (ie hash-table/dictionary)
+        class JsonObject : JsonValue
+        {
+        public:
+
+            // Create an invalid JsonObject
+            JsonObject()
+            {
+
+            }
+
+            // Convert a JsonValue into a JsonObject
+            JsonObject(JsonValue value)
+                : JsonValue(value)
+            {
+
+            }
+
+            // Tell if the object is valid
+            bool success()
+            {
+                return isObject();
+            }           
+
+            // Get the value associated with the specified key.
+            JsonValue operator[](const char* key)
+            {
+                return JsonValue::operator[](key);
+            }
+
+            // Tell if the specified key exists in the object.
+            bool containsKey(const char* key)
+            {
+                return operator[](key).success();
+            }
+
+            // Get an iterator pointing at the beginning of the object
+            JsonObjectIterator begin()
+            {
+                return isObject() ? firstChild() : null();
+            }
+
+            // Get an iterator pointing at the end of the object
+            JsonObjectIterator end()
+            {
+                return isObject() ? nextSibling() : null();
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED JsonArray getArray(const char* key);
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED bool getBool(const char* key)
+            {
+                return operator[](key);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED double getDouble(const char* key)
+            {
+                return operator[](key);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED JsonObject getHashTable(const char* key)
+            {
+                return operator[](key);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED long getLong(const char* key)
+            {
+                return operator[](key);
+            }
+
+            // Obsolete: Use operator[] instead
+            DEPRECATED char* getString(const char* key)
+            {
+                return operator[](key);
+            }
+        };
+
+        // Obsolete: Use JsonObject instead
+        DEPRECATED typedef JsonObject JsonHashTable;
+    }
+}

+ 54 - 54
JsonParser/JsonObjectIterator.h

@@ -2,57 +2,57 @@
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
 */
-
-#pragma once
-
-#include "JsonValue.h"
-#include "JsonPair.h"
-#include "JsonToken.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // An iterator for JsonObject
-        class JsonObjectIterator : JsonToken
-        {
-        public:
-
-            // Create an iterator pointing at the specified token
-            JsonObjectIterator(JsonToken token)
-                : JsonToken(token)
-            {
-            }
-
-            // Move to the next JsonPair
-            void operator++()
-            {
-                *this = JsonObjectIterator(nextSibling().nextSibling());
-            }
-
-            // Get the JsonPair pointed by the iterator
-            JsonPair operator*() const
-            {
-                return JsonPair(*this);
-            }
-
-            // Test iterator equality
-            bool operator!= (const JsonObjectIterator& other) const
-            {
-                return JsonToken::operator!=(other);
-            }
-
-            // Get the key of the JsonPair pointed by the iterator
-            const char* key() const
-            {
-                return operator*().key();
-            }
-
-            // Get the key of the JsonPair pointed by the iterator
-            JsonValue value() const
-            {
-                return operator*().value();
-            }
-        };
-    }
-}
+
+#pragma once
+
+#include "JsonValue.h"
+#include "JsonPair.h"
+#include "JsonToken.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // An iterator for JsonObject
+        class JsonObjectIterator : JsonToken
+        {
+        public:
+
+            // Create an iterator pointing at the specified token
+            JsonObjectIterator(JsonToken token)
+                : JsonToken(token)
+            {
+            }
+
+            // Move to the next JsonPair
+            void operator++()
+            {
+                *this = JsonObjectIterator(nextSibling().nextSibling());
+            }
+
+            // Get the JsonPair pointed by the iterator
+            JsonPair operator*() const
+            {
+                return JsonPair(*this);
+            }
+
+            // Test iterator equality
+            bool operator!= (const JsonObjectIterator& other) const
+            {
+                return JsonToken::operator!=(other);
+            }
+
+            // Get the key of the JsonPair pointed by the iterator
+            const char* key() const
+            {
+                return operator*().key();
+            }
+
+            // Get the key of the JsonPair pointed by the iterator
+            JsonValue value() const
+            {
+                return operator*().value();
+            }
+        };
+    }
+}

+ 34 - 34
JsonParser/JsonPair.h

@@ -1,37 +1,37 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "JsonValue.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // A JSON key-value pair, as a part of a JSON object
-        class JsonPair : JsonToken
-        {
-        public:
-            // Convert a JsonToken to a JsonPair
-            JsonPair(JsonToken token)
-                : JsonToken(token)
-            {
-            }
-
-            // Get the key
-            const char* key()
-            {
-                return getText();
-            }
-
-            // Get the value
-            JsonValue value()
-            {
-                return nextSibling();
-            }
-        };
-    }
-}
+*/
+
+#pragma once
+
+#include "JsonValue.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // A JSON key-value pair, as a part of a JSON object
+        class JsonPair : JsonToken
+        {
+        public:
+            // Convert a JsonToken to a JsonPair
+            JsonPair(JsonToken token)
+                : JsonToken(token)
+            {
+            }
+
+            // Get the key
+            const char* key()
+            {
+                return getText();
+            }
+
+            // Get the value
+            JsonValue value()
+            {
+                return nextSibling();
+            }
+        };
+    }
+}

+ 32 - 32
JsonParser/JsonParser.h

@@ -1,35 +1,35 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "JsonParserBase.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // The JSON parser.
-        //
-        // You need to specifiy the number of token to be allocated for that parser.
-        //
-        // CAUTION: JsonArray, JsonObject and JsonValue contain pointers to tokens of the
-        // JsonParser, so they need the JsonParser to be in memory to work.
-        // As a result, you must not create JsonArray, JsonObject or JsonValue that have a
-        // longer life that the JsonParser.
-        template <int MAX_TOKENS>
-        class JsonParser : public JsonParserBase
-        {
-        public:
-            JsonParser()
-                : JsonParserBase(tokens, MAX_TOKENS)
-            {
-            }
-
-        private:
-            jsmntok_t tokens[MAX_TOKENS];
-        };
-    }
-}
+*/
+
+#pragma once
+
+#include "JsonParserBase.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // The JSON parser.
+        //
+        // You need to specifiy the number of token to be allocated for that parser.
+        //
+        // CAUTION: JsonArray, JsonObject and JsonValue contain pointers to tokens of the
+        // JsonParser, so they need the JsonParser to be in memory to work.
+        // As a result, you must not create JsonArray, JsonObject or JsonValue that have a
+        // longer life that the JsonParser.
+        template <int MAX_TOKENS>
+        class JsonParser : public JsonParserBase
+        {
+        public:
+            JsonParser()
+                : JsonParserBase(tokens, MAX_TOKENS)
+            {
+            }
+
+        private:
+            jsmntok_t tokens[MAX_TOKENS];
+        };
+    }
+}

+ 17 - 17
JsonParser/JsonParserBase.cpp

@@ -1,20 +1,20 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonParserBase.h"
-#include "JsonToken.h"
-
-using namespace ArduinoJson::Parser;
-
-JsonValue JsonParserBase::parse(char* json)
-{
-    jsmn_parser parser;
-    jsmn_init(&parser);
-
-    if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens))
-        return JsonToken::null();
-
-    return JsonToken(json, tokens);
-}
+*/
+
+#include "JsonParserBase.h"
+#include "JsonToken.h"
+
+using namespace ArduinoJson::Parser;
+
+JsonValue JsonParserBase::parse(char* json)
+{
+    jsmn_parser parser;
+    jsmn_init(&parser);
+
+    if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens))
+        return JsonToken::null();
+
+    return JsonToken(json, tokens);
+}

+ 46 - 46
JsonParser/JsonParserBase.h

@@ -1,49 +1,49 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "JsonArray.h"
-#include "JsonObject.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // Base class for the JSON parser, in case you want to provide your own buffer
-        class JsonParserBase
-        {
-        public:
-
-            // Create a JSON parser using the provided buffer
-            JsonParserBase(jsmntok_t* tokens, int maxTokens)
-                : tokens(tokens), maxTokens(maxTokens)
-            {
-            }
-
-            // Parse the JSON string and return a array
-            //
-            // The content of the string may be altered to add '\0' at the
-            // end of string tokens            
-            JsonValue parse(char* json);
-
-            // Obsolete: use parse() instead
-            DEPRECATED JsonArray parseArray(char* json)
-            {
-                return parse(json);
-            }
-
-            // Obsolete: use parse() instead
-            DEPRECATED JsonObject parseHashTable(char* json)
-            {
-                return parse(json);
-            }
-
-        private:
-            jsmntok_t* tokens;
-            int maxTokens;
-        };
-    }
-}
+*/
+
+#pragma once
+
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // Base class for the JSON parser, in case you want to provide your own buffer
+        class JsonParserBase
+        {
+        public:
+
+            // Create a JSON parser using the provided buffer
+            JsonParserBase(jsmntok_t* tokens, int maxTokens)
+                : tokens(tokens), maxTokens(maxTokens)
+            {
+            }
+
+            // Parse the JSON string and return a array
+            //
+            // The content of the string may be altered to add '\0' at the
+            // end of string tokens            
+            JsonValue parse(char* json);
+
+            // Obsolete: use parse() instead
+            DEPRECATED JsonArray parseArray(char* json)
+            {
+                return parse(json);
+            }
+
+            // Obsolete: use parse() instead
+            DEPRECATED JsonObject parseHashTable(char* json)
+            {
+                return parse(json);
+            }
+
+        private:
+            jsmntok_t* tokens;
+            int maxTokens;
+        };
+    }
+}

+ 68 - 68
JsonParser/JsonToken.cpp

@@ -1,71 +1,71 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "JsonToken.h"
-
-using namespace ArduinoJson::Parser;
-
-char* JsonToken::getText()
-{
-    char* s = json + token->start;
-    json[token->end] = 0;
-
-    unescapeString(s);
-
-    return s;
-}
-
-inline void JsonToken::unescapeString(char* s)
-{
-    char* readPtr = s;
-    char* writePtr = s;
-    char c;
-
-    do
-    {
-        c = *readPtr++;
-
-        if (c == '\\')
-        {
-            c = unescapeChar(*readPtr++);
-        }
-
-        *writePtr++ = c;
-
-    } while (c != 0);
-}
-
-inline char JsonToken::unescapeChar(char c)
-{
-    // Optimized for code size on a 8-bit AVR
-
-    const char* p = "b\bf\fn\nr\rt\t";
-
-    while (true)
-    {
-        if (p[0] == 0) return c;
-        if (p[0] == c) return p[1];
-        p += 2;
-    }
-}
-
-JsonToken JsonToken::nextSibling() const
-{
-    // start with current token
-    jsmntok_t* t = token;
-
-    // count the number of token to skip
-    int yetToVisit = 1;
-    
-    // skip all nested tokens
-    while (yetToVisit)
-    {
-        yetToVisit += t->size - 1;
-        t++;
-    }
-
-    // build a JsonToken at the new location
-    return JsonToken(json, t);
-}
+*/
+
+#include "JsonToken.h"
+
+using namespace ArduinoJson::Parser;
+
+char* JsonToken::getText()
+{
+    char* s = json + token->start;
+    json[token->end] = 0;
+
+    unescapeString(s);
+
+    return s;
+}
+
+inline void JsonToken::unescapeString(char* s)
+{
+    char* readPtr = s;
+    char* writePtr = s;
+    char c;
+
+    do
+    {
+        c = *readPtr++;
+
+        if (c == '\\')
+        {
+            c = unescapeChar(*readPtr++);
+        }
+
+        *writePtr++ = c;
+
+    } while (c != 0);
+}
+
+inline char JsonToken::unescapeChar(char c)
+{
+    // Optimized for code size on a 8-bit AVR
+
+    const char* p = "b\bf\fn\nr\rt\t";
+
+    while (true)
+    {
+        if (p[0] == 0) return c;
+        if (p[0] == c) return p[1];
+        p += 2;
+    }
+}
+
+JsonToken JsonToken::nextSibling() const
+{
+    // start with current token
+    jsmntok_t* t = token;
+
+    // count the number of token to skip
+    int yetToVisit = 1;
+    
+    // skip all nested tokens
+    while (yetToVisit)
+    {
+        yetToVisit += t->size - 1;
+        t++;
+    }
+
+    // build a JsonToken at the new location
+    return JsonToken(json, t);
+}

+ 96 - 96
JsonParser/JsonToken.h

@@ -1,99 +1,99 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#pragma once
-
-#include "jsmn.h"
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // A pointer to a JSON token
-        class JsonToken
-        {
-        public:
-
-            // Create a "null" pointer
-            JsonToken()
-                : token(0)
-            {
-            }
-
-            // Create a pointer to the specified JSON token
-            JsonToken(char* json, jsmntok_t* token)
-                : json(json), token(token)
-            {
-            }
-
-            // Get content of the JSON token
-            char* getText();
-
-            // Get the number of children tokens
-            int childrenCount()
-            {
-                return token->size;
-            }
-
-            // Get a pointer to the first child of the current token
-            JsonToken firstChild() const
-            {
-                return JsonToken(json, token + 1);
-            }
-
-            // Get a pointer to the next sibling token (ie skiping the children tokens)
-            JsonToken nextSibling() const;
-
-            // Test equality
-            bool operator!=(const JsonToken& other) const
-            {
-                return token != other.token;
-            }
-
-            // Tell if the pointer is "null"
-            bool isValid()
-            {
-                return token != 0;
-            }
-
-            // Tell if the JSON token is a JSON object
-            bool isObject()
-            {
-                return token != 0 && token->type == JSMN_OBJECT;
-            }
-
-            // Tell if the JSON token is a JSON array
-            bool isArray()
-            {
-                return token != 0 && token->type == JSMN_ARRAY;
-            }
-
-            // Tell if the JSON token is a primitive
-            bool isPrimitive()
-            {
-                return token != 0 && token->type == JSMN_PRIMITIVE;
-            }
-
-            // Tell if the JSON token is a string
-            bool isString()
-            {
-                return token != 0 && token->type == JSMN_STRING;
-            }
-
-            // Explicit wait to create a "null" JsonToken
-            static JsonToken null()
-            {
-                return JsonToken();
-            }
-
-        private:
-            char* json;
-            jsmntok_t* token;
-            
-            static char unescapeChar(char c);
-            static void unescapeString(char* s);
-        };
-    }
-}
+*/
+
+#pragma once
+
+#include "jsmn.h"
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // A pointer to a JSON token
+        class JsonToken
+        {
+        public:
+
+            // Create a "null" pointer
+            JsonToken()
+                : token(0)
+            {
+            }
+
+            // Create a pointer to the specified JSON token
+            JsonToken(char* json, jsmntok_t* token)
+                : json(json), token(token)
+            {
+            }
+
+            // Get content of the JSON token
+            char* getText();
+
+            // Get the number of children tokens
+            int childrenCount()
+            {
+                return token->size;
+            }
+
+            // Get a pointer to the first child of the current token
+            JsonToken firstChild() const
+            {
+                return JsonToken(json, token + 1);
+            }
+
+            // Get a pointer to the next sibling token (ie skiping the children tokens)
+            JsonToken nextSibling() const;
+
+            // Test equality
+            bool operator!=(const JsonToken& other) const
+            {
+                return token != other.token;
+            }
+
+            // Tell if the pointer is "null"
+            bool isValid()
+            {
+                return token != 0;
+            }
+
+            // Tell if the JSON token is a JSON object
+            bool isObject()
+            {
+                return token != 0 && token->type == JSMN_OBJECT;
+            }
+
+            // Tell if the JSON token is a JSON array
+            bool isArray()
+            {
+                return token != 0 && token->type == JSMN_ARRAY;
+            }
+
+            // Tell if the JSON token is a primitive
+            bool isPrimitive()
+            {
+                return token != 0 && token->type == JSMN_PRIMITIVE;
+            }
+
+            // Tell if the JSON token is a string
+            bool isString()
+            {
+                return token != 0 && token->type == JSMN_STRING;
+            }
+
+            // Explicit wait to create a "null" JsonToken
+            static JsonToken null()
+            {
+                return JsonToken();
+            }
+
+        private:
+            char* json;
+            jsmntok_t* token;
+            
+            static char unescapeChar(char c);
+            static void unescapeString(char* s);
+        };
+    }
+}

+ 107 - 107
JsonParser/JsonValue.cpp

@@ -1,110 +1,110 @@
 /*
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
- */
-
-#include <stdlib.h> // for strtol, strtod
-#include <string.h> // for strcmp()
-#include "JsonArray.h"
-#include "JsonObject.h"
-#include "JsonValue.h"
-
-using namespace ArduinoJson::Parser;
-
-// Convert the JsonValue to a bool.
-// Returns false if the JsonValue is not a primitve.
-JsonValue::operator bool()
-{
-    if (!isPrimitive()) return 0;
-
-    char *text = getText();
-
-    // "true"
-    if (text[0] == 't') return true;
-
-    // "false"
-    if (text[0] == 'f') return false;
-
-    // "null"
-    if (text[0] == 'n') return false;
-
-    // number
-    return strtol(text, 0, 0) != 0;
-}
-
-// Convert the JsonValue to a floating point value.
-// Returns false if the JsonValue is not a number.
-JsonValue::operator double()
-{
-    return isPrimitive() ? strtod(getText(), 0) : 0;
-}
-
-// Convert the JsonValue to a floating point value.
-// Returns false if the JsonValue is not a number.
-JsonValue::operator long()
-{
-    return isPrimitive() ? strtol(getText(), 0, 0) : 0;
-}
-
-// Convert the JsonValue to a string.
-// Returns 0 if the JsonValue is not a string.
-JsonValue::operator char*()
-{
-    return isString() || isPrimitive() ? getText() : 0;
-}
-
-// Get the nested value at the specified index.            
-// Returns an invalid JsonValue if the current value is not an array.
-JsonValue JsonValue::operator[](int index)
-{
-    // sanity check
-    if (index < 0 || !isArray() || index >= childrenCount())
-        return null();
-
-    // skip first token, it's the whole object
-    JsonToken runningToken = firstChild();
-
-    // skip all tokens before the specified index
-    for (int i = 0; i < index; i++)
-    {
-        // move forward: current + nested tokens
-        runningToken = runningToken.nextSibling();
-    }
-
-    return runningToken;
-}
-
-// Get the nested value matching the specified index.            
-// Returns an invalid JsonValue if the current value is not an object.
-JsonValue JsonValue::operator[](const char* desiredKey)
-{
-    // sanity check
-    if (desiredKey == 0 || !isObject())
-        return null();
-
-    // skip first token, it's the whole object
-    JsonToken runningToken = firstChild();
-
-    // scan each keys
-    for (int i = 0; i < childrenCount() / 2; i++)
-    {
-        // get 'key' token string
-        char* key = runningToken.getText();
-
-        // move to the 'value' token
-        runningToken = runningToken.nextSibling();
-
-        // compare with desired name
-        if (strcmp(desiredKey, key) == 0)
-        {
-            // return the value token that follows the key token
-            return runningToken;
-        }
-
-        // skip nested tokens
-        runningToken = runningToken.nextSibling();
-    }
-
-    // nothing found, return NULL
-    return null();
-}
+ */
+
+#include <stdlib.h> // for strtol, strtod
+#include <string.h> // for strcmp()
+#include "JsonArray.h"
+#include "JsonObject.h"
+#include "JsonValue.h"
+
+using namespace ArduinoJson::Parser;
+
+// Convert the JsonValue to a bool.
+// Returns false if the JsonValue is not a primitve.
+JsonValue::operator bool()
+{
+    if (!isPrimitive()) return 0;
+
+    char *text = getText();
+
+    // "true"
+    if (text[0] == 't') return true;
+
+    // "false"
+    if (text[0] == 'f') return false;
+
+    // "null"
+    if (text[0] == 'n') return false;
+
+    // number
+    return strtol(text, 0, 0) != 0;
+}
+
+// Convert the JsonValue to a floating point value.
+// Returns false if the JsonValue is not a number.
+JsonValue::operator double()
+{
+    return isPrimitive() ? strtod(getText(), 0) : 0;
+}
+
+// Convert the JsonValue to a floating point value.
+// Returns false if the JsonValue is not a number.
+JsonValue::operator long()
+{
+    return isPrimitive() ? strtol(getText(), 0, 0) : 0;
+}
+
+// Convert the JsonValue to a string.
+// Returns 0 if the JsonValue is not a string.
+JsonValue::operator char*()
+{
+    return isString() || isPrimitive() ? getText() : 0;
+}
+
+// Get the nested value at the specified index.            
+// Returns an invalid JsonValue if the current value is not an array.
+JsonValue JsonValue::operator[](int index)
+{
+    // sanity check
+    if (index < 0 || !isArray() || index >= childrenCount())
+        return null();
+
+    // skip first token, it's the whole object
+    JsonToken runningToken = firstChild();
+
+    // skip all tokens before the specified index
+    for (int i = 0; i < index; i++)
+    {
+        // move forward: current + nested tokens
+        runningToken = runningToken.nextSibling();
+    }
+
+    return runningToken;
+}
+
+// Get the nested value matching the specified index.            
+// Returns an invalid JsonValue if the current value is not an object.
+JsonValue JsonValue::operator[](const char* desiredKey)
+{
+    // sanity check
+    if (desiredKey == 0 || !isObject())
+        return null();
+
+    // skip first token, it's the whole object
+    JsonToken runningToken = firstChild();
+
+    // scan each keys
+    for (int i = 0; i < childrenCount() / 2; i++)
+    {
+        // get 'key' token string
+        char* key = runningToken.getText();
+
+        // move to the 'value' token
+        runningToken = runningToken.nextSibling();
+
+        // compare with desired name
+        if (strcmp(desiredKey, key) == 0)
+        {
+            // return the value token that follows the key token
+            return runningToken;
+        }
+
+        // skip nested tokens
+        runningToken = runningToken.nextSibling();
+    }
+
+    // nothing found, return NULL
+    return null();
+}

+ 67 - 67
JsonParser/JsonValue.h

@@ -1,72 +1,72 @@
 /*
  * Arduino JSON library
  * Benoit Blanchon 2014 - MIT License
- */
-
-#pragma once
-
-#include "JsonToken.h"
-
-#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING
-#ifdef __GNUC__
-#define DEPRECATED __attribute__((deprecated))
-#elif defined(_MSC_VER)
-#define DEPRECATED __declspec(deprecated)
-#endif
+ */
+
+#pragma once
+
+#include "JsonToken.h"
+
+#ifndef ARDUINO_JSON_NO_DEPRECATION_WARNING
+#ifdef __GNUC__
+#define DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER)
+#define DEPRECATED __declspec(deprecated)
+#endif
 #else
 #define DEPRECATED
-#endif
-
-namespace ArduinoJson
-{
-    namespace Parser
-    {
-        // A JSON value
-        // Can be converted to string, double, bool, array or object.
-        class JsonValue : protected JsonToken
-        {
-        public:
-
-            // Create a invalid value
-            JsonValue()
-            {
-            }
-
-            // Convert a JsonToken to a JsonValue
-            JsonValue(JsonToken token)
-                : JsonToken(token)
-            {
-            }
-
-            // Tell is the JsonValue is valid
-            bool success()
-            {
-                return isValid();
-            }
-
-            // Convert the JsonValue to a bool.
-            // Returns false if the JsonValue is not a primitve.
-            operator bool();
-
-            // Convert the JsonValue to a floating point value.
-            // Returns false if the JsonValue is not a number.
-            operator double();
-
-            // Convert the JsonValue to a long integer.
-            // Returns 0 if the JsonValue is not a number.
-            operator long();
-
-            // Convert the JsonValue to a string.
-            // Returns 0 if the JsonValue is not a string.
-            operator char*();            
-            
-            // Get the nested value at the specified index.            
-            // Returns an invalid JsonValue if the current value is not an array.
-            JsonValue operator[](int index);
-
-            // Get the nested value matching the specified index.            
-            // Returns an invalid JsonValue if the current value is not an object.
-            JsonValue operator[](const char* key);
-        };
-    }
-}
+#endif
+
+namespace ArduinoJson
+{
+    namespace Parser
+    {
+        // A JSON value
+        // Can be converted to string, double, bool, array or object.
+        class JsonValue : protected JsonToken
+        {
+        public:
+
+            // Create a invalid value
+            JsonValue()
+            {
+            }
+
+            // Convert a JsonToken to a JsonValue
+            JsonValue(JsonToken token)
+                : JsonToken(token)
+            {
+            }
+
+            // Tell is the JsonValue is valid
+            bool success()
+            {
+                return isValid();
+            }
+
+            // Convert the JsonValue to a bool.
+            // Returns false if the JsonValue is not a primitve.
+            operator bool();
+
+            // Convert the JsonValue to a floating point value.
+            // Returns false if the JsonValue is not a number.
+            operator double();
+
+            // Convert the JsonValue to a long integer.
+            // Returns 0 if the JsonValue is not a number.
+            operator long();
+
+            // Convert the JsonValue to a string.
+            // Returns 0 if the JsonValue is not a string.
+            operator char*();            
+            
+            // Get the nested value at the specified index.            
+            // Returns an invalid JsonValue if the current value is not an array.
+            JsonValue operator[](int index);
+
+            // Get the nested value matching the specified index.            
+            // Returns an invalid JsonValue if the current value is not an object.
+            JsonValue operator[](const char* key);
+        };
+    }
+}

+ 241 - 241
JsonParserTests/GbathreeBug.cpp

@@ -1,244 +1,244 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-#include <string>
-
-using namespace std;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace ArduinoJsonParserTests
-{
-	TEST_CLASS(GbathreeBug)
-	{
-		char json[1024];
-		JsonParser<200> parser;
-		JsonHashTable root;
-		
-
-	public:
-
-		TEST_METHOD_INITIALIZE(Initialize)
-		{
-			// BUG described here:
-			// http://forum.arduino.cc/index.php?topic=172578.msg1608219#msg1608219
-			strcpy(json, "{ \"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}");
-			root = parser.parseHashTable(json);
-		}
-
-		TEST_METHOD(Root)
-		{
-			Assert::IsTrue(root.success());
-		}
-
-		TEST_METHOD(ProtocolName)
-		{
-			string protocol_name = root.getString("protocol_name");
-			Assert::AreEqual(string("fluorescence"), protocol_name);
-		}
-
-		TEST_METHOD(Repeats)
-		{
-			Assert::AreEqual(1L, root.getLong("repeats"));
-		}
-
-		TEST_METHOD(Wait)
-		{
-			Assert::AreEqual(0L, root.getLong("wait"));
-		}
-
-		TEST_METHOD(Measurements)
-		{
-			Assert::AreEqual(3L, root.getLong("measurements"));
-		}
-
-		TEST_METHOD(Meas2_Light)
-		{
-			Assert::AreEqual(15L, root.getLong("meas2_light"));
-		}
-
-		TEST_METHOD(Meas1_Baseline)
-		{
-			Assert::AreEqual(0L, root.getLong("meas1_baseline"));
-		}
-
-		TEST_METHOD(Act_Light)
-		{
-			Assert::AreEqual(20L, root.getLong("act_light"));
-		}
-
-		TEST_METHOD(Pulsesize)
-		{
-			Assert::AreEqual(25L, root.getLong("pulsesize"));
-		}
-
-		TEST_METHOD(Pulsedistance)
-		{
-			Assert::AreEqual(10000L, root.getLong("pulsedistance"));
-		}
-
-		TEST_METHOD(Actintensity1)
-		{
-			Assert::AreEqual(50L, root.getLong("actintensity1"));
-		}
-				
-		TEST_METHOD(Actintensity2)
-		{
-			Assert::AreEqual(255L, root.getLong("actintensity2"));
-		}
-		
-		TEST_METHOD(Measintensity)
-		{
-			Assert::AreEqual(255L, root.getLong("measintensity"));
-		}
-		
-		TEST_METHOD(Calintensity)
-		{
-			Assert::AreEqual(255L, root.getLong("calintensity"));
-		}
-
-		TEST_METHOD(Pulses)
-		{
-			// "pulses":[50,50,50]
-
-			JsonArray array = root.getArray("pulses");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(3, array.getLength());
-
-			for (int i = 0; i < 3; i++)
-			{
-				Assert::AreEqual(50L, array.getLong(i));
-			}
-		}
-
-		TEST_METHOD(Act)
-		{
-			// "act":[2,1,2,2]
-
-			JsonArray array = root.getArray("act");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(4, array.getLength());
-			Assert::AreEqual(2L, array.getLong(0));
-			Assert::AreEqual(1L, array.getLong(1));
-			Assert::AreEqual(2L, array.getLong(2));
-			Assert::AreEqual(2L, array.getLong(3));			
-		}
-
-		TEST_METHOD(Detectors)
-		{
-			// "detectors":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]]
-
-			JsonArray array = root.getArray("detectors");
-			Assert::IsTrue(array.success());
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(4, array.getArray(i).getLength());
-
-				for (int j = 0; j < 4; j++)
-					Assert::AreEqual(34L, array.getArray(i).getLong(j));
-			}
-		}
-
-		TEST_METHOD(Alta)
-		{
-			// alta:[2,2,2,2]
-
-			JsonArray array = root.getArray("alta");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(2L, array.getLong(i));
-			}
-		}
-
-		TEST_METHOD(Altb)
-		{
-			// altb:[2,2,2,2]
-
-			JsonArray array = root.getArray("altb");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(2L, array.getLong(i));
-			}
-		}
-
-		TEST_METHOD(Measlights)
-		{
-			// "measlights":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
-
-			JsonArray array = root.getArray("measlights");
-			Assert::IsTrue(array.success());
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(4, array.getArray(i).getLength());
-
-				for (int j = 0; j < 4; j++)
-					Assert::AreEqual(15L, array.getArray(i).getLong(j));
-			}
-		}
-
-		TEST_METHOD(Measlights2)
-		{
-			// "measlights2":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
-
-			JsonArray array = root.getArray("measlights2");
-			Assert::IsTrue(array.success());
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(4, array.getArray(i).getLength());
-
-				for (int j = 0; j < 4; j++)
-					Assert::AreEqual(15L, array.getArray(i).getLong(j));
-			}
-		}
-
-		TEST_METHOD(Altc)
-		{
-			// altc:[2,2,2,2]
-
-			JsonArray array = root.getArray("altc");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(2L, array.getLong(i));
-			}
-		}
-
-		TEST_METHOD(Altd)
-		{
-			// altd:[2,2,2,2]
-
-			JsonArray array = root.getArray("altd");
-			Assert::IsTrue(array.success());
-
-			Assert::AreEqual(4, array.getLength());
-
-			for (int i = 0; i < 4; i++)
-			{
-				Assert::AreEqual(2L, array.getLong(i));
-			}
-		}
-	};
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+#include <string>
+
+using namespace std;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace ArduinoJsonParserTests
+{
+	TEST_CLASS(GbathreeBug)
+	{
+		char json[1024];
+		JsonParser<200> parser;
+		JsonHashTable root;
+		
+
+	public:
+
+		TEST_METHOD_INITIALIZE(Initialize)
+		{
+			// BUG described here:
+			// http://forum.arduino.cc/index.php?topic=172578.msg1608219#msg1608219
+			strcpy(json, "{ \"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}");
+			root = parser.parseHashTable(json);
+		}
+
+		TEST_METHOD(Root)
+		{
+			Assert::IsTrue(root.success());
+		}
+
+		TEST_METHOD(ProtocolName)
+		{
+			string protocol_name = root.getString("protocol_name");
+			Assert::AreEqual(string("fluorescence"), protocol_name);
+		}
+
+		TEST_METHOD(Repeats)
+		{
+			Assert::AreEqual(1L, root.getLong("repeats"));
+		}
+
+		TEST_METHOD(Wait)
+		{
+			Assert::AreEqual(0L, root.getLong("wait"));
+		}
+
+		TEST_METHOD(Measurements)
+		{
+			Assert::AreEqual(3L, root.getLong("measurements"));
+		}
+
+		TEST_METHOD(Meas2_Light)
+		{
+			Assert::AreEqual(15L, root.getLong("meas2_light"));
+		}
+
+		TEST_METHOD(Meas1_Baseline)
+		{
+			Assert::AreEqual(0L, root.getLong("meas1_baseline"));
+		}
+
+		TEST_METHOD(Act_Light)
+		{
+			Assert::AreEqual(20L, root.getLong("act_light"));
+		}
+
+		TEST_METHOD(Pulsesize)
+		{
+			Assert::AreEqual(25L, root.getLong("pulsesize"));
+		}
+
+		TEST_METHOD(Pulsedistance)
+		{
+			Assert::AreEqual(10000L, root.getLong("pulsedistance"));
+		}
+
+		TEST_METHOD(Actintensity1)
+		{
+			Assert::AreEqual(50L, root.getLong("actintensity1"));
+		}
+				
+		TEST_METHOD(Actintensity2)
+		{
+			Assert::AreEqual(255L, root.getLong("actintensity2"));
+		}
+		
+		TEST_METHOD(Measintensity)
+		{
+			Assert::AreEqual(255L, root.getLong("measintensity"));
+		}
+		
+		TEST_METHOD(Calintensity)
+		{
+			Assert::AreEqual(255L, root.getLong("calintensity"));
+		}
+
+		TEST_METHOD(Pulses)
+		{
+			// "pulses":[50,50,50]
+
+			JsonArray array = root.getArray("pulses");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(3, array.getLength());
+
+			for (int i = 0; i < 3; i++)
+			{
+				Assert::AreEqual(50L, array.getLong(i));
+			}
+		}
+
+		TEST_METHOD(Act)
+		{
+			// "act":[2,1,2,2]
+
+			JsonArray array = root.getArray("act");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(4, array.getLength());
+			Assert::AreEqual(2L, array.getLong(0));
+			Assert::AreEqual(1L, array.getLong(1));
+			Assert::AreEqual(2L, array.getLong(2));
+			Assert::AreEqual(2L, array.getLong(3));			
+		}
+
+		TEST_METHOD(Detectors)
+		{
+			// "detectors":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]]
+
+			JsonArray array = root.getArray("detectors");
+			Assert::IsTrue(array.success());
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(4, array.getArray(i).getLength());
+
+				for (int j = 0; j < 4; j++)
+					Assert::AreEqual(34L, array.getArray(i).getLong(j));
+			}
+		}
+
+		TEST_METHOD(Alta)
+		{
+			// alta:[2,2,2,2]
+
+			JsonArray array = root.getArray("alta");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(2L, array.getLong(i));
+			}
+		}
+
+		TEST_METHOD(Altb)
+		{
+			// altb:[2,2,2,2]
+
+			JsonArray array = root.getArray("altb");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(2L, array.getLong(i));
+			}
+		}
+
+		TEST_METHOD(Measlights)
+		{
+			// "measlights":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
+
+			JsonArray array = root.getArray("measlights");
+			Assert::IsTrue(array.success());
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(4, array.getArray(i).getLength());
+
+				for (int j = 0; j < 4; j++)
+					Assert::AreEqual(15L, array.getArray(i).getLong(j));
+			}
+		}
+
+		TEST_METHOD(Measlights2)
+		{
+			// "measlights2":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
+
+			JsonArray array = root.getArray("measlights2");
+			Assert::IsTrue(array.success());
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(4, array.getArray(i).getLength());
+
+				for (int j = 0; j < 4; j++)
+					Assert::AreEqual(15L, array.getArray(i).getLong(j));
+			}
+		}
+
+		TEST_METHOD(Altc)
+		{
+			// altc:[2,2,2,2]
+
+			JsonArray array = root.getArray("altc");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(2L, array.getLong(i));
+			}
+		}
+
+		TEST_METHOD(Altd)
+		{
+			// altd:[2,2,2,2]
+
+			JsonArray array = root.getArray("altd");
+			Assert::IsTrue(array.success());
+
+			Assert::AreEqual(4, array.getLength());
+
+			for (int i = 0; i < 4; i++)
+			{
+				Assert::AreEqual(2L, array.getLong(i));
+			}
+		}
+	};
+}

+ 64 - 64
JsonParserTests/JsonArrayIteratorTests.cpp

@@ -1,67 +1,67 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace JsonParserTests
-{
-    TEST_CLASS(JsonArrayIteratorTests)
-    {
-    public:
-
-        TEST_METHOD(EmptyJson)
-        {
-            char json[] = "";
-            JsonParser<1> parser;
-
-            JsonArray a = parser.parse(json);
-
-            int loopCount = 0;
-
-            for (long i : a)
-            {
-                loopCount++;
-            }
-
-            Assert::AreEqual(0, loopCount);
-        }
-
-        TEST_METHOD(ThreeIntegers)
-        {
-            char json [] = "[1,2,3]";
-            long expected [] = {1, 2, 3};
-            JsonParser<4> parser;
-
-            JsonArray a = parser.parse(json);
-
-            int index = 0;
-
-            for (long i : a)
-            {
-                Assert::AreEqual(expected[index++], i);
-            }
-        }
-
-        TEST_METHOD(ThreeStrings)
-        {
-            char json[] = "[\"1\",\"2\",\"3\"]";
-            char* expected[] = {"1", "2", "3"};
-            JsonParser<4> parser;
-
-            JsonArray a = parser.parse(json);
-
-            int index = 0;
-
-            for (const char* i : a)
-            {
-                Assert::AreEqual(expected[index++], i);
-            }
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace JsonParserTests
+{
+    TEST_CLASS(JsonArrayIteratorTests)
+    {
+    public:
+
+        TEST_METHOD(EmptyJson)
+        {
+            char json[] = "";
+            JsonParser<1> parser;
+
+            JsonArray a = parser.parse(json);
+
+            int loopCount = 0;
+
+            for (long i : a)
+            {
+                loopCount++;
+            }
+
+            Assert::AreEqual(0, loopCount);
+        }
+
+        TEST_METHOD(ThreeIntegers)
+        {
+            char json [] = "[1,2,3]";
+            long expected [] = {1, 2, 3};
+            JsonParser<4> parser;
+
+            JsonArray a = parser.parse(json);
+
+            int index = 0;
+
+            for (long i : a)
+            {
+                Assert::AreEqual(expected[index++], i);
+            }
+        }
+
+        TEST_METHOD(ThreeStrings)
+        {
+            char json[] = "[\"1\",\"2\",\"3\"]";
+            char* expected[] = {"1", "2", "3"};
+            JsonParser<4> parser;
+
+            JsonArray a = parser.parse(json);
+
+            int index = 0;
+
+            for (const char* i : a)
+            {
+                Assert::AreEqual(expected[index++], i);
+            }
+        }
+    };
+}

+ 174 - 174
JsonParserTests/JsonArrayTests.cpp

@@ -1,181 +1,181 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace ArduinoJsonParserTests
-{
-    TEST_CLASS(JsonArrayTests)
-    {
-        JsonArray array;
-        char json[256];
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace ArduinoJsonParserTests
+{
+    TEST_CLASS(JsonArrayTests)
+    {
+        JsonArray array;
+        char json[256];
         jsmntok_t tokens[32];
-        JsonParserBase parser = JsonParserBase(tokens, 32);
-
-    public:
-        
-        TEST_METHOD(TooFewClosingBrackets)
-        {
-            whenInputIs("[[]");
-            parseMustFail();
-        }
-
-        TEST_METHOD(TooManyClosingBrackets)
-        {
-            whenInputIs("[]]");
-            parseMustFail();
-        }
-        
-        TEST_METHOD(EmptyArray)
-        {
-            whenInputIs("[]");
-            parseMustSucceed();
-            lengthMustBe(0);
-        }
-
-        TEST_METHOD(NotEnoughTokens)
-        {
-            setTokenCountTo(2);
-
-            whenInputIs("[1,2]");
-
-            parseMustFail();
-            itemMustNotExist(0);
-        }
-
-        TEST_METHOD(TwoIntegers)
-        {
-            setTokenCountTo(3);
-
-            whenInputIs("[1,2]");
-
-            parseMustSucceed();
-            lengthMustBe(2);
-            itemMustBe(0, 1L);
-            itemMustBe(1, 2L);
-            itemMustNotExist(2);
-        }
-
-        TEST_METHOD(TwoBooleans)
-        {
-            setTokenCountTo(3);
-
-            whenInputIs("[true,false]");
-
-            parseMustSucceed();
-            lengthMustBe(2);
-            itemMustBe(0, true);
-            itemMustBe(1, false);
-            itemMustNotExist(2);
-        }
-
-        TEST_METHOD(TwoStrings)
-        {
-            setTokenCountTo(3);
-
-            whenInputIs("[\"hello\",\"world\"]");
-
-            parseMustSucceed();
-            lengthMustBe(2);
-            itemMustBe(0, "hello");
-            itemMustBe(1, "world");
-            itemMustNotExist(2);
-        }
-
-        TEST_METHOD(TwoDimensionsArray)
-        {
-            setTokenCountTo(7);
-
-            whenInputIs("[[1,2],[3,4]]");
-
-            parseMustSucceed();
-            lengthMustBe(2);
-            itemMustBe(0, 0, 1L);
-            itemMustBe(0, 1, 2L);
-            itemMustBe(1, 0, 3L);
-            itemMustBe(1, 1, 4L);
-            itemMustNotExist(2);
-        }
-
-        TEST_METHOD(ThreeDimensionsArray)
-        {
-            setTokenCountTo(15);
-
-            whenInputIs("[[[1,2],[3,4]],[[5,6],[7,8]]]");
-
-            parseMustSucceed();
-            lengthMustBe(2);
-            itemMustBe(0, 0, 0, 1L);
-            itemMustBe(0, 0, 1, 2L);
-            itemMustBe(0, 1, 0, 3L);
-            itemMustBe(0, 1, 1, 4L);
-            itemMustBe(1, 0, 0, 5L);
-            itemMustBe(1, 0, 1, 6L);
-            itemMustBe(1, 1, 0, 7L);
-            itemMustBe(1, 1, 1, 8L);
-            itemMustNotExist(2);
-        }        
-        
-    private:
-
+        JsonParserBase parser = JsonParserBase(tokens, 32);
+
+    public:
+        
+        TEST_METHOD(TooFewClosingBrackets)
+        {
+            whenInputIs("[[]");
+            parseMustFail();
+        }
+
+        TEST_METHOD(TooManyClosingBrackets)
+        {
+            whenInputIs("[]]");
+            parseMustFail();
+        }
+        
+        TEST_METHOD(EmptyArray)
+        {
+            whenInputIs("[]");
+            parseMustSucceed();
+            lengthMustBe(0);
+        }
+
+        TEST_METHOD(NotEnoughTokens)
+        {
+            setTokenCountTo(2);
+
+            whenInputIs("[1,2]");
+
+            parseMustFail();
+            itemMustNotExist(0);
+        }
+
+        TEST_METHOD(TwoIntegers)
+        {
+            setTokenCountTo(3);
+
+            whenInputIs("[1,2]");
+
+            parseMustSucceed();
+            lengthMustBe(2);
+            itemMustBe(0, 1L);
+            itemMustBe(1, 2L);
+            itemMustNotExist(2);
+        }
+
+        TEST_METHOD(TwoBooleans)
+        {
+            setTokenCountTo(3);
+
+            whenInputIs("[true,false]");
+
+            parseMustSucceed();
+            lengthMustBe(2);
+            itemMustBe(0, true);
+            itemMustBe(1, false);
+            itemMustNotExist(2);
+        }
+
+        TEST_METHOD(TwoStrings)
+        {
+            setTokenCountTo(3);
+
+            whenInputIs("[\"hello\",\"world\"]");
+
+            parseMustSucceed();
+            lengthMustBe(2);
+            itemMustBe(0, "hello");
+            itemMustBe(1, "world");
+            itemMustNotExist(2);
+        }
+
+        TEST_METHOD(TwoDimensionsArray)
+        {
+            setTokenCountTo(7);
+
+            whenInputIs("[[1,2],[3,4]]");
+
+            parseMustSucceed();
+            lengthMustBe(2);
+            itemMustBe(0, 0, 1L);
+            itemMustBe(0, 1, 2L);
+            itemMustBe(1, 0, 3L);
+            itemMustBe(1, 1, 4L);
+            itemMustNotExist(2);
+        }
+
+        TEST_METHOD(ThreeDimensionsArray)
+        {
+            setTokenCountTo(15);
+
+            whenInputIs("[[[1,2],[3,4]],[[5,6],[7,8]]]");
+
+            parseMustSucceed();
+            lengthMustBe(2);
+            itemMustBe(0, 0, 0, 1L);
+            itemMustBe(0, 0, 1, 2L);
+            itemMustBe(0, 1, 0, 3L);
+            itemMustBe(0, 1, 1, 4L);
+            itemMustBe(1, 0, 0, 5L);
+            itemMustBe(1, 0, 1, 6L);
+            itemMustBe(1, 1, 0, 7L);
+            itemMustBe(1, 1, 1, 8L);
+            itemMustNotExist(2);
+        }        
+        
+    private:
+
         void setTokenCountTo(int n)
         {
             parser = JsonParserBase(tokens, n);
-        }
-
-        void whenInputIs(const char* input)
-        {
-            strcpy(json, input);
-            array = parser.parseArray(json);
-        }
-
-        void parseMustFail()
-        {
-            Assert::IsFalse(array.success());
-            lengthMustBe(0);
-        }
-
-        void parseMustSucceed()
-        {
-            Assert::IsTrue(array.success());
-        }
-
-        void lengthMustBe(int expected)
-        {
-            Assert::AreEqual(expected, array.getLength());
-        }
-
-        void itemMustBe(int index, long expected)
-        {
-            Assert::AreEqual(expected, array.getLong(index));
-        }
-
-        void itemMustBe(int index, bool expected)
-        {
-            Assert::AreEqual(expected, array.getBool(index));
-        }
-
-        void itemMustBe(int index, const char* expected)
-        {
-            Assert::AreEqual(expected, array.getString(index));
-        }
-
-        void itemMustBe(int index0, int index1, long expected)
-        {
-            Assert::AreEqual(expected, array.getArray(index0).getLong(index1));
-        }
-
-        void itemMustBe(int index0, int index1, int index2, long expected)
-        {
-            Assert::AreEqual(expected, array.getArray(index0).getArray(index1).getLong(index2));
-        }
-
+        }
+
+        void whenInputIs(const char* input)
+        {
+            strcpy(json, input);
+            array = parser.parseArray(json);
+        }
+
+        void parseMustFail()
+        {
+            Assert::IsFalse(array.success());
+            lengthMustBe(0);
+        }
+
+        void parseMustSucceed()
+        {
+            Assert::IsTrue(array.success());
+        }
+
+        void lengthMustBe(int expected)
+        {
+            Assert::AreEqual(expected, array.getLength());
+        }
+
+        void itemMustBe(int index, long expected)
+        {
+            Assert::AreEqual(expected, array.getLong(index));
+        }
+
+        void itemMustBe(int index, bool expected)
+        {
+            Assert::AreEqual(expected, array.getBool(index));
+        }
+
+        void itemMustBe(int index, const char* expected)
+        {
+            Assert::AreEqual(expected, array.getString(index));
+        }
+
+        void itemMustBe(int index0, int index1, long expected)
+        {
+            Assert::AreEqual(expected, array.getArray(index0).getLong(index1));
+        }
+
+        void itemMustBe(int index0, int index1, int index2, long expected)
+        {
+            Assert::AreEqual(expected, array.getArray(index0).getArray(index1).getLong(index2));
+        }
+
         void itemMustNotExist(int index)
         {
             Assert::IsFalse(array.getHashTable(index).success());
@@ -184,6 +184,6 @@ namespace ArduinoJsonParserTests
             Assert::AreEqual(0.0, array.getDouble(index));
             Assert::AreEqual(0L, array.getLong(index));
             Assert::IsNull(array.getString(index));
-        }
-    };
-}
+        }
+    };
+}

+ 68 - 68
JsonParserTests/JsonObjectIteratorTests.cpp

@@ -1,71 +1,71 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace JsonParserTests
-{
-    TEST_CLASS(JsonObjectIteratorTests)
-    {
-    public:
-
-        TEST_METHOD(EmptyObject)
-        {
-            char json [] = "{}";
-            JsonParser<1> parser;
-
-            JsonHashTable a = parser.parse(json);
-
-            int loopCount = 0;
-
-            for (auto i : a)
-            {
-                loopCount++;
-            }
-
-            Assert::AreEqual(0, loopCount);
-        }
-
-        TEST_METHOD(EmptyJson)
-        {
-            char json[] = "";
-            JsonParser<1> parser;
-
-            JsonHashTable a = parser.parse(json);
-
-            int loopCount = 0;
-
-            for (auto i : a)
-            {
-                loopCount++;
-            }
-
-            Assert::AreEqual(0, loopCount);
-        }
-
-        TEST_METHOD(ThreeStrings)
-        {
-            char json[] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
-            char* expectedKeys[] = {"key1", "key2", "key3"};
-            char* expectedValues[] = {"value1", "value2", "value3"};
-            JsonParser<7> parser;
-
-            JsonHashTable a = parser.parse(json);
-
-            int index = 0;
-
-            for (auto i : a)
-            {
-                Assert::AreEqual(expectedKeys[index], i.key());
-                Assert::AreEqual(expectedValues[index], (const char*) i.value());
-                index++;
-            }
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace JsonParserTests
+{
+    TEST_CLASS(JsonObjectIteratorTests)
+    {
+    public:
+
+        TEST_METHOD(EmptyObject)
+        {
+            char json [] = "{}";
+            JsonParser<1> parser;
+
+            JsonHashTable a = parser.parse(json);
+
+            int loopCount = 0;
+
+            for (auto i : a)
+            {
+                loopCount++;
+            }
+
+            Assert::AreEqual(0, loopCount);
+        }
+
+        TEST_METHOD(EmptyJson)
+        {
+            char json[] = "";
+            JsonParser<1> parser;
+
+            JsonHashTable a = parser.parse(json);
+
+            int loopCount = 0;
+
+            for (auto i : a)
+            {
+                loopCount++;
+            }
+
+            Assert::AreEqual(0, loopCount);
+        }
+
+        TEST_METHOD(ThreeStrings)
+        {
+            char json[] = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}";
+            char* expectedKeys[] = {"key1", "key2", "key3"};
+            char* expectedValues[] = {"value1", "value2", "value3"};
+            JsonParser<7> parser;
+
+            JsonHashTable a = parser.parse(json);
+
+            int index = 0;
+
+            for (auto i : a)
+            {
+                Assert::AreEqual(expectedKeys[index], i.key());
+                Assert::AreEqual(expectedValues[index], (const char*) i.value());
+                index++;
+            }
+        }
+    };
+}

+ 162 - 162
JsonParserTests/JsonObjectTests.cpp

@@ -1,165 +1,165 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-#include <string>
-
-using namespace std;
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace ArduinoJsonParserTests
-{
-    TEST_CLASS(JsonHashTableTests)
-    {
-        JsonHashTable hashTable;
-        JsonArray nestedArray;
-        char json[256];
-        jsmntok_t tokens[32];
-        JsonParserBase parser = JsonParserBase(tokens, 32);
-
-    public:
-
-        TEST_METHOD(EmptyHashTable)
-        {
-            whenInputIs("{}");
-            parseMustSucceed();
-        }
-
-        TEST_METHOD(NotEnoughTokens)
-        {
-            setTokenCountTo(2);
-
-            whenInputIs("{\"key\":0}");
-
-            parseMustFail();
-            itemMustNotExist("key");
-        }
-
-        TEST_METHOD(TwoIntegers)
-        {
-            setTokenCountTo(5);
-
-            whenInputIs("{\"key1\":1,\"key2\":2}");
-
-            parseMustSucceed();
-            itemMustBe("key1", 1L);
-            itemMustBe("key2", 2L);
-            itemMustNotExist("key3");
-        }
-
-        TEST_METHOD(TwoBooleans)
-        {
-            setTokenCountTo(5);
-
-            whenInputIs("{\"key1\":true,\"key2\":false}");
-
-            parseMustSucceed();
-            itemMustBe("key1", true);
-            itemMustBe("key2", false);
-            itemMustNotExist("key3");
-        }
-
-        TEST_METHOD(TwoStrings)
-        {
-            setTokenCountTo(5);
-
-            whenInputIs("{\"key1\":\"hello\",\"key2\":\"world\"}");
-
-            parseMustSucceed();
-            itemMustBe("key1", "hello");
-            itemMustBe("key2", "world");
-            itemMustNotExist("key3");
-        }
-
-        TEST_METHOD(TwoNestedArrays)
-        {
-            setTokenCountTo(9);
-
-            whenInputIs("{\"key1\":[1,2],\"key2\":[3,4]}");
-            parseMustSucceed();
-
-            itemMustBeAnArray("key1");
-            arrayLengthMustBe(2);
-            arrayItemMustBe(0, 1L);
-            arrayItemMustBe(1, 2L);
-            arrayItemMustBe(2, 0L);
-
-            itemMustBeAnArray("key2");
-            arrayLengthMustBe(2);
-            arrayItemMustBe(0, 3L);
-            arrayItemMustBe(1, 4L);
-            arrayItemMustBe(2, 0L);
-
-            itemMustNotExist("key3");
-        }
-
-    private:
-
-        void setTokenCountTo(int n)
-        {
-            parser = JsonParserBase(tokens, n);
-        }
-
-        void whenInputIs(const char* input)
-        {
-            strcpy(json, input);
-            hashTable = parser.parseHashTable(json);
-        }
-
-        void parseMustFail()
-        {
-            Assert::IsFalse(hashTable.success());
-        }
-
-        void parseMustSucceed()
-        {
-            Assert::IsTrue(hashTable.success());
-        }
-
-        void itemMustBe(const char* key, long expected)
-        {
-            Assert::AreEqual(expected, hashTable.getLong(key));
-        }
-
-        void itemMustBe(const char* key, bool expected)
-        {
-            Assert::AreEqual(expected, hashTable.getBool(key));
-        }
-
-        void itemMustBe(const char* key, const char* expected)
-        {
-            Assert::AreEqual(expected, hashTable.getString(key));
-        }
-
-        void itemMustNotExist(const char* key)
-        {
-            Assert::IsFalse(hashTable.containsKey(key));
-            Assert::IsFalse(hashTable.getHashTable(key).success());
-            Assert::IsFalse(hashTable.getArray(key).success());
-            Assert::IsFalse(hashTable.getBool(key));
-            Assert::AreEqual(0.0, hashTable.getDouble(key));
-            Assert::AreEqual(0L, hashTable.getLong(key));
-            Assert::IsNull(hashTable.getString(key));
-        }
-
-        void itemMustBeAnArray(const char* key)
-        {
-            nestedArray = hashTable.getArray(key);
-            Assert::IsTrue(nestedArray.success());
-        }
-
-        void arrayLengthMustBe(int expected)
-        {
-            Assert::AreEqual(expected, nestedArray.getLength());
-        }
-
-        void arrayItemMustBe(int index, long expected)
-        {
-            Assert::AreEqual(expected, nestedArray.getLong(index));
-        }
-    };
-}
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+#include <string>
+
+using namespace std;
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace ArduinoJsonParserTests
+{
+    TEST_CLASS(JsonHashTableTests)
+    {
+        JsonHashTable hashTable;
+        JsonArray nestedArray;
+        char json[256];
+        jsmntok_t tokens[32];
+        JsonParserBase parser = JsonParserBase(tokens, 32);
+
+    public:
+
+        TEST_METHOD(EmptyHashTable)
+        {
+            whenInputIs("{}");
+            parseMustSucceed();
+        }
+
+        TEST_METHOD(NotEnoughTokens)
+        {
+            setTokenCountTo(2);
+
+            whenInputIs("{\"key\":0}");
+
+            parseMustFail();
+            itemMustNotExist("key");
+        }
+
+        TEST_METHOD(TwoIntegers)
+        {
+            setTokenCountTo(5);
+
+            whenInputIs("{\"key1\":1,\"key2\":2}");
+
+            parseMustSucceed();
+            itemMustBe("key1", 1L);
+            itemMustBe("key2", 2L);
+            itemMustNotExist("key3");
+        }
+
+        TEST_METHOD(TwoBooleans)
+        {
+            setTokenCountTo(5);
+
+            whenInputIs("{\"key1\":true,\"key2\":false}");
+
+            parseMustSucceed();
+            itemMustBe("key1", true);
+            itemMustBe("key2", false);
+            itemMustNotExist("key3");
+        }
+
+        TEST_METHOD(TwoStrings)
+        {
+            setTokenCountTo(5);
+
+            whenInputIs("{\"key1\":\"hello\",\"key2\":\"world\"}");
+
+            parseMustSucceed();
+            itemMustBe("key1", "hello");
+            itemMustBe("key2", "world");
+            itemMustNotExist("key3");
+        }
+
+        TEST_METHOD(TwoNestedArrays)
+        {
+            setTokenCountTo(9);
+
+            whenInputIs("{\"key1\":[1,2],\"key2\":[3,4]}");
+            parseMustSucceed();
+
+            itemMustBeAnArray("key1");
+            arrayLengthMustBe(2);
+            arrayItemMustBe(0, 1L);
+            arrayItemMustBe(1, 2L);
+            arrayItemMustBe(2, 0L);
+
+            itemMustBeAnArray("key2");
+            arrayLengthMustBe(2);
+            arrayItemMustBe(0, 3L);
+            arrayItemMustBe(1, 4L);
+            arrayItemMustBe(2, 0L);
+
+            itemMustNotExist("key3");
+        }
+
+    private:
+
+        void setTokenCountTo(int n)
+        {
+            parser = JsonParserBase(tokens, n);
+        }
+
+        void whenInputIs(const char* input)
+        {
+            strcpy(json, input);
+            hashTable = parser.parseHashTable(json);
+        }
+
+        void parseMustFail()
+        {
+            Assert::IsFalse(hashTable.success());
+        }
+
+        void parseMustSucceed()
+        {
+            Assert::IsTrue(hashTable.success());
+        }
+
+        void itemMustBe(const char* key, long expected)
+        {
+            Assert::AreEqual(expected, hashTable.getLong(key));
+        }
+
+        void itemMustBe(const char* key, bool expected)
+        {
+            Assert::AreEqual(expected, hashTable.getBool(key));
+        }
+
+        void itemMustBe(const char* key, const char* expected)
+        {
+            Assert::AreEqual(expected, hashTable.getString(key));
+        }
+
+        void itemMustNotExist(const char* key)
+        {
+            Assert::IsFalse(hashTable.containsKey(key));
+            Assert::IsFalse(hashTable.getHashTable(key).success());
+            Assert::IsFalse(hashTable.getArray(key).success());
+            Assert::IsFalse(hashTable.getBool(key));
+            Assert::AreEqual(0.0, hashTable.getDouble(key));
+            Assert::AreEqual(0L, hashTable.getLong(key));
+            Assert::IsNull(hashTable.getString(key));
+        }
+
+        void itemMustBeAnArray(const char* key)
+        {
+            nestedArray = hashTable.getArray(key);
+            Assert::IsTrue(nestedArray.success());
+        }
+
+        void arrayLengthMustBe(int expected)
+        {
+            Assert::AreEqual(expected, nestedArray.getLength());
+        }
+
+        void arrayItemMustBe(int index, long expected)
+        {
+            Assert::AreEqual(expected, nestedArray.getLong(index));
+        }
+    };
+}

+ 103 - 103
JsonParserTests/JsonStringTests.cpp

@@ -1,107 +1,107 @@
 /*
 * Arduino JSON library
 * Benoit Blanchon 2014 - MIT License
-*/
-
-#include "CppUnitTest.h"
-#include "JsonParser.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-using namespace ArduinoJson::Parser;
-
-namespace ArduinoJsonParserTests
-{
-    TEST_CLASS(JsonStringTests)
-    {
-        const char* actual;
+*/
+
+#include "CppUnitTest.h"
+#include "JsonParser.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Parser;
+
+namespace ArduinoJsonParserTests
+{
+    TEST_CLASS(JsonStringTests)
+    {
+        const char* actual;
         char json[256];
-        JsonParser<32> parser;
-
-    public:
-
-        TEST_METHOD(EmptyString)
-        {
-            whenInputIs("");
-            outputMustBe(0);
-        }
-
-        TEST_METHOD(JustOneQuote)
-        {
-            whenInputIs("\"");
-            outputMustBe(0);
-        }
-
-        TEST_METHOD(SimpleString)
-        {
-            whenInputIs("\"Hi!\"");
-            outputMustBe("Hi!");
-        }
-
-        TEST_METHOD(EscapedQuote)
-        {
-            whenInputIs("\"12\\\"34\"");  // ie 12\"34
-            outputMustBe("12\"34");
-        }
-
-        TEST_METHOD(EscapedReverseSolidus)
-        {
-            whenInputIs("\"12\\\\34\""); // ie 12\\34
-            outputMustBe("12\\34");
-        }
-
-        TEST_METHOD(EscapedSolidus)
-        {
-            whenInputIs("\"12\\/34\"");
-            outputMustBe("12/34");
-        }
-
-        TEST_METHOD(EscapedBackspace)
-        {
-            whenInputIs("\"12\\b34\"");
-            outputMustBe("12\b34");
-        }
-
-        TEST_METHOD(EscapedFormfeed)
-        {
-            whenInputIs("\"12\\f34\"");
-            outputMustBe("12\f34");
-        }
-        
-        TEST_METHOD(EscapedNewline)
-        {
-            whenInputIs("\"12\\n34\""); 
-            outputMustBe("12\n34");
-        }
-
-        TEST_METHOD(EscapedCarriageReturn)
-        {
-            whenInputIs("\"12\\r34\"");
-            outputMustBe("12\r34");
-        }
-
-        TEST_METHOD(EscapedTab)
-        {
-            whenInputIs("\"12\\t34\"");
-            outputMustBe("12\t34");
-        }
-
-        TEST_METHOD(AllEscapedCharsTogether)
-        {
-            whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
-            outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
-        }
-
-    private:       
-
-        void whenInputIs(const char* input)
-        {
-            strcpy(json, input);
-            actual = parser.parse(json);
-        }
-
-        void outputMustBe(const char* expected)
-        {
-            Assert::AreEqual(expected, actual);
-        }
-    };
-}
+        JsonParser<32> parser;
+
+    public:
+
+        TEST_METHOD(EmptyString)
+        {
+            whenInputIs("");
+            outputMustBe(0);
+        }
+
+        TEST_METHOD(JustOneQuote)
+        {
+            whenInputIs("\"");
+            outputMustBe(0);
+        }
+
+        TEST_METHOD(SimpleString)
+        {
+            whenInputIs("\"Hi!\"");
+            outputMustBe("Hi!");
+        }
+
+        TEST_METHOD(EscapedQuote)
+        {
+            whenInputIs("\"12\\\"34\"");  // ie 12\"34
+            outputMustBe("12\"34");
+        }
+
+        TEST_METHOD(EscapedReverseSolidus)
+        {
+            whenInputIs("\"12\\\\34\""); // ie 12\\34
+            outputMustBe("12\\34");
+        }
+
+        TEST_METHOD(EscapedSolidus)
+        {
+            whenInputIs("\"12\\/34\"");
+            outputMustBe("12/34");
+        }
+
+        TEST_METHOD(EscapedBackspace)
+        {
+            whenInputIs("\"12\\b34\"");
+            outputMustBe("12\b34");
+        }
+
+        TEST_METHOD(EscapedFormfeed)
+        {
+            whenInputIs("\"12\\f34\"");
+            outputMustBe("12\f34");
+        }
+        
+        TEST_METHOD(EscapedNewline)
+        {
+            whenInputIs("\"12\\n34\""); 
+            outputMustBe("12\n34");
+        }
+
+        TEST_METHOD(EscapedCarriageReturn)
+        {
+            whenInputIs("\"12\\r34\"");
+            outputMustBe("12\r34");
+        }
+
+        TEST_METHOD(EscapedTab)
+        {
+            whenInputIs("\"12\\t34\"");
+            outputMustBe("12\t34");
+        }
+
+        TEST_METHOD(AllEscapedCharsTogether)
+        {
+            whenInputIs("\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"");
+            outputMustBe("1\"2\\3/4\b5\f6\n7\r8\t9");
+        }
+
+    private:       
+
+        void whenInputIs(const char* input)
+        {
+            strcpy(json, input);
+            actual = parser.parse(json);
+        }
+
+        void outputMustBe(const char* expected)
+        {
+            Assert::AreEqual(expected, actual);
+        }
+    };
+}

+ 25 - 25
JsonParserTests/TestHashGenerator.cpp

@@ -1,25 +1,25 @@
-#include "stdafx.h"
-#include "CppUnitTest.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace ArduinoJsonParserTests
-{
-	TEST_CLASS(TestHashGenerator)
-	{
-	public:
-		
-		TEST_METHOD(TestMethod1)
-		{
-            JsonArray<5> arr;
-            arr.Add(1);
-            arr.Add("Hi!");
-
-            JsonHashTable<4> hash;
-            hash.Add("key1", 1);
-            hash.Add("key2", "Hello!");
-            hash.Add("key3", arr);
-		}
-
-	};
-}
+#include "stdafx.h"
+#include "CppUnitTest.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace ArduinoJsonParserTests
+{
+	TEST_CLASS(TestHashGenerator)
+	{
+	public:
+		
+		TEST_METHOD(TestMethod1)
+		{
+            JsonArray<5> arr;
+            arr.Add(1);
+            arr.Add("Hi!");
+
+            JsonHashTable<4> hash;
+            hash.Add("key1", 1);
+            hash.Add("key2", "Hello!");
+            hash.Add("key3", arr);
+		}
+
+	};
+}