From 206fd85f999292861efaa49af2f4b320f89364e1 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 1 Feb 2008 19:34:54 +0000 Subject: [PATCH] Updated StringUtil.toString() to print Objects (associative hashes). Added some comments about inadequacies. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4929 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/StringUtil.as | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index e34e3805b..7c51b6cb4 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -172,16 +172,31 @@ public class StringUtil public static function toString (obj :*) :String { + // TODO: this should be able to detect circular references + + var s :String; if (obj is Array) { var arr :Array = (obj as Array); - var s :String = "Array("; + s = ""; for (var ii :int = 0; ii < arr.length; ii++) { if (ii > 0) { s += ", "; } s += (ii + ": " + toString(arr[ii])); } - return s + ")"; + return "Array(" + s + ")"; + } + + // TODO: maybe do this for any dynamic object? + if (obj != null && obj.constructor == Object) { + s = ""; + for (var prop :String in obj) { + if (s.length > 0) { + s += ", "; + } + s += prop + "=>" + toString(obj[prop]); + } + return "Object(" + s + ")"; } return String(obj);