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

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

Issue 1148283010: Remove dart backend (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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
(Empty)
1 part of dart.convert;
2 const HtmlEscape HTML_ESCAPE = const HtmlEscape();
3 class HtmlEscapeMode {final String _name;
4 final bool escapeLtGt;
5 final bool escapeQuot;
6 final bool escapeApos;
7 final bool escapeSlash;
8 static const HtmlEscapeMode UNKNOWN = const HtmlEscapeMode._('unknown', true, t rue, true, true);
9 static const HtmlEscapeMode ATTRIBUTE = const HtmlEscapeMode._('attribute', fal se, true, false, false);
10 static const HtmlEscapeMode ELEMENT = const HtmlEscapeMode._('element', true, f alse, false, true);
11 const HtmlEscapeMode._(this._name, this.escapeLtGt, this.escapeQuot, this.escap eApos, this.escapeSlash);
12 String toString() => _name;
13 }
14 class HtmlEscape extends Converter<String, String> {final HtmlEscapeMode mode;
15 const HtmlEscape([this.mode = HtmlEscapeMode.UNKNOWN]);
16 String convert(String text) {
17 var val = _convert(text, 0, text.length);
18 return val == null ? text : val;
19 }
20 String _convert(String text, int start, int end) {
21 StringBuffer result = null;
22 for (int i = start; i < end; i++) {
23 var ch = text[i];
24 String replace = null;
25 switch (ch) {case '&': replace = '&amp;';
26 break;
27 case '\u00A0': replace = '&nbsp;';
28 break;
29 case '"': if (mode.escapeQuot) replace = '&quot;';
30 break;
31 case "'": if (mode.escapeApos) replace = '&#x27;';
32 break;
33 case '<': if (mode.escapeLtGt) replace = '&lt;';
34 break;
35 case '>': if (mode.escapeLtGt) replace = '&gt;';
36 break;
37 case '/': if (mode.escapeSlash) replace = '&#x2F;';
38 break;
39 }
40 if (replace != null) {
41 if (result == null) result = new StringBuffer(text.substring(start, i));
42 result.write(replace);
43 }
44 else if (result != null) {
45 result.write(ch);
46 }
47 }
48 return result != null ? result.toString() : null;
49 }
50 StringConversionSink startChunkedConversion(Sink<String> sink) {
51 if (sink is! StringConversionSink) {
52 sink = new StringConversionSink.from(sink);
53 }
54 return new _HtmlEscapeSink(this, DEVC$RT.cast(sink, DEVC$RT.type((Sink<String> _) {
55 }
56 ), StringConversionSink, "ImplicitCast", """line 79, column 38 of dart:convert/h tml_escape.dart: """, sink is StringConversionSink, true));
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
« no previous file with comments | « test/dart_codegen/expect/convert/encoding.dart ('k') | test/dart_codegen/expect/convert/json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698