Skip to content

graze/csv-token

Repository files navigation

csv-token

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Tokenised Csv Reader that handles some of the strange configurations databases and application use.

  • Parses tokens and csv from streams and outputs using a Lazy Iterator
Csv Feature Example Array
Delimiter `thing other`
Quote Enclosure "quote, here",not here ['quote, here', 'not here']
Escaping "\"text","new\\nline" ['"text',"new\\\nline"]
Double Quotes """text","more" ['"text','more']
Double Quotes and Escaping """text","\, text" ['"text',', text']
Null value parsing "text",\\N,"text" ['text',null,'text']
Boolean value parsing "text",false,true ['text',false,true]
Numeric value parsing "text",1,-2.3,3.1e-24 ['text',1,-2.3,3.1e-24]
Handling of Byte Order Marks <UTF8BOM>"text","things" ['text','things']

Install

Via Composer

$ composer require graze/csv-token

Usage

Simple reader

$csvDefinition = new CsvDefinition();
$reader = new Reader($csvDefinition, $stream);
$iterator = $reader->read();

More advanced parsing (with value parsers)

// $stream = '"some","text",true,false,0,1,2';
$csvDefiniton = new CsvDefinition();
$parser = new Parser([new BoolValueParser(), new NumberValueParser()]);
$tokeniser = new StreamTokeniser($csvDefinition, $stream);
$iterator = $parser->parser($tokeniser->getTokens());

var_dump(iterator_to_array($iterator));
-> [['some','text',true,false,0,1,2]]

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ make test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.