| OLD | NEW |
| 1 library encoding_parser; | 1 library encoding_parser; |
| 2 | 2 |
| 3 import 'dart:collection'; | 3 import 'dart:collection'; |
| 4 import 'constants.dart'; | 4 import 'constants.dart'; |
| 5 import 'inputstream.dart'; | 5 import 'inputstream.dart'; |
| 6 | 6 |
| 7 // TODO(jmesserly): I converted StopIteration to StateError("No more elements"). | 7 // TODO(jmesserly): I converted StopIteration to StateError("No more elements"). |
| 8 // Seems strange to throw this from outside of an iterator though. | 8 // Seems strange to throw this from outside of an iterator though. |
| 9 /** | 9 /** |
| 10 * String-like object with an associated position and various extra methods | 10 * String-like object with an associated position and various extra methods |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } else if (attr[0] == "content") { | 197 } else if (attr[0] == "content") { |
| 198 var contentParser = new ContentAttrParser(new EncodingBytes(attr[1])); | 198 var contentParser = new ContentAttrParser(new EncodingBytes(attr[1])); |
| 199 var tentativeEncoding = contentParser.parse(); | 199 var tentativeEncoding = contentParser.parse(); |
| 200 var codec = codecName(tentativeEncoding); | 200 var codec = codecName(tentativeEncoding); |
| 201 if (codec != null) { | 201 if (codec != null) { |
| 202 encoding = codec; | 202 encoding = codec; |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 return true; // unreachable |
| 207 } | 208 } |
| 208 | 209 |
| 209 bool handlePossibleStartTag() => handlePossibleTag(false); | 210 bool handlePossibleStartTag() => handlePossibleTag(false); |
| 210 | 211 |
| 211 bool handlePossibleEndTag() { | 212 bool handlePossibleEndTag() { |
| 212 data.next(); | 213 data.next(); |
| 213 return handlePossibleTag(true); | 214 return handlePossibleTag(true); |
| 214 } | 215 } |
| 215 | 216 |
| 216 bool handlePossibleTag(bool endTag) { | 217 bool handlePossibleTag(bool endTag) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if (isSpaceOrAngleBracket(c)) { | 321 if (isSpaceOrAngleBracket(c)) { |
| 321 return [attrName.join(), attrValue.join()]; | 322 return [attrName.join(), attrValue.join()]; |
| 322 } else if (c == null) { | 323 } else if (c == null) { |
| 323 return null; | 324 return null; |
| 324 } else if (isLetter(c)) { | 325 } else if (isLetter(c)) { |
| 325 attrValue.add(c.toLowerCase()); | 326 attrValue.add(c.toLowerCase()); |
| 326 } else { | 327 } else { |
| 327 attrValue.add(c); | 328 attrValue.add(c); |
| 328 } | 329 } |
| 329 } | 330 } |
| 331 return null; // unreachable |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 | 335 |
| 334 class ContentAttrParser { | 336 class ContentAttrParser { |
| 335 final EncodingBytes data; | 337 final EncodingBytes data; |
| 336 | 338 |
| 337 ContentAttrParser(this.data); | 339 ContentAttrParser(this.data); |
| 338 | 340 |
| 339 String parse() { | 341 String parse() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 } | 379 } |
| 378 | 380 |
| 379 | 381 |
| 380 bool isSpaceOrAngleBracket(String char) { | 382 bool isSpaceOrAngleBracket(String char) { |
| 381 return char == ">" || char == "<" || isWhitespace(char); | 383 return char == ">" || char == "<" || isWhitespace(char); |
| 382 } | 384 } |
| 383 | 385 |
| 384 typedef bool CharPreciate(String char); | 386 typedef bool CharPreciate(String char); |
| OLD | NEW |