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

Unified Diff: packages/html/lib/src/encoding_parser.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 | « packages/html/lib/src/css_class_set.dart ('k') | packages/html/lib/src/list_proxy.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/html/lib/src/encoding_parser.dart
diff --git a/packages/html/lib/src/encoding_parser.dart b/packages/html/lib/src/encoding_parser.dart
index fd64ff9b01047a9ef880f17d11046e1b5f104246..9da260bed305e3303b9381a0e9bd5888e50a98be 100644
--- a/packages/html/lib/src/encoding_parser.dart
+++ b/packages/html/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
}
@@ -192,7 +200,6 @@ class EncodingParser {
}
}
}
- return true; // unreachable
}
bool handlePossibleStartTag() => handlePossibleTag(false);
@@ -314,7 +321,6 @@ class EncodingParser {
attrValue.add(c);
}
}
- return null; // unreachable
}
}
@@ -352,12 +358,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 | « packages/html/lib/src/css_class_set.dart ('k') | packages/html/lib/src/list_proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698