Replace special characters in strings with their escaped versions.
| 754 | // Replace special characters in strings with their escaped versions. |
| 755 | // <https://www.json.org/json-en.html> |
| 756 | std::string EscapeJSONCString(std::string string) { |
| 757 | if (output_type == OutputType::text || output_type == OutputType::html) return string; |
| 758 | std::string out{}; |
| 759 | for (size_t i = 0; i < string.size(); i++) { |
| 760 | char c = string[i]; |
| 761 | char out_c = c; |
| 762 | switch (c) { |
| 763 | case '\"': |
| 764 | case '\\': |
| 765 | out.push_back('\\'); |
| 766 | break; |
| 767 | case '\b': |
| 768 | out.push_back('\\'); |
| 769 | out_c = 'b'; |
| 770 | break; |
| 771 | case '\f': |
| 772 | out.push_back('\\'); |
| 773 | out_c = 'f'; |
| 774 | break; |
| 775 | case '\n': |
| 776 | out.push_back('\\'); |
| 777 | out_c = 'n'; |
| 778 | break; |
| 779 | case '\r': |
| 780 | out.push_back('\\'); |
| 781 | out_c = 'r'; |
| 782 | break; |
| 783 | case '\t': |
| 784 | out.push_back('\\'); |
| 785 | out_c = 't'; |
| 786 | break; |
| 787 | } |
| 788 | out.push_back(out_c); |
| 789 | } |
| 790 | |
| 791 | return out; |
| 792 | } |
| 793 | }; |
| 794 | // Purpose: When a Printer starts an object or array it will automatically indent the output. This isn't |
| 795 | // always desired, requiring a manual decrease of indention. This wrapper facilitates that while also |
nothing calls this directly
no outgoing calls
no test coverage detected