MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / EscapeJson

Method EscapeJson

tests/gtest/gtest-all.cc:5498–5535  ·  view source on GitHub ↗

Returns an JSON-escaped copy of the input string str.

Source from the content-addressed store, hash-verified

5496
5497// Returns an JSON-escaped copy of the input string str.
5498std::string JsonUnitTestResultPrinter::EscapeJson(const std::string& str) {
5499 Message m;
5500
5501 for (size_t i = 0; i < str.size(); ++i) {
5502 const char ch = str[i];
5503 switch (ch) {
5504 case '\\':
5505 case '"':
5506 case '/':
5507 m << '\\' << ch;
5508 break;
5509 case '\b':
5510 m << "\\b";
5511 break;
5512 case '\t':
5513 m << "\\t";
5514 break;
5515 case '\n':
5516 m << "\\n";
5517 break;
5518 case '\f':
5519 m << "\\f";
5520 break;
5521 case '\r':
5522 m << "\\r";
5523 break;
5524 default:
5525 if (ch < ' ') {
5526 m << "\\u00" << String::FormatByte(static_cast<unsigned char>(ch));
5527 } else {
5528 m << ch;
5529 }
5530 break;
5531 }
5532 }
5533
5534 return m.GetString();
5535}
5536
5537// The following routines generate an JSON representation of a UnitTest
5538// object.

Callers

nothing calls this directly

Calls 2

GetStringMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected