Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.
Commit message: Fixed CSV quote-parsing bug. Requested reviews: Paul J. Lucas (paul-lucas) For more details, see: https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/215776 Fixed CSV quote-parsing bug. -- https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/215776 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/util/csv_parser.cpp' --- src/util/csv_parser.cpp 2014-03-06 19:06:43 +0000 +++ src/util/csv_parser.cpp 2014-04-14 23:00:32 +0000 @@ -20,10 +20,22 @@ // local #include "csv_parser.h" +using namespace std; + namespace zorba { /////////////////////////////////////////////////////////////////////////////// +inline bool peek( istream &is, char &c ) { + char const temp = is.peek(); + bool const peeked = is.good(); + if ( peeked ) + c = temp; + return peeked; +} + +/////////////////////////////////////////////////////////////////////////////// + bool csv_parser::next_value( zstring *value, bool *eol, bool *quoted ) const { ztd::string_appender<zstring,128> appender( value ); char c; @@ -35,7 +47,9 @@ while ( is_->get( c ) ) { if ( in_quote ) { if ( quote_esc_ == quote_ ) { // "" - if ( c == quote_ && (c = is_->peek(), is_->good()) ) { + if ( c == quote_ ) { + if ( !peek( *is_, c ) ) + break; if ( c != quote_ ) { in_quote = false; continue; @@ -61,7 +75,7 @@ } switch ( c ) { case '\r': - if ( ((c = is_->peek()), is_->good()) && c == '\n' ) + if ( peek( *is_, c ) && c == '\n' ) is_->get(); // no break; case '\n': === added file 'test/rbkt/ExpQueryResults/zorba/csv/csv-parse-02.xml.res' --- test/rbkt/ExpQueryResults/zorba/csv/csv-parse-02.xml.res 1970-01-01 00:00:00 +0000 +++ test/rbkt/ExpQueryResults/zorba/csv/csv-parse-02.xml.res 2014-04-14 23:00:32 +0000 @@ -0,0 +1,4 @@ +{ + "key_1" : "value_1", + "key_2" : "value_2" +} === added file 'test/rbkt/Queries/zorba/csv/csv-parse-02.jq' --- test/rbkt/Queries/zorba/csv/csv-parse-02.jq 1970-01-01 00:00:00 +0000 +++ test/rbkt/Queries/zorba/csv/csv-parse-02.jq 2014-04-14 23:00:32 +0000 @@ -0,0 +1,9 @@ +xquery version "1.0"; + +import module namespace csv = "http://zorba.io/modules/json-csv"; + +let $csvString2 := """key_1"",""key_2"" +""value_1"",""value_2""" +return csv:parse( $csvString2 ) + +(: vim:set et sw=2 ts=2: :) === added file 'test/rbkt/Queries/zorba/csv/csv-parse-02.spec' --- test/rbkt/Queries/zorba/csv/csv-parse-02.spec 1970-01-01 00:00:00 +0000 +++ test/rbkt/Queries/zorba/csv/csv-parse-02.spec 2014-04-14 23:00:32 +0000 @@ -0,0 +1,1 @@ +Serialization: indent=yes
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp