Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias btokentest {
- var %range $1
- var %chars $2
- var %string $3
- bset -t &data -1 %string
- var %x $btoken(&data,%range,%chars,$iif($4,$4))
- if ($4) + $bvar($4,1,$bvar($4,0)).text
- else + %x
- }
- alias btoken {
- hinc -m BTOKEN NUMBER
- var %htable BTOKEN $+ $hget(BTOKEN,NUMBER)
- hadd -m %htable COUNT 0
- var %bvar $1
- var %tokenSeperator $iif($3,$3,$chr(32))
- var %numtok $bnumtok(%bvar, %htable, %tokenSeperator)
- $iif($2 == 0,return %numtok)
- var %range $parseRange($2, %numtok)
- var %startTok $token(%range,1,32)
- var %endTok $iif($token(%range,2,32) >= %startTok,$v1 + 1, $v1 - 1)
- var %temp &t $+ %htable,%return
- while %startTok != %endTok {
- ;var %data $hget(%htable,$iif(%startTok > 0,%startTok, $calc(%numtok + %startTok + 1)),%temp)
- var %data $hget(%htable,%startTok,%temp)
- if ($4) {
- bcopy $4 -1 %temp 1 %data
- bset -t $4 -1 %tokenSeperator
- inc %return %data
- inc %return $len(%tokenSeperator)
- bunset %temp
- }
- else {
- var %return $+(%return,$bvar(%temp,1,%data).text,%tokenSeperator)
- }
- $iif(%startTok > %endTok,dec,inc) %startTok
- }
- hfree %htable
- return $iif($4,$calc(%return - $len(%tokenSeperator)),$left(%return,- $+ $len(%tokenSeperator)))
- }
- alias bnumtok {
- var %bvar $1
- var %htable $$2
- var %btoksep &btoksep $+ %htable
- var %bnumtok &bnumtok $+ %htable
- var %toksep $iif($3,$3,$chr(32))
- bset %btoksep -1 $asc(%toksep)
- $iif($right(%toksep,-1),bset -t %btoksep -1 $v1)
- $iif($hget(%htable,COUNT) != 0,return $hget(%htable,COUNT))
- var %findPos 1
- var %lastFindPos 1
- var %lengthOfBvar $bvar(%bvar,0)
- var %odd $bvar(%btoksep,0)
- while %lastFindPos < %lengthOfBvar {
- var %findPos $iif($bfind(%bvar,%lastFindPos,$bvar(%btoksep,1,$bvar(%btoksep,0))) == 0,$bvar(%bvar,0),$v1) - 1
- hinc -m %htable COUNT
- bcopy %bnumtok 1 %bvar %lastFindPos $calc(%findpos - %lastFindPos + $iif($calc(%findPos + %odd + 1) > %lengthOfBvar,2,1))
- hadd -mb %htable $hget(%htable,COUNT) %bnumtok
- bunset %bnumtok
- var %lastFindPos $calc(%findPos + %odd + 1)
- }
- return $hget(%htable,COUNT)
- }
- alias parserange {
- var %input $1
- var %maxRange $2
- var %startNumber
- var %endNumber
- ;if the first character is a -, the first parameter is a negative number; proceed to second - or end of the string
- var %flag $iif($left(%input,1) == -,$true,$fale)
- var %b $token(%input,1,45)
- var %input $iif(%flag,$right(%input,-1),%input)
- var %a $pos(%input,-,1)
- if %a == $len(%input) {
- ;second - as at end of string (range encountered) no second integer
- %startNumber = $iif(%flag,$calc(%maxRange - %b + 1),%b )
- %endNumber = %maxRange
- }
- else if !%a {
- ;no - after the first token; no range
- %startNumber = %b
- %endNumber = %startNumber
- }
- else {
- ;range encountered; second number present
- var %startNumber $iif(%flag,$calc(%maxRange - %b + 1),%b)
- ;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)
- if %b > 0 && $calc(%b - %a) == 1 {
- ;second integer is negative,
- var %endNumber $calc(%maxRange - $token(%input,2,45) + 1)
- }
- else if %b == 0 {
- ;second integer is positive
- var %endnumber $token(%input,2,45)
- }
- else {
- ;unknown condition
- var %endnumber $token(%input,2,45)
- }
- }
- return %startNumber %endNumber
- }
- alias -l + {
- if (!$window(@DEBUG)) window -e @DEBUG
- echo @DEBUG $1-
- }
- alias -l - {
- noop
- }urn %start %end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement