From 2e323be4235a51008844950320b680c27cc523f9 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 16 May 2013 17:19:04 -0400 Subject: [PATCH] [Positioner] CSVStringReader: allow "(X;Y;Z)" CSVStringReader::read_point3D() now allow the first of the three fields forming a Point3D (that is, X) to start with an opening parenthesis, and the last (Z) to end with a closing parenthesis. That allows an improved clarity for strings containing several points, e.g. "(1;2;3);(4;5;6)". --- owlps-positioner/src/csvstringreader.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/owlps-positioner/src/csvstringreader.cc b/owlps-positioner/src/csvstringreader.cc index b4377ae..b6b18f8 100644 --- a/owlps-positioner/src/csvstringreader.cc +++ b/owlps-positioner/src/csvstringreader.cc @@ -132,6 +132,10 @@ bool CSVStringReader::read_timestamp(Timestamp &t) } +/** + * The first field (X) can start with an opening parenthesis, and the + * last one (Z) can finish with a closing parenthesis. + */ bool CSVStringReader::read_point3d(Point3D &p) { float coord[3] ; @@ -142,9 +146,19 @@ bool CSVStringReader::read_point3d(Point3D &p) return false ; ++current_field_nb ; + string field = *token_iterator ; + if (field.empty()) + return false ; + + /* Handle a leading '(' and a trailing ')' */ + if (i == 0 && field.front() == '(') + field.erase(field.begin()) ; + if (i == 2 && field.back() == ')') + field.pop_back() ; + try { - coord[i] = lexical_cast(*token_iterator) ; + coord[i] = lexical_cast(field) ; } catch (bad_lexical_cast &e) {