Download the file
  1. #include "formatter.h"
  2. #include "Print.h"
  3.  
  4. void Formatter::zero() {
  5. offset = 0;
  6. for (int i=0; i<BUFLEN; i++)
  7. buffer[i] = '\0';
  8. }
  9.  
  10. size_t Formatter::write(uint8_t c) {
  11. if (offset < BUFLEN - 1)
  12. buffer[offset++] = c;
  13. return 1;
  14. }
  15.  
  16. void Formatter::align_right(uint8_t width) {
  17. if (width < offset) return;
  18. int8_t d = width-offset;
  19. for (int8_t i=offset-1; i>=0; i--)
  20. buffer[i+d] = buffer[i];
  21. for (int8_t i=d-1; i>=0; i--)
  22. buffer[i] = ' ';
  23. }
  24. // vim:ft=arduino
  25.