// lexnum - convert legal number
/*
lexnum - pad out object number with zeros so it can be used
for comparisons or for sorting.
Usage: string lexNum(Object o|string s)
smartDXL.com
Acknowledgement:
This script was originally taken from the Telelogic kitchen
and has been modified for use here.
*/
/*******************************************************************************
lexNum
returns the object number padded out with leading zeroes
so that it can be used lexicographically in comparisons or for sorting.
Ensure that s is a valid legal number if using this version.
*******************************************************************************/
string lexNum(string s)
{
// description of first part of legal number
Regexp firstNum = regexp "^([0-9]+)([.-]|$)"
Buffer zeros = create
Buffer numA = create
Buffer aN = create
Buffer result = create
string retVal
zeros = "000000"
numA = s
result = ""
// loop through legal number
while (firstNum numA)
{
aN = numA[match 1]
result += "." tempStringOf(zeros[1:5-length(aN)]) tempStringOf(aN)
numA = numA[(end 0)+1:]
}
retVal = stringOf(result)
delete(zeros)
delete(numA)
delete(aN)
delete(result)
return retVal[1:]
}
/*******************************************************************************
lexNum
returns the object number padded out with leading zeroes
so that it can be used lexicographically in comparisons or for sorting.
*******************************************************************************/
string lexNum(Object o)
{
return(lexNum(number(o)))
}
sitemap