Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias parserange {
- var %input $1
- var %maxRange $2
- var %startNumber, %endNumber,%c $token(%input,1,45)
- ;if the first character is a -, the first parameter is a negative number; proceed to second - or end of the string
- if ($left(%input,1) == -) {
- var %startNumber $calc(%maxRange - %c + 1)
- var %input $right(%input,-1)
- }
- else {
- var %startNumber %c
- }
- var %a $pos(%input,-,1)
- if %a == $len(%input) {
- ;second - as at end of string (range encountered) no second integer
- %endNumber = %maxRange
- }
- else if !%a {
- ;no - after the first token; no range
- %endNumber = %startNumber
- }
- else {
- ;range encountered; second number present
- ;proceed to first - or end of string, and if there is a positive or negative integer
- var %a $iif($Pos(%input,-,1),$v1,0)
- var %b $iif($pos(%input,-,2),$v1,0)
- var %c $token(%input,2,45)
- if %b > 0 && $calc(%b - %a) == 1 {
- ;second integer is negative,
- var %endNumber $calc(%maxRange - %c + 1)
- }
- else if %b == 0 {
- ;second integer is positive
- var %endnumber %c
- }
- else {
- ;unknown condition
- var %endnumber %c
- }
- }
- return %startNumber %endNumber
- }
Add Comment
Please, Sign In to add comment