From b36c006a01c2409c44887d80e3c48d83323bc83a Mon Sep 17 00:00:00 2001 From: pk19604014 <95385881+pk19604014@users.noreply.github.com> Date: Wed, 18 May 2022 11:57:00 -0400 Subject: [PATCH] Change proto_to_carbon to use \x for escaping in string literals to be compatible with Carbon string parsing (#1266) --- common/fuzzing/proto_to_carbon.cpp | 2 +- explorer/testdata/string/hex.carbon | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/fuzzing/proto_to_carbon.cpp b/common/fuzzing/proto_to_carbon.cpp index 60878aad9633..d53c6cd29045 100644 --- a/common/fuzzing/proto_to_carbon.cpp +++ b/common/fuzzing/proto_to_carbon.cpp @@ -45,7 +45,7 @@ static auto IdentifierToCarbon(std::string_view s, llvm::raw_ostream& out) static auto StringLiteralToCarbon(std::string_view s, llvm::raw_ostream& out) { out << '"'; - out.write_escaped(s); + out.write_escaped(s, /*UseHexEscapes=*/true); out << '"'; } diff --git a/explorer/testdata/string/hex.carbon b/explorer/testdata/string/hex.carbon index 3fd0cc18acea..173edd6a8619 100644 --- a/explorer/testdata/string/hex.carbon +++ b/explorer/testdata/string/hex.carbon @@ -12,12 +12,12 @@ package ExplorerTest api; fn CompareStr(s: String) -> i32 { - if (s == "str;") { + if (s == "str;\x07") { return 0; } return 1; } fn Main() -> i32 { - return CompareStr("\x73\x74\x72\x3B"); + return CompareStr("\x73\x74\x72\x3B\x07"); }