MEMO: (quoted-field) ( delimiter -- delimiter' )
"\"\n" swap suffix ; inline
-: not-quoted-field ( -- endchar )
- delimiter> (quoted-field) read-until
- dup CHAR: " =
- [ 2drop quoted-field ]
- [
- swap dup {
- [ ?first blank? ]
- [ ?last blank? ]
- } 1||
- [ [ blank? ] trim ] when %
- ]
- if ;
-
: maybe-escaped-quote ( -- endchar )
read1 dup {
{ CHAR: " [ , quoted-field ] }
drop % maybe-escaped-quote ;
: field ( -- sep string )
- [ not-quoted-field ] "" make ;
+ delimiter> (quoted-field) read-until
+ dup CHAR: " = [
+ 2drop [ quoted-field ] "" make
+ ] [
+ swap [ "" ] [
+ dup {
+ [ ?first blank? ]
+ [ ?last blank? ]
+ } 1||
+ [ [ blank? ] trim ] when
+ ] if-empty
+ ] if ;
: (row) ( -- sep )
f delimiter> '[ dup _ = ]