From e6ac5d8881e78d47ff5baeaa4061c49f69bae612 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 1 Nov 2011 21:11:10 -0400 Subject: [PATCH] csv: also start auto-detecting ';' and '|' characters as likely separators --- plugins/input/csv/csv_datasource.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index 431bf2824..16b452161 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -26,7 +26,6 @@ #include #include - 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