; TokStrings are strings of space delimited colon separated item:value pairs.
; These functions allow you maintain lists of named values in a single variable.
; Limitations: Items and values *must not* contain spaces or colons. Beware.
; There is no error checking for speed sake. If you feed in garbage you get garbage.
;
; GetTokStr -- Get an item's value.
; $gettokstr(tokenstring, itemname) == value
;
; SetTokStr -- Add, replace or delete an item and its value.
; $settokstr(tokenstring, itemname, [data]) == tokenstring
;
; IncTokStr -- Increase or decrease an item's value. Item is created if new.
; $inctokstr(tokenstring, itemname, [-]number) == tokenstring
;
; $gettokstr(the:5 quick:3 brown:2 fox:7, fox) == 7
; $settokstr(the:5 quick:3 brown:2, fox, 6) == the:5 quick:3 brown:2 fox:6
; $settokstr(the:5 quick:3 brown:2 fox:7, brown, 4) == the:5 quick:3 brown:4 fox:7
; $settokstr(the:5 quick:3 brown:2 fox:7, brown) == the:5 quick:3 fox:7
; $inctokstr(the:5 quick:3 brown:2 fox:7, quick, -2) == the:5 quick:1 brown:2 fox:7
gettokstr {
return $gettok($wildtok($1,$+($2,:*),1,32),2,58)
} ; Raccoon 2020
settokstr {
if ($3 != $null) {
if ($wildtok($1,$+($2,:*),1,32)) {
return $reptok($1,$v1,$+($2,:,$3),1,32)
}
return $addtok($1,$+($2,:,$3),32)
}
if ($wildtok($1,$+($2,:*),1,32)) {
return $remtok($1,$v1,1,32)
}
return $1
} ; Raccoon 2020 speed
inctokstr {
if ($wildtok($1,$+($2,:*),1,32)) {
return $reptok($1,$v1,$+($2,:,$calc($gettok($v1,2,58) + $3)),1,32)
}
return $addtok($1,$+($2,:,$3),32)
} ; Raccoon 2020
; P.S. the Str might also stand for Structure. As in TokStructures.