Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Fix landro#70 : getfield implementation splits only on character and …
Browse files Browse the repository at this point in the history
…not str
  • Loading branch information
axel3rd committed Jul 19, 2022
1 parent e317438 commit 5907ec3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/global.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
9 changes: 9 additions & 0 deletions test/test_global.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5907ec3

Please sign in to comment.