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

Unified Diff: runtime/observatory/lib/utils.dart

Issue 2291233002: Converted Observatory instance-view element (Closed)
Patch Set: Addressed comments Created 4 years, 4 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
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/observatory_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/observatory/lib/utils.dart
diff --git a/runtime/observatory/lib/utils.dart b/runtime/observatory/lib/utils.dart
index b8b5bb33bd9ff998e016a549cb417c29c2a89346..8796e3d61c1dce1c3ac5e242425e5d15439d8028 100644
--- a/runtime/observatory/lib/utils.dart
+++ b/runtime/observatory/lib/utils.dart
@@ -157,6 +157,32 @@ class Utils {
formatMillis(x.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND);
static bool runningInJavaScript() => identical(1.0, 1);
+
+ static formatStringAsLiteral(String value, [bool wasTruncated=false]) {
+ var result = new List();
+ result.add("'".codeUnitAt(0));
+ for (int codeUnit in value.codeUnits) {
+ if (codeUnit == '\n'.codeUnitAt(0)) result.addAll('\\n'.codeUnits);
+ else if (codeUnit == '\r'.codeUnitAt(0)) result.addAll('\\r'.codeUnits);
+ else if (codeUnit == '\f'.codeUnitAt(0)) result.addAll('\\f'.codeUnits);
+ else if (codeUnit == '\b'.codeUnitAt(0)) result.addAll('\\b'.codeUnits);
+ else if (codeUnit == '\t'.codeUnitAt(0)) result.addAll('\\t'.codeUnits);
+ else if (codeUnit == '\v'.codeUnitAt(0)) result.addAll('\\v'.codeUnits);
+ else if (codeUnit == '\$'.codeUnitAt(0)) result.addAll('\\\$'.codeUnits);
+ else if (codeUnit == '\\'.codeUnitAt(0)) result.addAll('\\\\'.codeUnits);
+ else if (codeUnit == "'".codeUnitAt(0)) result.addAll("'".codeUnits);
+ else if (codeUnit < 32) {
+ var escapeSequence = "\\u" + codeUnit.toRadixString(16).padLeft(4, "0");
+ result.addAll(escapeSequence.codeUnits);
+ } else result.add(codeUnit);
+ }
+ if (wasTruncated) {
+ result.addAll("...".codeUnits);
+ } else {
+ result.add("'".codeUnitAt(0));
+ }
+ return new String.fromCharCodes(result);
+ }
}
/// A [Task] that can be scheduled on the Dart event queue.
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/observatory_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698