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

Unified Diff: pkg/matcher/lib/src/utils.dart

Issue 313563002: pkg/matcher: Reverting 36881,36896 while investigating dart2js checked crash (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | « pkg/matcher/lib/src/string_matchers.dart ('k') | pkg/matcher/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/utils.dart
diff --git a/pkg/matcher/lib/src/utils.dart b/pkg/matcher/lib/src/utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c2182c28949b1755d44efea4be99e9dc61befea0
--- /dev/null
+++ b/pkg/matcher/lib/src/utils.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2013, 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 matcher.utils;
+
+/**
+ * Returns the name of the type of [x], or "Unknown" if the type name can't be
+ * determined.
+ */
+String typeName(x) {
+ // dart2js blows up on some objects (e.g. window.navigator).
+ // So we play safe here.
+ try {
+ if (x == null) return "null";
+ var type = x.runtimeType.toString();
+ // TODO(nweiz): if the object's type is private, find a public superclass to
+ // display once there's a portable API to do that.
+ return type.startsWith("_") ? "?" : type;
+ } catch (e) {
+ return "?";
+ }
+}
+
+/**
+ * Returns [source] with any control characters replaced by their escape
+ * sequences.
+ *
+ * This doesn't add quotes to the string, but it does escape single quote
+ * characters so that single quotes can be applied externally.
+ */
+String escapeString(String source) =>
+ source.split("").map(_escapeChar).join("");
+
+/** Return the escaped form of a character [ch]. */
+String _escapeChar(String ch) {
+ if (ch == "'")
+ return "\\'";
+ else if (ch == '\n')
+ return '\\n';
+ else if (ch == '\r')
+ return '\\r';
+ else if (ch == '\t')
+ return '\\t';
+ else
+ return ch;
+}
+
+/** Indent each line in [str] by two spaces. */
+String indent(String str) =>
+ str.replaceAll(new RegExp("^", multiLine: true), " ");
+
+/** A pair of values. */
+class Pair<E, F> {
+ E first;
+ F last;
+
+ Pair(this.first, this.last);
+
+ String toString() => '($first, $last)';
+
+ bool operator ==(other) {
+ if (other is! Pair) return false;
+ return other.first == first && other.last == last;
+ }
+
+ int get hashCode => first.hashCode ^ last.hashCode;
+}
+
« no previous file with comments | « pkg/matcher/lib/src/string_matchers.dart ('k') | pkg/matcher/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698