diff --git a/src/global.tcl b/src/global.tcl index 56f0738..fc6af4b 100644 --- a/src/global.tcl +++ b/src/global.tcl @@ -123,7 +123,12 @@ namespace eval ::testcl { proc ::testcl::getfield { str delim ind } { log::log debug "GLOBAL::getfield $str $delim $ind invoked" - return [lindex [split $str $delim] [expr {$ind - 1}]] + if { [string len $delim] == 1 } { + return [lindex [split $str $delim] [expr {$ind - 1}]] + } + # See https://gist.github.com/ncimino/5526288 + set mc \x00 + return [lindex [split [string map [list $delim $mc] $str] $mc] [expr {$ind - 1}]] } # testcl::log -- diff --git a/test/test_global.tcl b/test/test_global.tcl index 3d56f89..ce78458 100644 --- a/test/test_global.tcl +++ b/test/test_global.tcl @@ -11,3 +11,12 @@ assertStringEquals [getfield "foo:bar" ":" 0] "" assertStringEquals [getfield "foo:bar" ":" 1] "foo" assertStringEquals [getfield "foo:bar" ":" 2] "bar" assertStringEquals [getfield "foo:bar" ":" 3] "" + +assertStringEquals [getfield "st-str-ts" "str" -1] "" +assertStringEquals [getfield "st-str-ts" "str" 0] "" +assertStringEquals [getfield "st-str-ts" "str" 1] "st-" +assertStringEquals [getfield "st-str-ts" "str" 2] "-ts" +assertStringEquals [getfield "st-str-ts" "str" 3] "" +assertStringEquals [getfield "st-str-ts" "str" 42] "" + +assertStringEquals [getfield "st-str-ts-str-foo" "str" 3] "-foo" \ No newline at end of file