| 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 int startIndex = firstQuoteLength(string, quote); | 133 return unescape( |
| 134 if (startIndex == string.length) { | 134 string.substring(firstQuoteLength(string, quote), |
| 135 return ''; | 135 string.length - lastQuoteLength(quote)), |
| 136 } | 136 quote); |
| 137 int endIndex = string.length - lastQuoteLength(quote); | |
| 138 return unescape(string.substring(startIndex, endIndex), quote); | |
| 139 } | 137 } |
| 140 | 138 |
| 141 String unescape(String string, Quote quote) { | 139 String unescape(String string, Quote quote) { |
| 142 switch (quote) { | 140 switch (quote) { |
| 143 case Quote.Single: | 141 case Quote.Single: |
| 144 case Quote.Double: | 142 case Quote.Double: |
| 145 return !string.contains("\\") | 143 return !string.contains("\\") |
| 146 ? string | 144 ? string |
| 147 : unescapeCodeUnits(string.codeUnits, false); | 145 : unescapeCodeUnits(string.codeUnits, false); |
| 148 | 146 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 245 } |
| 248 } else { | 246 } else { |
| 249 // Nothing, escaped character is passed through; | 247 // Nothing, escaped character is passed through; |
| 250 } | 248 } |
| 251 if (code > 0x10FFFF) return error(i, invalidCodePoint); | 249 if (code > 0x10FFFF) return error(i, invalidCodePoint); |
| 252 } | 250 } |
| 253 result[resultOffset++] = code; | 251 result[resultOffset++] = code; |
| 254 } | 252 } |
| 255 return new String.fromCharCodes(result, 0, resultOffset); | 253 return new String.fromCharCodes(result, 0, resultOffset); |
| 256 } | 254 } |
| OLD | NEW |