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

Side by Side Diff: runtime/bin/vmservice/observatory/lib/src/elements/observatory_element.dart

Issue 542363003: Don't double-escape in strings in the VM Service, and don't use \u0000 to determine the string lengt (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library observatory_element; 5 library observatory_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'package:observatory/app.dart'; 9 import 'package:observatory/app.dart';
10 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 String formatSize(int bytes) => Utils.formatSize(bytes); 105 String formatSize(int bytes) => Utils.formatSize(bytes);
106 106
107 String fileAndLine(Map frame) { 107 String fileAndLine(Map frame) {
108 var file = frame['script'].name; 108 var file = frame['script'].name;
109 var shortFile = file.substring(file.lastIndexOf('/') + 1); 109 var shortFile = file.substring(file.lastIndexOf('/') + 1);
110 return "${shortFile}:${frame['line']}"; 110 return "${shortFile}:${frame['line']}";
111 } 111 }
112 112
113 int parseInt(String value) => int.parse(value); 113 int parseInt(String value) => int.parse(value);
114
115 String asStringLiteral(String value, [bool wasTruncated=false]) {
116 var result = new List();
117 result.add("'".codeUnitAt(0));
turnidge 2014/09/09 16:12:31 I like the change to single quotes.
118 for (int codeUnit in value.codeUnits) {
119 if (codeUnit == '\n'.codeUnitAt(0)) result.addAll('\\n'.codeUnits);
120 else if (codeUnit == '\r'.codeUnitAt(0)) result.addAll('\\r'.codeUnits);
121 else if (codeUnit == '\f'.codeUnitAt(0)) result.addAll('\\f'.codeUnits);
122 else if (codeUnit == '\b'.codeUnitAt(0)) result.addAll('\\b'.codeUnits);
123 else if (codeUnit == '\t'.codeUnitAt(0)) result.addAll('\\t'.codeUnits);
124 else if (codeUnit == '\v'.codeUnitAt(0)) result.addAll('\\v'.codeUnits);
125 else if (codeUnit == '\$'.codeUnitAt(0)) result.addAll('\\\$'.codeUnits);
126 else if (codeUnit == '\\'.codeUnitAt(0)) result.addAll('\\\\'.codeUnits);
127 else if (codeUnit == "'".codeUnitAt(0)) result.addAll("'".codeUnits);
128 else if (codeUnit < 32) result.addAll("\\u$codeUnit".codeUnits);
129 else result.add(codeUnit);
turnidge 2014/09/09 16:12:31 A switch statement might be more idiomatic here.
130 }
131 if (wasTruncated) {
132 result.addAll("...".codeUnits);
133 } else {
134 result.add("'".codeUnitAt(0));
135 }
136 return new String.fromCharCodes(result);
137 }
114 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698