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

Side by Side Diff: pkg/analysis_server/lib/src/status/utilities.dart

Issue 840953008: Alternate status page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Sorted and formatted Created 5 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analysis_server.src.status.utilities;
6
7 /**
8 * Encode the characters in the given [string] so that they are safe for
9 * inclusion in HTML.
10 */
11 String encodeHtml(String string) {
Paul Berry 2015/01/20 17:28:11 I don't believe this function is necessary. It sh
Brian Wilkerson 2015/01/20 17:46:34 I tried that, but it failed to encode the right-ar
12 StringBuffer buffer = new StringBuffer();
13 for (int i = 0; i < string.length; i++) {
14 int char = string.codeUnitAt(i);
15 if ((char >= 'a'.codeUnitAt(0) && char <= 'z'.codeUnitAt(0)) ||
16 (char >= 'A'.codeUnitAt(0) && char <= 'Z'.codeUnitAt(0)) ||
17 (char >= '0'.codeUnitAt(0) && char <= '9'.codeUnitAt(0)) ||
18 char == '_'.codeUnitAt(0) ||
19 char == '#'.codeUnitAt(0) ||
20 char == ','.codeUnitAt(0) ||
21 char == '.'.codeUnitAt(0) ||
22 char == ';'.codeUnitAt(0) ||
23 char == ':'.codeUnitAt(0) ||
24 char == '('.codeUnitAt(0) ||
25 char == ')'.codeUnitAt(0) ||
26 char == '['.codeUnitAt(0) ||
27 char == ']'.codeUnitAt(0) ||
28 char == '{'.codeUnitAt(0) ||
29 char == '}'.codeUnitAt(0) ||
30 char == ' '.codeUnitAt(0) ||
31 char == '='.codeUnitAt(0) ||
32 char == '+'.codeUnitAt(0) ||
33 char == '-'.codeUnitAt(0) ||
34 char == '*'.codeUnitAt(0) ||
35 char == '%'.codeUnitAt(0)) {
36 buffer.writeCharCode(char);
37 } else if (char == '<'.codeUnitAt(0)) {
38 buffer.write('&lt;');
39 } else if (char == '>'.codeUnitAt(0)) {
40 buffer.write('&gt;');
41 } else if (char == '&'.codeUnitAt(0)) {
42 buffer.write('&amp;');
43 } else if (char == '"'.codeUnitAt(0)) {
44 buffer.write('&quot;');
45 } else if (char == "'".codeUnitAt(0)) {
46 buffer.write('&#x27;');
47 } else if (char == '/'.codeUnitAt(0)) {
48 buffer.write('&#x2F;');
49 } else if (char == 0x2192) {
50 buffer.write('&rarr;');
51 } else if (char == 0x00A0) {
52 buffer.write('&nbsp;');
53 } else {
54 buffer.write('<b>x${char.toRadixString(16)};</b>');
55 }
56 }
57 return buffer.toString();
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698