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

Unified 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 side-by-side diff with in-line comments
Download patch
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('&lt;');
+ } else if (char == '>'.codeUnitAt(0)) {
+ buffer.write('&gt;');
+ } else if (char == '&'.codeUnitAt(0)) {
+ buffer.write('&amp;');
+ } else if (char == '"'.codeUnitAt(0)) {
+ buffer.write('&quot;');
+ } else if (char == "'".codeUnitAt(0)) {
+ buffer.write('&#x27;');
+ } else if (char == '/'.codeUnitAt(0)) {
+ buffer.write('&#x2F;');
+ } else if (char == 0x2192) {
+ buffer.write('&rarr;');
+ } else if (char == 0x00A0) {
+ buffer.write('&nbsp;');
+ } else {
+ buffer.write('<b>x${char.toRadixString(16)};</b>');
+ }
+ }
+ return buffer.toString();
+}

Powered by Google App Engine
This is Rietveld 408576698