MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Tools / EscapeJSONCString

Method EscapeJSONCString

vulkaninfo/outputprinter.h:756–792  ·  view source on GitHub ↗

Replace special characters in strings with their escaped versions.

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected