From 1248c23c81e5ca81fc0118a9d51dea7300dd6c0d Mon Sep 17 00:00:00 2001 From: mattirn Date: Sun, 10 May 2020 09:38:03 +0200 Subject: [PATCH] jline-groovy: improved object to string conversion --- demo/src/main/scripts/gron.nanorc | 2 +- groovy/src/main/groovy/org/jline/groovy/Utils.groovy | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/demo/src/main/scripts/gron.nanorc b/demo/src/main/scripts/gron.nanorc index 86231fdef..390559ad9 100644 --- a/demo/src/main/scripts/gron.nanorc +++ b/demo/src/main/scripts/gron.nanorc @@ -5,7 +5,7 @@ color brightblue "\<[-]?[0-9]*([Ee][+-]?[0-9]+)?\>" "\<[-]?[0](\.[0-9]+)?\>" color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'|[a-zA-Z]+[a-zA-Z0-9]*" color cyan "\" color brightcyan "\<(true|false)\>" -color brightyellow "\"(\\"|[^"])*\"[[:space:]]*:" "'(\'|[^'])*'[[:space:]]*:" "[a-zA-Z0-9]*[[:space:]]*:" +color brightyellow "\"(\\"|[^"])*\"\s*:" "'(\'|[^'])*'\s*:" "(\[|,)\s*[a-zA-Z0-9]*\s*:" color magenta "\\u[0-9a-fA-F]{4}|\\[bfnrt'"/\\]" color ,green "[[:space:]]+$" color ,red " + +| + +" \ No newline at end of file diff --git a/groovy/src/main/groovy/org/jline/groovy/Utils.groovy b/groovy/src/main/groovy/org/jline/groovy/Utils.groovy index 0b0d5ed86..f90ad3f3a 100644 --- a/groovy/src/main/groovy/org/jline/groovy/Utils.groovy +++ b/groovy/src/main/groovy/org/jline/groovy/Utils.groovy @@ -20,7 +20,14 @@ public class Utils { private Utils() {} static String toString(Object object) { - object != null ? object.toString() : 'null' + if (object == null) { + return 'null' + } else if (object instanceof Collection) { + return object.toListString() + } else if (object instanceof Map) { + return object.toMapString() + } + object.toString() } static Object toObject(String json) {