osm-ToniE / ptna

Public Transport Network Analysis for OSM
GNU General Public License v3.0
19 stars 5 forks source link

enhance CVS parsing to allow "ref1;ref2";bus;comment;from;to;"operator1;operator2" #62

Closed osm-ToniE closed 5 years ago

osm-ToniE commented 5 years ago

Try one of the solutions below

my $csv = Text::CSV->new({ sep_char => ',' });

my @fields = Text::ParseWords::parse_line(';', 0, $line);

From stackoverflow

sub csvsplit {
        my $line = shift;
        my $sep = (shift or ';');

        return () unless $line;

        my @cells;
        $line =~ s/\r?\n$//;

        my $re = qr/(?:^|$sep)(?:"([^"]*)"|([^$sep]*))/;

        while($line =~ /$re/g) {
                my $value = defined $1 ? $1 : $2;
                push @cells, (defined $value ? $value : '');
        }

        return @cells;
}
osm-ToniE commented 5 years ago

I will not completely change the code, because much of existing CSV would need to be changed, example from "Flixbus"

Actually, there is currently only one example where "ref-separator" would need to be equal to "separator"

VRS:

So, the suggested solution above is only used when "separator" is equal to "ref-separator" or "or-separator". Otherwise, the current code with split(...) is used.

osm-ToniE commented 5 years ago

The solution will be: