Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Check the validity of string literals. | 5 // Check the validity of string literals. |
| 6 | 6 |
| 7 #library("stringvalidator"); | 7 #library("stringvalidator"); |
| 8 | 8 |
| 9 #import("leg.dart"); | 9 #import("leg.dart"); |
| 10 #import("scanner/scannerlib.dart"); | 10 #import("scanner/scannerlib.dart"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 token.charOffset + leftQuote, | 42 token.charOffset + leftQuote, |
| 43 content, | 43 content, |
| 44 quoting); | 44 quoting); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static StringQuoting quotingFromString(SourceString sourceString) { | 47 static StringQuoting quotingFromString(SourceString sourceString) { |
| 48 Iterator<int> source = sourceString.iterator(); | 48 Iterator<int> source = sourceString.iterator(); |
| 49 bool raw = false; | 49 bool raw = false; |
| 50 int quoteLength = 1; | 50 int quoteLength = 1; |
| 51 int quoteChar = source.next(); | 51 int quoteChar = source.next(); |
| 52 if (quoteChar == $AT) { | 52 // TODO(aprelev@gmail.com) Remove deprecated "quoteChar === $AT ||" below |
|
ahe
2012/09/11 06:04:34
Add : after ). Terminate comment with period.
aam-me
2012/09/12 02:12:38
Done.
| |
| 53 if (quoteChar === $AT || quoteChar === $r) { | |
| 53 raw = true; | 54 raw = true; |
| 54 quoteChar = source.next(); | 55 quoteChar = source.next(); |
| 55 } | 56 } |
| 56 assert(quoteChar === $SQ || quoteChar === $DQ); | 57 assert(quoteChar === $SQ || quoteChar === $DQ); |
| 57 // String has at least one quote. Check it if has three. | 58 // String has at least one quote. Check it if has three. |
| 58 // If it only have two, the string must be an empty string literal, | 59 // If it only have two, the string must be an empty string literal, |
| 59 // and end after the second quote. | 60 // and end after the second quote. |
| 60 bool multiline = false; | 61 bool multiline = false; |
| 61 if (source.hasNext() && source.next() === quoteChar && source.hasNext()) { | 62 if (source.hasNext() && source.next() === quoteChar && source.hasNext()) { |
| 62 int code = source.next(); | 63 int code = source.next(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 179 } |
| 179 } | 180 } |
| 180 // String literal successfully validated. | 181 // String literal successfully validated. |
| 181 if (quoting.raw || !containsEscape) { | 182 if (quoting.raw || !containsEscape) { |
| 182 // A string without escapes could just as well have been raw. | 183 // A string without escapes could just as well have been raw. |
| 183 return new DartString.rawString(string, length); | 184 return new DartString.rawString(string, length); |
| 184 } | 185 } |
| 185 return new DartString.escapedString(string, length); | 186 return new DartString.escapedString(string, length); |
| 186 } | 187 } |
| 187 } | 188 } |
| OLD | NEW |