escstring.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <stdio.h>
  2. int main(int argc, char* argv[])
  3. {
  4. char c;
  5. putchar('"');
  6. while ((c = getchar()) != EOF) {
  7. switch (c) {
  8. case 0x08:
  9. putchar('\\');
  10. putchar('b');
  11. break;
  12. case 0x0a:
  13. putchar('\\');
  14. putchar('n');
  15. break;
  16. case 0x0c:
  17. putchar('\\');
  18. putchar('f');
  19. break;
  20. case 0x0d:
  21. putchar('\\');
  22. putchar('r');
  23. break;
  24. case 0x09:
  25. putchar('\\');
  26. putchar('t');
  27. break;
  28. case '"':
  29. case '\\':
  30. case 0x00:
  31. case 0x01:
  32. case 0x02:
  33. case 0x03:
  34. case 0x04:
  35. case 0x05:
  36. case 0x06:
  37. case 0x07:
  38. case 0x0b:
  39. case 0x0e:
  40. case 0x0f:
  41. case 0x10:
  42. case 0x11:
  43. case 0x12:
  44. case 0x13:
  45. case 0x14:
  46. case 0x15:
  47. case 0x16:
  48. case 0x17:
  49. case 0x18:
  50. case 0x19:
  51. case 0x1a:
  52. case 0x1b:
  53. case 0x1c:
  54. case 0x1d:
  55. case 0x1e:
  56. case 0x1f:
  57. putchar('\\');
  58. default:
  59. putchar(c);
  60. }
  61. }
  62. putchar('"');
  63. }