From cb1652835a07b11e4e2c77a2a03e4b1a1ef63370 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Tue, 10 Jun 2014 19:20:41 +1000 Subject: [PATCH] Added 'unpad' command to remove leading zeros from base 10 numbers. --- site_ansto/instrument/util/extra_utility.tcl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/site_ansto/instrument/util/extra_utility.tcl b/site_ansto/instrument/util/extra_utility.tcl index 88ffbab5..ba8da11f 100644 --- a/site_ansto/instrument/util/extra_utility.tcl +++ b/site_ansto/instrument/util/extra_utility.tcl @@ -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}] +}