my xfce4 dotfiles
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.

71 lines
1.8 KiB

3 years ago
  1. // Copyright 2019 Roman Perepelitsa.
  2. //
  3. // This file is part of GitStatus.
  4. //
  5. // GitStatus is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GitStatus is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with GitStatus. If not, see <https://www.gnu.org/licenses/>.
  17. #include <cassert>
  18. #include "strings.h"
  19. namespace gitstatus {
  20. void CEscape(std::ostream& strm, const char* begin, const char* end) {
  21. assert(!begin == !end);
  22. if (!begin) return;
  23. for (; begin != end; ++begin) {
  24. const unsigned char c = *begin;
  25. switch (c) {
  26. case '\t':
  27. strm << "\\t";
  28. continue;
  29. case '\n':
  30. strm << "\\n";
  31. continue;
  32. case '\r':
  33. strm << "\\r";
  34. continue;
  35. case '"':
  36. strm << "\\\"";
  37. continue;
  38. case '\'':
  39. strm << "\\'";
  40. continue;
  41. case '\\':
  42. strm << "\\\\";
  43. continue;
  44. }
  45. if (c > 31 && c < 127) {
  46. strm << c;
  47. continue;
  48. }
  49. strm << '\\';
  50. strm << static_cast<char>('0' + ((c >> 6) & 7));
  51. strm << static_cast<char>('0' + ((c >> 3) & 7));
  52. strm << static_cast<char>('0' + ((c >> 0) & 7));
  53. }
  54. }
  55. void Quote(std::ostream& strm, const char* begin, const char* end) {
  56. assert(!begin == !end);
  57. if (!begin) {
  58. strm << "null";
  59. return;
  60. }
  61. strm << '"';
  62. CEscape(strm, begin, end);
  63. strm << '"';
  64. }
  65. } // namespace gitstatus