Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
762 B

  1. #include "fmt.h"
  2. static void fmt_oct3(char* dest,uint8_t w) {
  3. dest[2]=(char)((w&7)+'0'); w>>=3;
  4. dest[1]=(char)((w&7)+'0'); w>>=3;
  5. dest[0]=(char)((w&7)+'0');
  6. }
  7. size_t fmt_escapecharc(char* dest,uint32_t ch) {
  8. char c;
  9. if (ch>0xff) return 0;
  10. switch (ch) {
  11. case '\a': c='a'; goto doescape;
  12. case '\b': c='b'; goto doescape;
  13. case 0x1b: c='e'; goto doescape;
  14. case '\f': c='f'; goto doescape;
  15. case '\n': c='n'; goto doescape;
  16. case '\r': c='r'; goto doescape;
  17. case '\t': c='t'; goto doescape;
  18. case '\v': c='v'; goto doescape;
  19. case '\\':
  20. c='\\';
  21. doescape:
  22. if (dest) {
  23. dest[0]='\\';
  24. dest[1]=c;
  25. }
  26. return 2;
  27. default:
  28. if (dest) {
  29. dest[0]='\\';
  30. fmt_oct3(dest+1,ch&0xff);
  31. }
  32. return 4;
  33. }
  34. }