imk0tter

parserange

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