[RFA,testsuite,2/5] Introduce build_kv_pairs
Commit Message
Hi,
This patch is a simple utility function to build lists of key/value
pairs. It is used by subsequent patches.
Keith
testsuite/ChangeLog
2014-04-15 Keith Seitz <keiths@redhat.com>
* lib/mi-support.exp (mi_build_kv_pairs): New procedure.
Comments
>>>>> "Keith" == Keith Seitz <keiths@redhat.com> writes:
Keith> 2014-04-15 Keith Seitz <keiths@redhat.com>
Keith> * lib/mi-support.exp (mi_build_kv_pairs): New procedure.
Ok.
Tom
@@ -2354,3 +2354,25 @@ proc mi_walk_varobj_tree {language tree \
mi_varobj_tree_test_children_callback}} {
::varobj_tree::walk_tree $language $tree $callback
}
+
+# Build a list of key-value pairs given by the list ATTR_LIST. Flatten
+# this list using the optional JOINER, a comma by default.
+#
+# The list must contain an even number of elements, which are the key-value
+# pairs. Each value will be surrounded by quotes, according to the grammar,
+# except if the value starts with \[ or \{, when the quotes will be omitted.
+#
+# Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
+# returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
+proc mi_build_kv_pairs {attr_list {joiner ,}} {
+ set l {}
+ foreach {var value} $attr_list {
+ if {[string range $value 0 1] == "\\\["
+ || [string range $value 0 1] == "\\\{"} {
+ lappend l "$var=$value"
+ } else {
+ lappend l "$var=\"$value\""
+ }
+ }
+ return "[join $l $joiner]"
+}