OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.quote; | 5 library fasta.quote; |
6 | 6 |
7 import 'errors.dart' show inputError, internalError; | 7 import 'errors.dart' show inputError, internalError; |
8 | 8 |
9 import 'scanner/characters.dart' | 9 import 'scanner/characters.dart' |
10 show | 10 show |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 return unescape(first.substring(firstQuoteLength(first, quote)), quote); | 123 return unescape(first.substring(firstQuoteLength(first, quote)), quote); |
124 } | 124 } |
125 | 125 |
126 String unescapeLastStringPart(String last, Quote quote) { | 126 String unescapeLastStringPart(String last, Quote quote) { |
127 return unescape( | 127 return unescape( |
128 last.substring(0, last.length - lastQuoteLength(quote)), quote); | 128 last.substring(0, last.length - lastQuoteLength(quote)), quote); |
129 } | 129 } |
130 | 130 |
131 String unescapeString(String string) { | 131 String unescapeString(String string) { |
132 Quote quote = analyzeQuote(string); | 132 Quote quote = analyzeQuote(string); |
133 return unescape( | 133 int startIndex = firstQuoteLength(string, quote); |
134 string.substring(firstQuoteLength(string, quote), | 134 if (startIndex == string.length) { |
135 string.length - lastQuoteLength(quote)), | 135 return ''; |
136 quote); | 136 } |
137 int endIndex = string.length - lastQuoteLength(quote); | |
138 return unescape(string.substring(startIndex, endIndex), quote); | |
ahe
2017/05/29 15:05:30
Same question.
| |
137 } | 139 } |
138 | 140 |
139 String unescape(String string, Quote quote) { | 141 String unescape(String string, Quote quote) { |
140 switch (quote) { | 142 switch (quote) { |
141 case Quote.Single: | 143 case Quote.Single: |
142 case Quote.Double: | 144 case Quote.Double: |
143 return !string.contains("\\") | 145 return !string.contains("\\") |
144 ? string | 146 ? string |
145 : unescapeCodeUnits(string.codeUnits, false); | 147 : unescapeCodeUnits(string.codeUnits, false); |
146 | 148 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 } | 247 } |
246 } else { | 248 } else { |
247 // Nothing, escaped character is passed through; | 249 // Nothing, escaped character is passed through; |
248 } | 250 } |
249 if (code > 0x10FFFF) return error(i, invalidCodePoint); | 251 if (code > 0x10FFFF) return error(i, invalidCodePoint); |
250 } | 252 } |
251 result[resultOffset++] = code; | 253 result[resultOffset++] = code; |
252 } | 254 } |
253 return new String.fromCharCodes(result, 0, resultOffset); | 255 return new String.fromCharCodes(result, 0, resultOffset); |
254 } | 256 } |
OLD | NEW |