From 89939e2862b61eedb4ababb22d3ae17fae179de8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 12 May 2014 00:25:19 +0100 Subject: [PATCH] Remove use of boost::lexical_cast as it appears to be difficult to make it use the standard "C" locale for both decimal and thousands separators. Instead, use std::stringstream which it appears will use "C" for both decimal and thousands after s.imbue (std::locale::classic ()); --- src/cxml.cc | 19 +++++++++++++++++++ src/cxml.h | 48 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/cxml.cc b/src/cxml.cc index a955b91..68ad109 100644 --- a/src/cxml.cc +++ b/src/cxml.cc @@ -1,3 +1,22 @@ +/* + Copyright (C) 2012-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include #include #include diff --git a/src/cxml.h b/src/cxml.h index df99056..eea15f5 100644 --- a/src/cxml.h +++ b/src/cxml.h @@ -1,3 +1,22 @@ +/* + Copyright (C) 2012-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #ifndef LIBCXML_CXML_H #define LIBCXML_CXML_H @@ -6,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +107,12 @@ public: { std::string s = string_child (c); boost::erase_all (s, " "); - return boost::lexical_cast (s); + std::stringstream t; + t.imbue (std::locale::classic ()); + t << s; + T n; + t >> n; + return n; } template @@ -102,7 +125,12 @@ public: std::string t = s.get (); boost::erase_all (t, " "); - return boost::optional (boost::lexical_cast (t)); + std::stringstream u; + u.imbue (std::locale::classic ()); + u << t; + T n; + u >> n; + return n; } /** This will mark a child as to be ignored when calling done() */ @@ -128,7 +156,12 @@ public: { std::string s = string_attribute (c); boost::erase_all (s, " "); - return boost::lexical_cast (s); + std::stringstream t; + t.imbue (std::locale::classic ()); + t << s; + T n; + t >> n; + return n; } template @@ -141,7 +174,12 @@ public: std::string t = s.get (); boost::erase_all (t, " "); - return boost::optional (boost::lexical_cast (t)); + std::stringstream u; + u.imbue (std::locale::classic ()); + u << t; + T n; + t >> n; + return n; } /** @return The content of this node */ -- 2.30.2