Added 'unpad' command to remove leading zeros from base 10 numbers.

This commit is contained in:
Ferdi Franceschini
2014-06-10 19:20:41 +10:00
parent 96526c7866
commit cb1652835a

View File

@ -236,3 +236,13 @@ proc error_msg {args} {
set arglist [lrange $cmdinfo 1 end]
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}]
}