Commit 0119700c authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk) :
- Update toBoolean() method in XMLAttributs class.
parent 7db9f609
#include "../../../include/ElementaryUtils/parser/XMLAttributs.h"
#include <iostream>
#include <stdexcept>
#include <utility>
#include <sstream> // needed
#include <sstream> // needed #include <stdexcept> #include <utility> #include <utility> #include <utility> #include <utility>
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
namespace ElemUtils {
......@@ -80,15 +80,19 @@ bool XMLAttributs::isAvailable(const std::string& key) const {
}
bool XMLAttributs::getBooleanValueOf(const std::string& key) {
bool b = false;
std::stringstream sstream;
sstream << getStringValueOf(key);
bool b = false;
// if conversion failed then print an exception
if ((sstream >> b).fail()) {
throw std::runtime_error(
"[Attributs::getBooleanValueOf] cast from std::string to bool failed ! ");
if (StringUtils::equalsIgnoreCase(sstream.str(), "true")) {
b = 1;
} else if (!StringUtils::equalsIgnoreCase(sstream.str(), "false")) {
throw CustomException("XMLAttributs", __func__,
"Cast from std::string to bool failed ! ");
}
}
return b;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment