Changes Tk8.7 -underline type result in runtime errors
Brought to you by:
pspjuth
Values for the canvas widget -underline option have changed in Tk8.7 (Tcl 9) from TIP #577. It has changed from type int to type index, which include values like "end-2", and "" (the empty set).
Existing code uses the old form: {$underline != -1} to test for the empty set, These checks need to change to {$underline ne ""}.
Also note that type index is nolonger a simple integer.
I made a fix that makes it handle it a bit more gracefully.
End-style index will be treated as not existing for now.
Is there a nice way to parse end-style from Tcl?
I'm not aware of a specific command for this. However, the following should work:
~~~~
set str "Example String Value"
set index "end-3"
set intIndex [lindex [lseq [string length $str]] $index]
proc intIndexForString {stringValue index} {
return [lindex [lseq [string length $stringValue]] $index]
}
proc intIndexForList {listValue index} {
return [lindex [lseq [llength $listValue]] $index]
}
~~~
These functions should have O(1) performance regardless of string length or list length.
Fixed it with the lseq trick.