Tokenize a string: Difference between revisions
Content added Content deleted
(+ Forth) |
|||
Line 105: | Line 105: | ||
begin |
begin |
||
2dup 2, \ save this token ( addr len ) |
2dup 2, \ save this token ( addr len ) |
||
2over search \ find next separator |
2over search \ find next separator |
||
while |
while |
||
dup negate here 2 cells - +! \ adjust last token length |
dup negate here 2 cells - +! \ adjust last token length |
||
2over nip /string |
2over nip /string \ start next search past separator |
||
repeat |
repeat |
||
2drop 2drop |
2drop 2drop |
||
r> here over - ( tokens length ) |
r> here over - ( tokens length ) |
||
dup negate allot \ reclaim dictionary |
dup negate allot \ reclaim dictionary |
||
2 cells / ; \ turn byte length into token count |
2 cells / ; \ turn byte length into token count |
||
: .tokens ( tokens count -- ) |
: .tokens ( tokens count -- ) |