JsonObjectBase.cpp 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #include "JsonObjectBase.h"
  6. using namespace ArduinoJson::Generator;
  7. size_t JsonObjectBase::printTo(Print& p) const
  8. {
  9. size_t n = 0;
  10. n += p.write('{');
  11. // NB: the code has been optimized for a small size on a 8-bit AVR
  12. const KeyValuePair* current = items;
  13. for (int i = count; i > 0; i--)
  14. {
  15. n += current->key.printTo(p);
  16. n += p.write(':');
  17. n += current->value.printTo(p);
  18. current++;
  19. if (i > 1)
  20. {
  21. n += p.write(',');
  22. }
  23. }
  24. n += p.write('}');
  25. return n;
  26. }
  27. JsonObjectBase::KeyValuePair* JsonObjectBase::getMatchingPair(char const* key)
  28. {
  29. for (int i = 0; i < count; ++i)
  30. {
  31. if (items[i].key.equals(key))
  32. {
  33. return &items[i];
  34. }
  35. }
  36. if (count >= capacity) return 0;
  37. KeyValuePair* p = &items[count++];
  38. p->key.set(key);
  39. return p;
  40. }