Chromium Code Reviews| Index: pkg/analysis_server/lib/src/status/utilities.dart |
| diff --git a/pkg/analysis_server/lib/src/status/utilities.dart b/pkg/analysis_server/lib/src/status/utilities.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e532f7c496994d234985139e967de2ea869c275c |
| --- /dev/null |
| +++ b/pkg/analysis_server/lib/src/status/utilities.dart |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library analysis_server.src.status.utilities; |
| + |
| +/** |
| + * Encode the characters in the given [string] so that they are safe for |
| + * inclusion in HTML. |
| + */ |
| +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
|
| + StringBuffer buffer = new StringBuffer(); |
| + for (int i = 0; i < string.length; i++) { |
| + int char = string.codeUnitAt(i); |
| + if ((char >= 'a'.codeUnitAt(0) && char <= 'z'.codeUnitAt(0)) || |
| + (char >= 'A'.codeUnitAt(0) && char <= 'Z'.codeUnitAt(0)) || |
| + (char >= '0'.codeUnitAt(0) && char <= '9'.codeUnitAt(0)) || |
| + char == '_'.codeUnitAt(0) || |
| + char == '#'.codeUnitAt(0) || |
| + char == ','.codeUnitAt(0) || |
| + char == '.'.codeUnitAt(0) || |
| + char == ';'.codeUnitAt(0) || |
| + char == ':'.codeUnitAt(0) || |
| + char == '('.codeUnitAt(0) || |
| + char == ')'.codeUnitAt(0) || |
| + char == '['.codeUnitAt(0) || |
| + char == ']'.codeUnitAt(0) || |
| + char == '{'.codeUnitAt(0) || |
| + char == '}'.codeUnitAt(0) || |
| + char == ' '.codeUnitAt(0) || |
| + char == '='.codeUnitAt(0) || |
| + char == '+'.codeUnitAt(0) || |
| + char == '-'.codeUnitAt(0) || |
| + char == '*'.codeUnitAt(0) || |
| + char == '%'.codeUnitAt(0)) { |
| + buffer.writeCharCode(char); |
| + } else if (char == '<'.codeUnitAt(0)) { |
| + buffer.write('<'); |
| + } else if (char == '>'.codeUnitAt(0)) { |
| + buffer.write('>'); |
| + } else if (char == '&'.codeUnitAt(0)) { |
| + buffer.write('&'); |
| + } else if (char == '"'.codeUnitAt(0)) { |
| + buffer.write('"'); |
| + } else if (char == "'".codeUnitAt(0)) { |
| + buffer.write('''); |
| + } else if (char == '/'.codeUnitAt(0)) { |
| + buffer.write('/'); |
| + } else if (char == 0x2192) { |
| + buffer.write('→'); |
| + } else if (char == 0x00A0) { |
| + buffer.write(' '); |
| + } else { |
| + buffer.write('<b>x${char.toRadixString(16)};</b>'); |
| + } |
| + } |
| + return buffer.toString(); |
| +} |