Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: pkg/front_end/lib/src/fasta/quote.dart

Issue 2847793002: Update handling of multiline strings to specification. (Closed)
Patch Set: Work around analyzer bug and update status file. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language_kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/quote.dart
diff --git a/pkg/front_end/lib/src/fasta/quote.dart b/pkg/front_end/lib/src/fasta/quote.dart
index 8d9525304f1d57a467dabc86573914029cafcecf..a0624144952c7ac9f67c17a7aacb6dad5b94138d 100644
--- a/pkg/front_end/lib/src/fasta/quote.dart
+++ b/pkg/front_end/lib/src/fasta/quote.dart
@@ -68,7 +68,7 @@ int lengthOfOptionalWhitespacePrefix(String first, int start) {
}
if (code == $TAB || code == $SPACE) continue;
if (code == $CR) {
- if (i + 1 < codeUnits.length && codeUnits[i] == $LF) {
+ if (i + 1 < codeUnits.length && codeUnits[i + 1] == $LF) {
i++;
}
return i + 1;
@@ -140,17 +140,27 @@ String unescape(String string, Quote quote) {
switch (quote) {
case Quote.Single:
case Quote.Double:
+ return !string.contains("\\")
+ ? string
+ : unescapeCodeUnits(string.codeUnits, false);
+
case Quote.MultiLineSingle:
case Quote.MultiLineDouble:
- break;
+ return !string.contains("\\") && !string.contains("\r")
+ ? string
+ : unescapeCodeUnits(string.codeUnits, false);
case Quote.RawSingle:
case Quote.RawDouble:
+ return string;
+
case Quote.RawMultiLineSingle:
case Quote.RawMultiLineDouble:
- return string;
+ return !string.contains("\r")
+ ? string
+ : unescapeCodeUnits(string.codeUnits, true);
}
- return !string.contains("\\") ? string : unescapeCodeUnits(string.codeUnits);
+ return internalError("Unhandled string quote: $quote");
}
const String incompleteSequence = "Incomplete escape sequence.";
@@ -161,7 +171,7 @@ const String invalidCodePoint = "Invalid code point.";
// Note: based on
// [StringValidator.validateString](pkg/compiler/lib/src/string_validator.dart).
-String unescapeCodeUnits(List<int> codeUnits) {
+String unescapeCodeUnits(List<int> codeUnits, bool isRaw) {
// Can't use Uint8List or Uint16List here, the code units may be larger.
List<int> result = new List<int>(codeUnits.length);
int resultOffset = 0;
@@ -171,7 +181,12 @@ String unescapeCodeUnits(List<int> codeUnits) {
for (int i = 0; i < codeUnits.length; i++) {
int code = codeUnits[i];
- if (code == $BACKSLASH) {
+ if (code == $CR) {
+ if (i + 1 < codeUnits.length && codeUnits[i + 1] == $LF) {
+ i++;
+ }
+ code = $LF;
+ } else if (!isRaw && code == $BACKSLASH) {
if (codeUnits.length == ++i) return error(i, incompleteSequence);
code = codeUnits[i];
« no previous file with comments | « no previous file | tests/language/language_kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698