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

Unified Diff: frog/leg/string_validator.dart

Issue 9293006: Refactoring of string literals. Implement static string addition. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
Index: frog/leg/string_validator.dart
diff --git a/frog/leg/string_validator.dart b/frog/leg/string_validator.dart
index f160cd1b1db940395627951eb551b22c1e739027..c83fe6f291e077b4a53352a7f205ea9dd02e0213 100644
--- a/frog/leg/string_validator.dart
+++ b/frog/leg/string_validator.dart
@@ -17,7 +17,7 @@ class StringValidator {
StringValidator(this.listener);
- QuotedString validateQuotedString(Token token) {
+ DartString validateQuotedString(Token token) {
SourceString source = token.value;
StringQuoting quoting = quotingFromString(source);
int leftQuote = quoting.leftQuoteLength;
@@ -29,9 +29,9 @@ class StringValidator {
quoting);
}
- QuotedString validateInterpolationPart(Token token, StringQuoting quoting,
- [bool isFirst = false,
- bool isLast = false]) {
+ DartString validateInterpolationPart(Token token, StringQuoting quoting,
+ [bool isFirst = false,
+ bool isLast = false]) {
SourceString source = token.value;
int leftQuote = 0;
int rightQuote = 0;
@@ -70,22 +70,24 @@ class StringValidator {
/**
* Validates the escape sequences and special characters of a string literal.
- * Returns a QuotedString if valid, and null if not.
+ * Returns a DartString if valid, and null if not.
*/
- QuotedString validateString(Token token,
- int startOffset,
- SourceString string,
- StringQuoting quoting) {
+ DartString validateString(Token token,
+ int startOffset,
+ SourceString string,
+ StringQuoting quoting) {
// We only need to check for invalid x and u escapes, for line
// terminators in non-multiline strings, and for invalid Unicode
// scalar values (either directly or as u-escape values).
int length = 0;
int index = startOffset;
+ bool containsEscape = false;
for(Iterator<int> iter = string.iterator(); iter.hasNext(); length++) {
index++;
int code = iter.next();
if (code === $BACKSLASH) {
if (quoting.raw) continue;
+ containsEscape = true;
if (!iter.hasNext()) {
stringParseError("Incomplete escape sequence",token, index);
return null;
@@ -162,6 +164,10 @@ class StringValidator {
}
}
// String literal successfully validated.
- return new QuotedString(string, quoting, length);
+ if (quoting.raw || !containsEscape) {
+ // A string without escapes could just as well have been raw.
+ return new DartString.rawString(string, length);
+ }
+ return new DartString.escapedString(string, length);
}
}
« no previous file with comments | « frog/leg/ssa/optimize.dart ('k') | frog/leg/tree/nodes.dart » ('j') | frog/leg/tree/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698