Advertisement
imk0tter

Untitled

May 9th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. alias -l parserange {
  2. var %input $1
  3. var %maxRange $2
  4.  
  5. var %startNumber
  6. var %endNumber
  7.  
  8. ;if the first character is a -, the first parameter is a negative number; proceed to second - or end of the string
  9. var %flag $iif($left(%input,1) == -,$true,$false)
  10.  
  11. var %b $token(%input,1,45)
  12.  
  13. var %input $iif(%flag,$right(%input,-1),%input)
  14. var %a $pos(%input,-,1)
  15.  
  16. if %a == $len(%input) {
  17. ;second - as at end of string (range encountered) no second integer
  18. %startNumber = $iif(%flag,$calc(%maxRange - %b + 1),%b)
  19. %endNumber = %maxRange
  20. }
  21. else if !%a {
  22. ;no - after the first token; no range
  23. %startNumber = $iif(%flag,$calc(%maxRange - %b + 1),%b)
  24. %endNumber = %startNumber
  25. }
  26. else {
  27. ;range encountered; second number present
  28. var %startNumber $iif(%flag,$calc(%maxRange - %b + 1),%b)
  29.  
  30. ;proceed to first - or end of string, and if there is a positive or negative integer
  31.  
  32. var %a $iif($Pos(%input,-,1),$v1,0)
  33. var %b $iif($pos(%input,-,2),$v1,0)
  34.  
  35. if %b > 0 && $calc(%b - %a) == 1 {
  36. ;second integer is negative,
  37.  
  38. var %endNumber $calc(%maxRange - $token(%input,2,45) + 1)
  39. }
  40. else if %b == 0 {
  41. ;second integer is positive
  42. var %endnumber $token(%input,2,45)
  43. }
  44. else {
  45. ;unknown condition
  46. var %endnumber $token(%input,2,45)
  47. }
  48. }
  49. return %startNumber %endNumber
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement