TABLE OF CONTENTS
::pwtk::parseIndex1
SYNOPSIS
proc ::pwtk::parseIndex1 {index lastIndex} {
PURPOSE
Tranform symbolic index to numeric index. The first index has the value of 1 (hence the prefix 1 in the name), i.e.:
begin, first, 1st --> 1 begin+N, first+N, 1st+N --> 1+N end, last --> $lastIndex end-N, last-N, --> $lastIndex-N
First index can have symbolic values of:
first, begin, 1st
Last index can have symbolic values of:
end, last
If index is given as math expression, it is evaluated. For example:
parseIndex1 end-1 3
returns 2.
ARGUMENTS
- index -- index to parse
- lastIndex -- the greatest value an index can have (used to transform 'end' to a number)
SOURCE
set ind [regsub -nocase {(^begin|^first|^1st)} $index 1] set ind [regsub -nocase {(^end|^last)} $ind $lastIndex] try { set index [expr $ind] } on error err { set index $ind } # if { ! [string is integer -strict $index] } { uplevel 1 [list ::pwtk::error "expected integer for index, but got $index" 1] } return $index }