[fpc-pascal] CSV via PCRE

Graeme Geldenhuys graemeg.lists at gmail.com
Sat Nov 10 09:23:40 CET 2007


OK, while we are busy with show-and-tell... Then have a look at my
token library implementation.

http://tinyurl.com/395vgp

*  It's based on a Infinite State Machine.
*  No external units required.
*  Allows multiple separators (user selectable) between tokens.
*  Allows for user selectable seperator characters.
*  Does line number and position error reporting in case the CSV file
is not well formatted.
*  Only parses the string once, so if you request multiple tokens, it
takes no performance it.
*  I also think it is much easier to understand and extend than than
than single regex which looks more to me like your are cursing! ;-)


Sample Usage:

tokenizer := TTokens.Create(FieldSpecLine, ', ', '"', '"', '\',
                    tsMultipleSeparatorsBetweenTokens);
try
  lField := tokenizer.Token(2);
  lAnotherField := tokenizer.Token(4);
finally
  tokenizer.Free;
end;



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list