StringBuilder.hpp 536 B

123456789101112131415161718192021222324252627282930
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #pragma once
  7. #include "../Arduino/Print.hpp"
  8. namespace ArduinoJson {
  9. namespace Internals {
  10. // A Print implementation that allows to write in a char[]
  11. class StringBuilder : public Print {
  12. public:
  13. StringBuilder(char *buf, int size)
  14. : buffer(buf), capacity(size - 1), length(0) {
  15. buffer[0] = '\0';
  16. }
  17. virtual size_t write(uint8_t c);
  18. private:
  19. char *buffer;
  20. int capacity;
  21. int length;
  22. };
  23. }
  24. }