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

Unified Diff: runtime/vm/object.cc

Issue 12568007: Translate raw strings to regular strings during source code generation. This should hopefully avoid… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 20219)
+++ runtime/vm/object.cc (working copy)
@@ -251,7 +251,9 @@
(value == '\b') ||
(value == '\t') ||
(value == '\v') ||
- (value == '\r'));
+ (value == '\r') ||
+ (value == '\\') ||
+ (value == '$'));
}
@@ -271,6 +273,10 @@
return 'v';
} else if (value == '\r') {
return 'r';
+ } else if (value == '\\') {
+ return '\\';
+ } else if (value == '$') {
+ return '$';
}
UNREACHABLE();
return '\0';
@@ -4844,37 +4850,17 @@
// Handle the current token.
if (curr == Token::kSTRING) {
- bool is_raw_string = false;
bool escape_characters = false;
for (intptr_t i = 0; i < literal.Length(); i++) {
if (IsSpecialCharacter(literal.CharAt(i))) {
escape_characters = true;
}
- // TODO(4995): Temp solution for raw strings, this will break
- // if we saw a string that is not a raw string but has back slashes
- // in it.
- if ((literal.CharAt(i) == '\\')) {
- if ((next != Token::kINTERPOL_VAR) &&
- (next != Token::kINTERPOL_START) &&
- (prev != Token::kINTERPOL_VAR) &&
- (prev != Token::kINTERPOL_END)) {
- is_raw_string = true;
- } else {
- escape_characters = true;
- }
- }
- if ((literal.CharAt(i) == '$')) {
- escape_characters = true;
- }
}
if ((prev != Token::kINTERPOL_VAR) && (prev != Token::kINTERPOL_END)) {
- if (is_raw_string) {
- literals.Add(Symbols::LowercaseR());
- }
literals.Add(Symbols::DoubleQuotes());
}
if (escape_characters) {
- literal = String::EscapeSpecialCharacters(literal, is_raw_string);
+ literal = String::EscapeSpecialCharacters(literal);
literals.Add(literal);
} else {
literals.Add(literal);
@@ -11136,12 +11122,12 @@
}
-RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) {
+RawString* String::EscapeSpecialCharacters(const String& str) {
if (str.IsOneByteString()) {
- return OneByteString::EscapeSpecialCharacters(str, raw_str);
+ return OneByteString::EscapeSpecialCharacters(str);
}
ASSERT(str.IsTwoByteString());
- return TwoByteString::EscapeSpecialCharacters(str, raw_str);
+ return TwoByteString::EscapeSpecialCharacters(str);
}
@@ -11529,16 +11515,13 @@
}
-RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str,
- bool raw_str) {
+RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str) {
intptr_t len = str.Length();
if (len > 0) {
intptr_t num_escapes = 0;
intptr_t index = 0;
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(str, i)) ||
- (!raw_str && (*CharAddr(str, i) == '$')) ||
- (!raw_str && (*CharAddr(str, i) == '\\'))) {
+ if (IsSpecialCharacter(*CharAddr(str, i))) {
num_escapes += 1;
}
}
@@ -11549,14 +11532,6 @@
*(CharAddr(dststr, index)) = '\\';
*(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i));
index += 2;
- } else if (!raw_str && (*CharAddr(str, i) == '$')) {
- *(CharAddr(dststr, index)) = '\\';
- *(CharAddr(dststr, index + 1)) = '$';
- index += 2;
- } else if (!raw_str && (*CharAddr(str, i) == '\\')) {
- *(CharAddr(dststr, index)) = '\\';
- *(CharAddr(dststr, index + 1)) = '\\';
- index += 2;
} else {
*(CharAddr(dststr, index)) = *CharAddr(str, i);
index += 1;
@@ -11718,15 +11693,13 @@
}
-RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str,
- bool raw_str) {
+RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) {
intptr_t len = str.Length();
if (len > 0) {
intptr_t num_escapes = 0;
intptr_t index = 0;
for (intptr_t i = 0; i < len; i++) {
- if (IsSpecialCharacter(*CharAddr(str, i)) ||
- (!raw_str && (*CharAddr(str, i) == '\\'))) {
+ if (IsSpecialCharacter(*CharAddr(str, i))) {
num_escapes += 1;
}
}
@@ -11737,10 +11710,6 @@
*(CharAddr(dststr, index)) = '\\';
*(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i));
index += 2;
- } else if (!raw_str && (*CharAddr(str, i) == '\\')) {
- *(CharAddr(dststr, index)) = '\\';
- *(CharAddr(dststr, index + 1)) = '\\';
- index += 2;
} else {
*(CharAddr(dststr, index)) = *CharAddr(str, i);
index += 1;
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698