\ 4tH library - TOOLBELT TRIM - Copyright 2003,2007 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

\ Load definitions when needed
[UNDEFINED] IS-WHITE [IF]
[NEEDS lib/istype.4th]
[THEN]

[UNDEFINED] ?NOT [IF]
[NEEDS lib/yesno.4th]
[THEN]

[UNDEFINED] TRIM [IF]
: TRIM ( addr1 n1 -- addr1 n2 )
  BEGIN DUP IF OVER OVER 1- CHARS + C@ IS-WHITE ELSE DUP THEN WHILE 1- REPEAT ;
  
: (BL-SCAN)
  IS ?NOT BEGIN DUP
  IF OVER C@ IS-WHITE ?NOT IF CHOP TRUE ELSE FALSE THEN
  ELSE FALSE THEN OVER 0<> AND 0= UNTIL ;
 
: BL-SKIP ['] (YES) (BL-SCAN) ; ( S: A N --- A' N' ) ( G: SKIP CHARACTERS )
: BL-SCAN ['] (NO)  (BL-SCAN) ; ( S: A N --- A' N' ) ( G: SCAN STRING )

[DEFINED] 4TH# [IF]
hide (BL-SCAN)
[THEN]
[THEN]

