MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ParseStringLiteral

Function ParseStringLiteral

internal/strings.cc:591–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591absl::StatusOr<std::string> ParseStringLiteral(absl::string_view str) {
592 std::string out;
593 bool is_string_literal = MayBeStringLiteral(str);
594 bool is_raw_string_literal = MayBeRawStringLiteral(str);
595 if (!is_string_literal && !is_raw_string_literal) {
596 return absl::InvalidArgumentError("Invalid string literal");
597 }
598
599 absl::string_view copy_str = str;
600 if (is_raw_string_literal) {
601 // Strip off the prefix 'r' from the raw string content before parsing.
602 copy_str = absl::ClippedSubstr(copy_str, 1);
603 }
604
605 bool is_triple_quoted = MayBeTripleQuotedString(copy_str);
606 // Starts after the opening quotes {""", '''} or {", '}.
607 int quotes_length = is_triple_quoted ? 3 : 1;
608 absl::string_view quotes = copy_str.substr(0, quotes_length);
609 copy_str = absl::ClippedSubstr(copy_str, quotes_length);
610 std::string error;
611 if (!UnescapeInternal(copy_str, quotes, is_raw_string_literal, false, &out,
612 &error)) {
613 return absl::InvalidArgumentError(
614 absl::StrCat("Invalid string literal: ", error));
615 }
616 return out;
617}
618
619absl::StatusOr<std::string> ParseBytesLiteral(absl::string_view str) {
620 std::string out;

Callers 4

visitStringMethod · 0.85
TestQuotedStringFunction · 0.85
TestParseStringFunction · 0.85
TestInvalidStringFunction · 0.85

Calls 4

MayBeStringLiteralFunction · 0.85
MayBeRawStringLiteralFunction · 0.85
MayBeTripleQuotedStringFunction · 0.85
UnescapeInternalFunction · 0.85

Tested by 3

TestQuotedStringFunction · 0.68
TestParseStringFunction · 0.68
TestInvalidStringFunction · 0.68