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

Side by Side Diff: test/dart_codegen/expect/convert/html_escape.dart

Issue 963593002: Disable formatting and add new-lines to make tests faster. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 part of dart.convert; 1 part of dart.convert;
2 2 const HtmlEscape HTML_ESCAPE = const HtmlEscape();
3 const HtmlEscape HTML_ESCAPE = const HtmlEscape(); 3 class HtmlEscapeMode {final String _name;
4 class HtmlEscapeMode { 4 final bool escapeLtGt;
5 final String _name; 5 final bool escapeQuot;
6 final bool escapeLtGt; 6 final bool escapeApos;
7 final bool escapeQuot; 7 final bool escapeSlash;
8 final bool escapeApos; 8 static const HtmlEscapeMode UNKNOWN = const HtmlEscapeMode._('unknown', true, t rue, true, true);
9 final bool escapeSlash; 9 static const HtmlEscapeMode ATTRIBUTE = const HtmlEscapeMode._('attribute', fal se, true, false, false);
10 static const HtmlEscapeMode UNKNOWN = 10 static const HtmlEscapeMode ELEMENT = const HtmlEscapeMode._('element', true, f alse, false, true);
11 const HtmlEscapeMode._('unknown', true, true, true, true); 11 const HtmlEscapeMode._(this._name, this.escapeLtGt, this.escapeQuot, this.escap eApos, this.escapeSlash);
12 static const HtmlEscapeMode ATTRIBUTE = 12 String toString() => _name;
13 const HtmlEscapeMode._('attribute', false, true, false, false);
14 static const HtmlEscapeMode ELEMENT =
15 const HtmlEscapeMode._('element', true, false, false, true);
16 const HtmlEscapeMode._(this._name, this.escapeLtGt, this.escapeQuot,
17 this.escapeApos, this.escapeSlash);
18 String toString() => _name;
19 } 13 }
20 class HtmlEscape extends Converter<String, String> { 14 class HtmlEscape extends Converter<String, String> {final HtmlEscapeMode mode;
21 final HtmlEscapeMode mode; 15 const HtmlEscape([this.mode = HtmlEscapeMode.UNKNOWN]);
22 const HtmlEscape([this.mode = HtmlEscapeMode.UNKNOWN]); 16 String convert(String text) {
23 String convert(String text) { 17 var val = _convert(text, 0, text.length);
24 var val = _convert(text, 0, text.length); 18 return val == null ? text : val;
25 return val == null ? text : val; 19 }
20 String _convert(String text, int start, int end) {
21 StringBuffer result = null;
22 for (int i = start;
23 i < end;
24 i++) {
25 var ch = text[i];
26 String replace = null;
27 switch (ch) {case '&': replace = '&amp;';
28 break;
29 case '\u00A0': replace = '&nbsp;';
30 break;
31 case '"': if (mode.escapeQuot) replace = '&quot;';
32 break;
33 case "'": if (mode.escapeApos) replace = '&#x27;';
34 break;
35 case '<': if (mode.escapeLtGt) replace = '&lt;';
36 break;
37 case '>': if (mode.escapeLtGt) replace = '&gt;';
38 break;
39 case '/': if (mode.escapeSlash) replace = '&#x2F;';
40 break;
26 } 41 }
27 String _convert(String text, int start, int end) { 42 if (replace != null) {
28 StringBuffer result = null; 43 if (result == null) result = new StringBuffer(text.substring(start, i));
29 for (int i = start; i < end; i++) { 44 result.write(replace);
30 var ch = text[i];
31 String replace = null;
32 switch (ch) {
33 case '&':
34 replace = '&amp;';
35 break;
36 case '\u00A0':
37 replace = '&nbsp;';
38 break;
39 case '"':
40 if (mode.escapeQuot) replace = '&quot;';
41 break;
42 case "'":
43 if (mode.escapeApos) replace = '&#x27;';
44 break;
45 case '<':
46 if (mode.escapeLtGt) replace = '&lt;';
47 break;
48 case '>':
49 if (mode.escapeLtGt) replace = '&gt;';
50 break;
51 case '/':
52 if (mode.escapeSlash) replace = '&#x2F;';
53 break;
54 }
55 if (replace != null) {
56 if (result == null) result = new StringBuffer(text.substring(start, i));
57 result.write(replace);
58 } else if (result != null) {
59 result.write(ch);
60 }
61 }
62 return ((__x6) => DDC$RT.cast(__x6, dynamic, String, "CastGeneral",
63 """line 72, column 12 of dart:convert/html_escape.dart: """,
64 __x6 is String, true))(result != null ? result.toString() : null);
65 } 45 }
66 StringConversionSink startChunkedConversion(Sink<String> sink) { 46 else if (result != null) {
67 if (sink is! StringConversionSink) { 47 result.write(ch);
68 sink = new StringConversionSink.from(sink);
69 }
70 return new _HtmlEscapeSink(this, sink);
71 } 48 }
72 } 49 }
73 class _HtmlEscapeSink extends StringConversionSinkBase { 50 return ((__x6) => DDC$RT.cast(__x6, dynamic, String, "CastGeneral", """line 72, column 12 of dart:convert/html_escape.dart: """, __x6 is String, true))(result != null ? result.toString() : null);
74 final HtmlEscape _escape;
75 final StringConversionSink _sink;
76 _HtmlEscapeSink(this._escape, this._sink);
77 void addSlice(String chunk, int start, int end, bool isLast) {
78 var val = _escape._convert(chunk, start, end);
79 if (val == null) {
80 _sink.addSlice(chunk, start, end, isLast);
81 } else {
82 _sink.add(val);
83 if (isLast) _sink.close();
84 }
85 }
86 void close() => _sink.close();
87 } 51 }
52 StringConversionSink startChunkedConversion(Sink<String> sink) {
53 if (sink is! StringConversionSink) {
54 sink = new StringConversionSink.from(sink);
55 }
56 return new _HtmlEscapeSink(this, sink);
57 }
58 }
59 class _HtmlEscapeSink extends StringConversionSinkBase {final HtmlEscape _escap e;
60 final StringConversionSink _sink;
61 _HtmlEscapeSink(this._escape, this._sink);
62 void addSlice(String chunk, int start, int end, bool isLast) {
63 var val = _escape._convert(chunk, start, end);
64 if (val == null) {
65 _sink.addSlice(chunk, start, end, isLast);
66 }
67 else {
68 _sink.add(val);
69 if (isLast) _sink.close();
70 }
71 }
72 void close() => _sink.close();
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698