summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2013-12-16 13:35:48 +0100
committerFridrich Štrba <fridrich.strba@bluewin.ch>2013-12-16 13:35:48 +0100
commitc43a413414a8bd3cf4d61b5716606bfe8b4d060e (patch)
tree8ad221c0105bad07d7772b3aec26e07b859b08a1
parent1afbb575ae6d80b51b75a9c8f6fafa8f0f07f8d5 (diff)
Words cannot tell the love we have towards boost
Change-Id: I0ab0b4858348a6b75de319672df808b6c73af87d
-rw-r--r--configure.ac1
-rw-r--r--src/lib/VSDXMLHelper.cpp50
2 files changed, 13 insertions, 38 deletions
diff --git a/configure.ac b/configure.ac
index 7fa0150..9e4df06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,7 @@ AC_SUBST(ZLIB_LIBS)
AC_CHECK_HEADERS(
boost/algorithm/string.hpp \
+ boost/lexical_cast.hpp \
boost/optional.hpp \
boost/spirit/include/classic.hpp,
[],
diff --git a/src/lib/VSDXMLHelper.cpp b/src/lib/VSDXMLHelper.cpp
index 2367a45..bef794d 100644
--- a/src/lib/VSDXMLHelper.cpp
+++ b/src/lib/VSDXMLHelper.cpp
@@ -34,6 +34,7 @@
#include <istream>
#include <vector>
#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
#include <libxml/xmlIO.h>
#include <libxml/xmlstring.h>
#include <librevenge-stream/librevenge-stream.h>
@@ -140,65 +141,38 @@ libvisio::Colour libvisio::xmlStringToColour(const xmlChar *s)
long libvisio::xmlStringToLong(const xmlChar *s)
{
+ using boost::lexical_cast;
+ using boost::bad_lexical_cast;
if (xmlStrEqual(s, BAD_CAST("Themed")))
return 0;
- char *end;
- errno = 0;
- long value = strtol((const char *)s, &end, 0);
-
- if ((ERANGE == errno && (LONG_MAX == value || LONG_MIN == value)) || (errno && !value))
+ try
{
- VSD_DEBUG_MSG(("Throwing XmlParserException\n"));
- throw XmlParserException();
+ return boost::lexical_cast<long, const char *>((const char *)s);
}
- else if (*end)
+ catch (const boost::bad_lexical_cast &)
{
VSD_DEBUG_MSG(("Throwing XmlParserException\n"));
throw XmlParserException();
}
-
- return value;
+ return 0;
}
double libvisio::xmlStringToDouble(const xmlChar *s)
{
if (xmlStrEqual(s, BAD_CAST("Themed")))
- return 0;
-
- char *end;
- std::string doubleStr((const char *)s);
-
-#ifndef __ANDROID__
- std::string decimalPoint(localeconv()->decimal_point);
-#else
- std::string decimalPoint(".");
-#endif
- if (!decimalPoint.empty() && decimalPoint != ".")
- {
- if (!doubleStr.empty())
- {
- std::string::size_type pos;
- while ((pos = doubleStr.find(".")) != std::string::npos)
- doubleStr.replace(pos,1,decimalPoint);
- }
- }
+ return 0.0;
- errno = 0;
- double value = strtod(doubleStr.c_str(), &end);
-
- if ((ERANGE == errno) || (errno && !value))
+ try
{
- VSD_DEBUG_MSG(("Throwing XmlParserException\n"));
- throw XmlParserException();
+ return boost::lexical_cast<double, const char *>((const char *)s);
}
- else if (*end)
+ catch (const boost::bad_lexical_cast &)
{
VSD_DEBUG_MSG(("Throwing XmlParserException\n"));
throw XmlParserException();
}
-
- return value;
+ return 0.0;
}
bool libvisio::xmlStringToBool(const xmlChar *s)