Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: lib/src/encoding_parser.dart

Issue 1971923002: Make package:html strong clean (Closed) Base URL: git@github.com:dart-lang/html.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/css_class_set.dart ('k') | lib/src/list_proxy.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/encoding_parser.dart
diff --git a/lib/src/encoding_parser.dart b/lib/src/encoding_parser.dart
index fd64ff9b01047a9ef880f17d11046e1b5f104246..0b84989ade70f499d80945d61f1ed94e7c68ae8e 100644
--- a/lib/src/encoding_parser.dart
+++ b/lib/src/encoding_parser.dart
@@ -121,6 +121,14 @@ class EncodingBytes {
}
}
+typedef bool _MethodHandler();
+
+class _DispatchEntry {
+ final String pattern;
+ final _MethodHandler handler;
+ _DispatchEntry(this.pattern, this.handler);
+}
+
/// Mini parser for detecting character encoding from meta elements.
class EncodingParser {
final EncodingBytes data;
@@ -133,19 +141,19 @@ class EncodingParser {
String getEncoding() {
final methodDispatch = [
- ["<!--", handleComment],
- ["<meta", handleMeta],
- ["</", handlePossibleEndTag],
- ["<!", handleOther],
- ["<?", handleOther],
- ["<", handlePossibleStartTag]
+ new _DispatchEntry("<!--", handleComment),
+ new _DispatchEntry("<meta", handleMeta),
+ new _DispatchEntry("</", handlePossibleEndTag),
+ new _DispatchEntry("<!", handleOther),
+ new _DispatchEntry("<?", handleOther),
+ new _DispatchEntry("<", handlePossibleStartTag),
];
try {
for (;;) {
for (var dispatch in methodDispatch) {
- if (data.matchBytes(dispatch[0])) {
- var keepParsing = dispatch[1]();
+ if (data.matchBytes(dispatch.pattern)) {
+ var keepParsing = dispatch.handler();
if (keepParsing) break;
// We found an encoding. Stop.
@@ -154,7 +162,7 @@ class EncodingParser {
}
data.position += 1;
}
- } on StateError catch (e) {
+ } on StateError catch (_) {
// Catch this here to match behavior of Python's StopIteration
// TODO(jmesserly): refactor to not use exceptions
}
@@ -352,12 +360,12 @@ class ContentAttrParser {
try {
data.skipUntil(isWhitespace);
return data.slice(oldPosition, data.position);
- } on StateError catch (e) {
+ } on StateError catch (_) {
//Return the whole remaining value
return data.slice(oldPosition);
}
}
- } on StateError catch (e) {
+ } on StateError catch (_) {
return null;
}
}
« no previous file with comments | « lib/src/css_class_set.dart ('k') | lib/src/list_proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698