Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 5516387

Browse files
authored
Drop Pair util class (#255)
1 parent 50837e5 commit 5516387

File tree

4 files changed

+131
-146
lines changed

4 files changed

+131
-146
lines changed

lib/parser.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ class HtmlParser {
248248
return enc == 'text/html' || enc == 'application/xhtml+xml';
249249
} else {
250250
return htmlIntegrationPointElements
251-
.contains(Pair(element.namespaceUri, element.localName));
251+
.contains((element.namespaceUri, element.localName));
252252
}
253253
}
254254

255255
bool isMathMLTextIntegrationPoint(Element element) {
256256
return mathmlTextIntegrationPointElements
257-
.contains(Pair(element.namespaceUri, element.localName));
257+
.contains((element.namespaceUri, element.localName));
258258
}
259259

260260
bool inForeignContent(Token token, int type) {
@@ -3978,7 +3978,7 @@ class ParseError implements SourceSpanException {
39783978
}
39793979

39803980
/// Convenience function to get the pair of namespace and localName.
3981-
Pair<String, String?> getElementNameTuple(Element e) {
3981+
(String, String?) getElementNameTuple(Element e) {
39823982
final ns = e.namespaceUri ?? Namespaces.html;
3983-
return Pair(ns, e.localName);
3983+
return (ns, e.localName);
39843984
}

lib/src/constants.dart

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -258,139 +258,139 @@ class Namespaces {
258258
}
259259
}
260260

261-
const List<Pair<String, String>> scopingElements = [
262-
Pair(Namespaces.html, 'applet'),
263-
Pair(Namespaces.html, 'caption'),
264-
Pair(Namespaces.html, 'html'),
265-
Pair(Namespaces.html, 'marquee'),
266-
Pair(Namespaces.html, 'object'),
267-
Pair(Namespaces.html, 'table'),
268-
Pair(Namespaces.html, 'td'),
269-
Pair(Namespaces.html, 'th'),
270-
Pair(Namespaces.mathml, 'mi'),
271-
Pair(Namespaces.mathml, 'mo'),
272-
Pair(Namespaces.mathml, 'mn'),
273-
Pair(Namespaces.mathml, 'ms'),
274-
Pair(Namespaces.mathml, 'mtext'),
275-
Pair(Namespaces.mathml, 'annotation-xml'),
276-
Pair(Namespaces.svg, 'foreignObject'),
277-
Pair(Namespaces.svg, 'desc'),
278-
Pair(Namespaces.svg, 'title')
261+
const List<(String, String)> scopingElements = [
262+
(Namespaces.html, 'applet'),
263+
(Namespaces.html, 'caption'),
264+
(Namespaces.html, 'html'),
265+
(Namespaces.html, 'marquee'),
266+
(Namespaces.html, 'object'),
267+
(Namespaces.html, 'table'),
268+
(Namespaces.html, 'td'),
269+
(Namespaces.html, 'th'),
270+
(Namespaces.mathml, 'mi'),
271+
(Namespaces.mathml, 'mo'),
272+
(Namespaces.mathml, 'mn'),
273+
(Namespaces.mathml, 'ms'),
274+
(Namespaces.mathml, 'mtext'),
275+
(Namespaces.mathml, 'annotation-xml'),
276+
(Namespaces.svg, 'foreignObject'),
277+
(Namespaces.svg, 'desc'),
278+
(Namespaces.svg, 'title')
279279
];
280280

281281
const formattingElements = [
282-
Pair(Namespaces.html, 'a'),
283-
Pair(Namespaces.html, 'b'),
284-
Pair(Namespaces.html, 'big'),
285-
Pair(Namespaces.html, 'code'),
286-
Pair(Namespaces.html, 'em'),
287-
Pair(Namespaces.html, 'font'),
288-
Pair(Namespaces.html, 'i'),
289-
Pair(Namespaces.html, 'nobr'),
290-
Pair(Namespaces.html, 's'),
291-
Pair(Namespaces.html, 'small'),
292-
Pair(Namespaces.html, 'strike'),
293-
Pair(Namespaces.html, 'strong'),
294-
Pair(Namespaces.html, 'tt'),
295-
Pair(Namespaces.html, '')
282+
(Namespaces.html, 'a'),
283+
(Namespaces.html, 'b'),
284+
(Namespaces.html, 'big'),
285+
(Namespaces.html, 'code'),
286+
(Namespaces.html, 'em'),
287+
(Namespaces.html, 'font'),
288+
(Namespaces.html, 'i'),
289+
(Namespaces.html, 'nobr'),
290+
(Namespaces.html, 's'),
291+
(Namespaces.html, 'small'),
292+
(Namespaces.html, 'strike'),
293+
(Namespaces.html, 'strong'),
294+
(Namespaces.html, 'tt'),
295+
(Namespaces.html, '')
296296
];
297297

298298
const specialElements = [
299-
Pair(Namespaces.html, 'address'),
300-
Pair(Namespaces.html, 'applet'),
301-
Pair(Namespaces.html, 'area'),
302-
Pair(Namespaces.html, 'article'),
303-
Pair(Namespaces.html, 'aside'),
304-
Pair(Namespaces.html, 'base'),
305-
Pair(Namespaces.html, 'basefont'),
306-
Pair(Namespaces.html, 'bgsound'),
307-
Pair(Namespaces.html, 'blockquote'),
308-
Pair(Namespaces.html, 'body'),
309-
Pair(Namespaces.html, 'br'),
310-
Pair(Namespaces.html, 'button'),
311-
Pair(Namespaces.html, 'caption'),
312-
Pair(Namespaces.html, 'center'),
313-
Pair(Namespaces.html, 'col'),
314-
Pair(Namespaces.html, 'colgroup'),
315-
Pair(Namespaces.html, 'command'),
316-
Pair(Namespaces.html, 'dd'),
317-
Pair(Namespaces.html, 'details'),
318-
Pair(Namespaces.html, 'dir'),
319-
Pair(Namespaces.html, 'div'),
320-
Pair(Namespaces.html, 'dl'),
321-
Pair(Namespaces.html, 'dt'),
322-
Pair(Namespaces.html, 'embed'),
323-
Pair(Namespaces.html, 'fieldset'),
324-
Pair(Namespaces.html, 'figure'),
325-
Pair(Namespaces.html, 'footer'),
326-
Pair(Namespaces.html, 'form'),
327-
Pair(Namespaces.html, 'frame'),
328-
Pair(Namespaces.html, 'frameset'),
329-
Pair(Namespaces.html, 'h1'),
330-
Pair(Namespaces.html, 'h2'),
331-
Pair(Namespaces.html, 'h3'),
332-
Pair(Namespaces.html, 'h4'),
333-
Pair(Namespaces.html, 'h5'),
334-
Pair(Namespaces.html, 'h6'),
335-
Pair(Namespaces.html, 'head'),
336-
Pair(Namespaces.html, 'header'),
337-
Pair(Namespaces.html, 'hr'),
338-
Pair(Namespaces.html, 'html'),
339-
Pair(Namespaces.html, 'iframe'),
299+
(Namespaces.html, 'address'),
300+
(Namespaces.html, 'applet'),
301+
(Namespaces.html, 'area'),
302+
(Namespaces.html, 'article'),
303+
(Namespaces.html, 'aside'),
304+
(Namespaces.html, 'base'),
305+
(Namespaces.html, 'basefont'),
306+
(Namespaces.html, 'bgsound'),
307+
(Namespaces.html, 'blockquote'),
308+
(Namespaces.html, 'body'),
309+
(Namespaces.html, 'br'),
310+
(Namespaces.html, 'button'),
311+
(Namespaces.html, 'caption'),
312+
(Namespaces.html, 'center'),
313+
(Namespaces.html, 'col'),
314+
(Namespaces.html, 'colgroup'),
315+
(Namespaces.html, 'command'),
316+
(Namespaces.html, 'dd'),
317+
(Namespaces.html, 'details'),
318+
(Namespaces.html, 'dir'),
319+
(Namespaces.html, 'div'),
320+
(Namespaces.html, 'dl'),
321+
(Namespaces.html, 'dt'),
322+
(Namespaces.html, 'embed'),
323+
(Namespaces.html, 'fieldset'),
324+
(Namespaces.html, 'figure'),
325+
(Namespaces.html, 'footer'),
326+
(Namespaces.html, 'form'),
327+
(Namespaces.html, 'frame'),
328+
(Namespaces.html, 'frameset'),
329+
(Namespaces.html, 'h1'),
330+
(Namespaces.html, 'h2'),
331+
(Namespaces.html, 'h3'),
332+
(Namespaces.html, 'h4'),
333+
(Namespaces.html, 'h5'),
334+
(Namespaces.html, 'h6'),
335+
(Namespaces.html, 'head'),
336+
(Namespaces.html, 'header'),
337+
(Namespaces.html, 'hr'),
338+
(Namespaces.html, 'html'),
339+
(Namespaces.html, 'iframe'),
340340
// Note that image is commented out in the spec as "this isn't an
341341
// element that can end up on the stack, so it doesn't matter,"
342-
Pair(Namespaces.html, 'image'),
343-
Pair(Namespaces.html, 'img'),
344-
Pair(Namespaces.html, 'input'),
345-
Pair(Namespaces.html, 'isindex'),
346-
Pair(Namespaces.html, 'li'),
347-
Pair(Namespaces.html, 'link'),
348-
Pair(Namespaces.html, 'listing'),
349-
Pair(Namespaces.html, 'marquee'),
350-
Pair(Namespaces.html, 'men'),
351-
Pair(Namespaces.html, 'meta'),
352-
Pair(Namespaces.html, 'nav'),
353-
Pair(Namespaces.html, 'noembed'),
354-
Pair(Namespaces.html, 'noframes'),
355-
Pair(Namespaces.html, 'noscript'),
356-
Pair(Namespaces.html, 'object'),
357-
Pair(Namespaces.html, 'ol'),
358-
Pair(Namespaces.html, 'p'),
359-
Pair(Namespaces.html, 'param'),
360-
Pair(Namespaces.html, 'plaintext'),
361-
Pair(Namespaces.html, 'pre'),
362-
Pair(Namespaces.html, 'script'),
363-
Pair(Namespaces.html, 'section'),
364-
Pair(Namespaces.html, 'select'),
365-
Pair(Namespaces.html, 'style'),
366-
Pair(Namespaces.html, 'table'),
367-
Pair(Namespaces.html, 'tbody'),
368-
Pair(Namespaces.html, 'td'),
369-
Pair(Namespaces.html, 'textarea'),
370-
Pair(Namespaces.html, 'tfoot'),
371-
Pair(Namespaces.html, 'th'),
372-
Pair(Namespaces.html, 'thead'),
373-
Pair(Namespaces.html, 'title'),
374-
Pair(Namespaces.html, 'tr'),
375-
Pair(Namespaces.html, 'ul'),
376-
Pair(Namespaces.html, 'wbr'),
377-
Pair(Namespaces.html, 'xmp'),
378-
Pair(Namespaces.svg, 'foreignObject')
342+
(Namespaces.html, 'image'),
343+
(Namespaces.html, 'img'),
344+
(Namespaces.html, 'input'),
345+
(Namespaces.html, 'isindex'),
346+
(Namespaces.html, 'li'),
347+
(Namespaces.html, 'link'),
348+
(Namespaces.html, 'listing'),
349+
(Namespaces.html, 'marquee'),
350+
(Namespaces.html, 'men'),
351+
(Namespaces.html, 'meta'),
352+
(Namespaces.html, 'nav'),
353+
(Namespaces.html, 'noembed'),
354+
(Namespaces.html, 'noframes'),
355+
(Namespaces.html, 'noscript'),
356+
(Namespaces.html, 'object'),
357+
(Namespaces.html, 'ol'),
358+
(Namespaces.html, 'p'),
359+
(Namespaces.html, 'param'),
360+
(Namespaces.html, 'plaintext'),
361+
(Namespaces.html, 'pre'),
362+
(Namespaces.html, 'script'),
363+
(Namespaces.html, 'section'),
364+
(Namespaces.html, 'select'),
365+
(Namespaces.html, 'style'),
366+
(Namespaces.html, 'table'),
367+
(Namespaces.html, 'tbody'),
368+
(Namespaces.html, 'td'),
369+
(Namespaces.html, 'textarea'),
370+
(Namespaces.html, 'tfoot'),
371+
(Namespaces.html, 'th'),
372+
(Namespaces.html, 'thead'),
373+
(Namespaces.html, 'title'),
374+
(Namespaces.html, 'tr'),
375+
(Namespaces.html, 'ul'),
376+
(Namespaces.html, 'wbr'),
377+
(Namespaces.html, 'xmp'),
378+
(Namespaces.svg, 'foreignObject')
379379
];
380380

381381
const htmlIntegrationPointElements = [
382-
Pair(Namespaces.mathml, 'annotaion-xml'),
383-
Pair(Namespaces.svg, 'foreignObject'),
384-
Pair(Namespaces.svg, 'desc'),
385-
Pair(Namespaces.svg, 'title')
382+
(Namespaces.mathml, 'annotaion-xml'),
383+
(Namespaces.svg, 'foreignObject'),
384+
(Namespaces.svg, 'desc'),
385+
(Namespaces.svg, 'title')
386386
];
387387

388388
const mathmlTextIntegrationPointElements = [
389-
Pair(Namespaces.mathml, 'mi'),
390-
Pair(Namespaces.mathml, 'mo'),
391-
Pair(Namespaces.mathml, 'mn'),
392-
Pair(Namespaces.mathml, 'ms'),
393-
Pair(Namespaces.mathml, 'mtext')
389+
(Namespaces.mathml, 'mi'),
390+
(Namespaces.mathml, 'mo'),
391+
(Namespaces.mathml, 'mn'),
392+
(Namespaces.mathml, 'ms'),
393+
(Namespaces.mathml, 'mtext')
394394
];
395395

396396
const spaceCharacters = ' \n\r\t\u000C';

lib/src/treebuilder.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import '../parser.dart' show getElementNameTuple;
1010
import 'constants.dart';
1111
import 'list_proxy.dart';
1212
import 'token.dart';
13-
import 'utils.dart';
1413

1514
/// Open elements in the formatting category, most recent element last.
1615
///
@@ -113,29 +112,29 @@ class TreeBuilder {
113112
final exactNode = target is Node;
114113

115114
var listElements1 = scopingElements;
116-
var listElements2 = const <Pair<String, String>>[];
115+
var listElements2 = const <(String, String)>[];
117116
var invert = false;
118117
if (variant != null) {
119118
switch (variant) {
120119
case 'button':
121-
listElements2 = const [Pair(Namespaces.html, 'button')];
120+
listElements2 = const [(Namespaces.html, 'button')];
122121
break;
123122
case 'list':
124123
listElements2 = const [
125-
Pair(Namespaces.html, 'ol'),
126-
Pair(Namespaces.html, 'ul')
124+
(Namespaces.html, 'ol'),
125+
(Namespaces.html, 'ul')
127126
];
128127
break;
129128
case 'table':
130129
listElements1 = const [
131-
Pair(Namespaces.html, 'html'),
132-
Pair(Namespaces.html, 'table')
130+
(Namespaces.html, 'html'),
131+
(Namespaces.html, 'table')
133132
];
134133
break;
135134
case 'select':
136135
listElements1 = const [
137-
Pair(Namespaces.html, 'optgroup'),
138-
Pair(Namespaces.html, 'option')
136+
(Namespaces.html, 'optgroup'),
137+
(Namespaces.html, 'option')
139138
];
140139
invert = true;
141140
break;

lib/src/utils.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
import 'constants.dart';
22

3-
class Pair<F, S> {
4-
final F first;
5-
final S second;
6-
7-
const Pair(this.first, this.second);
8-
9-
@override
10-
int get hashCode => 37 * first.hashCode + second.hashCode;
11-
12-
@override
13-
bool operator ==(Object other) =>
14-
other is Pair && other.first == first && other.second == second;
15-
}
16-
173
bool startsWithAny(String str, List<String> prefixes) =>
184
prefixes.any(str.startsWith);
195

0 commit comments

Comments
 (0)