csv: faster, only use make when field contains quotes or newlines.
parent
3bd6610a9d
commit
e607cfb6ce
|
@ -24,19 +24,6 @@ DEFER: quoted-field
|
||||||
MEMO: (quoted-field) ( delimiter -- delimiter' )
|
MEMO: (quoted-field) ( delimiter -- delimiter' )
|
||||||
"\"\n" swap suffix ; inline
|
"\"\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 )
|
: maybe-escaped-quote ( -- endchar )
|
||||||
read1 dup {
|
read1 dup {
|
||||||
{ CHAR: " [ , quoted-field ] }
|
{ CHAR: " [ , quoted-field ] }
|
||||||
|
@ -50,7 +37,18 @@ MEMO: (quoted-field) ( delimiter -- delimiter' )
|
||||||
drop % maybe-escaped-quote ;
|
drop % maybe-escaped-quote ;
|
||||||
|
|
||||||
: field ( -- sep string )
|
: 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 )
|
: (row) ( -- sep )
|
||||||
f delimiter> '[ dup _ = ]
|
f delimiter> '[ dup _ = ]
|
||||||
|
|
Loading…
Reference in New Issue