| OLD | NEW |
| 1 library encoding_parser; | 1 library encoding_parser; |
| 2 | 2 |
| 3 import 'constants.dart'; | 3 import 'constants.dart'; |
| 4 import 'inputstream.dart'; | 4 import 'inputstream.dart'; |
| 5 | 5 |
| 6 // TODO(jmesserly): I converted StopIteration to StateError("No more elements"). | 6 // TODO(jmesserly): I converted StopIteration to StateError("No more elements"). |
| 7 // Seems strange to throw this from outside of an iterator though. | 7 // Seems strange to throw this from outside of an iterator though. |
| 8 /// String-like object with an associated position and various extra methods | 8 /// String-like object with an associated position and various extra methods |
| 9 /// If the position is ever greater than the string length then an exception is | 9 /// If the position is ever greater than the string length then an exception is |
| 10 /// raised. | 10 /// raised. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } else if (attr[0] == "content") { | 193 } else if (attr[0] == "content") { |
| 194 var contentParser = new ContentAttrParser(new EncodingBytes(attr[1])); | 194 var contentParser = new ContentAttrParser(new EncodingBytes(attr[1])); |
| 195 var tentativeEncoding = contentParser.parse(); | 195 var tentativeEncoding = contentParser.parse(); |
| 196 var codec = codecName(tentativeEncoding); | 196 var codec = codecName(tentativeEncoding); |
| 197 if (codec != null) { | 197 if (codec != null) { |
| 198 encoding = codec; | 198 encoding = codec; |
| 199 return false; | 199 return false; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 return true; // unreachable | |
| 204 } | 203 } |
| 205 | 204 |
| 206 bool handlePossibleStartTag() => handlePossibleTag(false); | 205 bool handlePossibleStartTag() => handlePossibleTag(false); |
| 207 | 206 |
| 208 bool handlePossibleEndTag() { | 207 bool handlePossibleEndTag() { |
| 209 data.next(); | 208 data.next(); |
| 210 return handlePossibleTag(true); | 209 return handlePossibleTag(true); |
| 211 } | 210 } |
| 212 | 211 |
| 213 bool handlePossibleTag(bool endTag) { | 212 bool handlePossibleTag(bool endTag) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 if (isSpaceOrAngleBracket(c)) { | 314 if (isSpaceOrAngleBracket(c)) { |
| 316 return [attrName.join(), attrValue.join()]; | 315 return [attrName.join(), attrValue.join()]; |
| 317 } else if (c == null) { | 316 } else if (c == null) { |
| 318 return null; | 317 return null; |
| 319 } else if (isLetter(c)) { | 318 } else if (isLetter(c)) { |
| 320 attrValue.add(c.toLowerCase()); | 319 attrValue.add(c.toLowerCase()); |
| 321 } else { | 320 } else { |
| 322 attrValue.add(c); | 321 attrValue.add(c); |
| 323 } | 322 } |
| 324 } | 323 } |
| 325 return null; // unreachable | |
| 326 } | 324 } |
| 327 } | 325 } |
| 328 | 326 |
| 329 class ContentAttrParser { | 327 class ContentAttrParser { |
| 330 final EncodingBytes data; | 328 final EncodingBytes data; |
| 331 | 329 |
| 332 ContentAttrParser(this.data); | 330 ContentAttrParser(this.data); |
| 333 | 331 |
| 334 String parse() { | 332 String parse() { |
| 335 try { | 333 try { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 return null; | 367 return null; |
| 370 } | 368 } |
| 371 } | 369 } |
| 372 } | 370 } |
| 373 | 371 |
| 374 bool isSpaceOrAngleBracket(String char) { | 372 bool isSpaceOrAngleBracket(String char) { |
| 375 return char == ">" || char == "<" || isWhitespace(char); | 373 return char == ">" || char == "<" || isWhitespace(char); |
| 376 } | 374 } |
| 377 | 375 |
| 378 typedef bool CharPreciate(String char); | 376 typedef bool CharPreciate(String char); |
| OLD | NEW |