Anonymous user
Strip comments from a string: Difference between revisions
m
→{{header|Forth}}
Line 622:
Or Concatenate the functions together as we did here.
Tested with Swift Forth on OS/X, GForth on Windows
<LANG FORTH>\ Rosetta Code Strip Comment
▲: LASTCHAR ( addr len -- addr len c) 2DUP + 1- C@ ;
: COMMENT? ( char -- ? ) S" #;" ROT SCAN NIP ; \ is char '#' or ';'
: -COMMENT ( addr len -- addr len') \ removes # or ; comments
LASTCHAR COMMENT? 0=
1- \ reduce length by 1
REPEAT
1- ; \ remove 1 more (the comment char)
: -TRAILING ( adr len -- adr len') \ remove trailing spaces
WHILE \ while lastchar = blank
1- \ reduce length by 1
REPEAT
1+ ;
: COMMENT-STRIP ( addr len -- addr 'len) -COMMENT -TRAILING ;</LANG>
|