| 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 library csslib.parser; | 5 library csslib.parser; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:source_span/source_span.dart'; | 9 import 'package:source_span/source_span.dart'; |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // because by the time the flag is set one token has already been fetched. | 123 // because by the time the flag is set one token has already been fetched. |
| 124 ..tokenizer.inSelector = true) | 124 ..tokenizer.inSelector = true) |
| 125 .processSelectorGroup(); | 125 .processSelectorGroup(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 String _inputAsString(input) { | 128 String _inputAsString(input) { |
| 129 String source; | 129 String source; |
| 130 | 130 |
| 131 if (input is String) { | 131 if (input is String) { |
| 132 source = input; | 132 source = input; |
| 133 } else if (input is List<int>) { | 133 } else if (input is List) { |
| 134 // TODO(terry): The parse function needs an "encoding" argument and will | 134 // TODO(terry): The parse function needs an "encoding" argument and will |
| 135 // default to whatever encoding CSS defaults to. | 135 // default to whatever encoding CSS defaults to. |
| 136 // | 136 // |
| 137 // Here's some info about CSS encodings: | 137 // Here's some info about CSS encodings: |
| 138 // http://www.w3.org/International/questions/qa-css-charset.en.php | 138 // http://www.w3.org/International/questions/qa-css-charset.en.php |
| 139 // | 139 // |
| 140 // As JMesserly suggests it will probably need a "preparser" html5lib | 140 // As JMesserly suggests it will probably need a "preparser" html5lib |
| 141 // (encoding_parser.dart) that interprets the bytes as ASCII and scans for | 141 // (encoding_parser.dart) that interprets the bytes as ASCII and scans for |
| 142 // @charset. But for now an "encoding" argument would work. Often the | 142 // @charset. But for now an "encoding" argument would work. Often the |
| 143 // HTTP header will indicate the correct encoding. | 143 // HTTP header will indicate the correct encoding. |
| 144 // | 144 // |
| 145 // See encoding helpers at: package:html5lib/lib/src/char_encodings.dart | 145 // See encoding helpers at: package:html5lib/lib/src/char_encodings.dart |
| 146 // These helpers can decode in different formats given an encoding name | 146 // These helpers can decode in different formats given an encoding name |
| 147 // (mostly unicode, ascii, windows-1252 which is html5 default encoding). | 147 // (mostly unicode, ascii, windows-1252 which is html5 default encoding). |
| 148 source = new String.fromCharCodes(input); | 148 source = new String.fromCharCodes(input as List<int>); |
| 149 } else { | 149 } else { |
| 150 // TODO(terry): Support RandomAccessFile using console. | 150 // TODO(terry): Support RandomAccessFile using console. |
| 151 throw new ArgumentError("'source' must be a String or " | 151 throw new ArgumentError("'source' must be a String or " |
| 152 "List<int> (of bytes). RandomAccessFile not supported from this " | 152 "List<int> (of bytes). RandomAccessFile not supported from this " |
| 153 "simple interface"); | 153 "simple interface"); |
| 154 } | 154 } |
| 155 | 155 |
| 156 return source; | 156 return source; |
| 157 } | 157 } |
| 158 | 158 |
| (...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2695 | 2695 |
| 2696 if (replace != null && result == null) { | 2696 if (replace != null && result == null) { |
| 2697 result = new StringBuffer(text.substring(0, i)); | 2697 result = new StringBuffer(text.substring(0, i)); |
| 2698 } | 2698 } |
| 2699 | 2699 |
| 2700 if (result != null) result.write(replace != null ? replace : text[i]); | 2700 if (result != null) result.write(replace != null ? replace : text[i]); |
| 2701 } | 2701 } |
| 2702 | 2702 |
| 2703 return result == null ? text : result.toString(); | 2703 return result == null ? text : result.toString(); |
| 2704 } | 2704 } |
| OLD | NEW |