Added 'unpad' command to remove leading zeros from base 10 numbers.
This commit is contained in:
@ -236,3 +236,13 @@ proc error_msg {args} {
|
|||||||
set arglist [lrange $cmdinfo 1 end]
|
set arglist [lrange $cmdinfo 1 end]
|
||||||
error "ERROR: [namespace origin $cmd] $arglist: $args"
|
error "ERROR: [namespace origin $cmd] $arglist: $args"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use this function if you expect a decimal number which might be
|
||||||
|
# padded with zeroes.
|
||||||
|
# \brief Strips leading zeroes from decimal numbers.
|
||||||
|
# NOTE: It's up to you to check if the unpadded string is a valid number.
|
||||||
|
#
|
||||||
|
# Handles 0 and numbers prefixed with - or +.
|
||||||
|
proc unpad {n} {
|
||||||
|
return [regsub {([+-])?0*(\d+)} $n {\1\2}]
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user