[REBOL] Re: Speed and Memory Management in REBOL Re:(2)
From: g:santilli:tiscalinet:it at: 11-Sep-2000 19:12
Hello [joel--neely--fedex--com]!
On 11-Set-00, you wrote:
j> Consider the "csv" file below, created by a Well-Known
j> Spreadsheet from a Large Redmond Company:
Here's a parser for files generated by that monster. :-)
HTH,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
REBOL [
Title: "CSV parser"
Author: "Gabriele Santilli"
]
CSV-parser: make object! [
line-rule: [field any [separator field]]
field: [[quoted-string | string] (insert tail fields any [f-val copy ""])]
string: [copy f-val any str-char]
quoted-string: [{"} copy f-val any qstr-char {"} (replace/all f-val {""} {"})]
str-char: none
qstr-char: [{""} | separator | str-char]
fields: []
f-val: none
separator: #";"
set 'parse-csv-line func [
"Parses a CSV line (returns a block of strings)"
line [string!]
/with sep [char!] "The separator between fields"
] [
clear fields
separator: any [sep #";"]
str-char: complement charset join {"} separator
parse/all line line-rule
copy fields
]
]