csv: also start auto-detecting ';' and '|' characters as likely separators
This commit is contained in:
parent
16ab2ba895
commit
e6ac5d8881
1 changed files with 23 additions and 2 deletions
|
@ -26,7 +26,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
using mapnik::datasource;
|
||||
using mapnik::parameters;
|
||||
using namespace boost::spirit;
|
||||
|
@ -191,11 +190,11 @@ void csv_datasource::parse_csv(T& stream,
|
|||
{
|
||||
// default to ','
|
||||
sep = ",";
|
||||
int num_commas = std::count(csv_line.begin(), csv_line.end(), ',');
|
||||
// detect tabs
|
||||
int num_tabs = std::count(csv_line.begin(), csv_line.end(), '\t');
|
||||
if (num_tabs > 0)
|
||||
{
|
||||
int num_commas = std::count(csv_line.begin(), csv_line.end(), ',');
|
||||
if (num_tabs > num_commas)
|
||||
{
|
||||
sep = "\t";
|
||||
|
@ -204,6 +203,28 @@ void csv_datasource::parse_csv(T& stream,
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else // pipes
|
||||
{
|
||||
int num_pipes = std::count(csv_line.begin(), csv_line.end(), '|');
|
||||
if (num_pipes > num_commas)
|
||||
{
|
||||
sep = "|";
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "CSV Plugin: auto detected '|' separator\n";
|
||||
#endif
|
||||
}
|
||||
else // semicolons
|
||||
{
|
||||
int num_semicolons = std::count(csv_line.begin(), csv_line.end(), ';');
|
||||
if (num_semicolons > num_commas)
|
||||
{
|
||||
sep = ";";
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "CSV Plugin: auto detected ';' separator\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set back to start
|
||||
|
|
Loading…
Reference in a new issue