Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
partons
core
elementary-utils
Commits
0119700c
Commit
0119700c
authored
Oct 18, 2016
by
Bryan Berthou
Browse files
refs#16
In ElementaryUtils (trunk) : - Update toBoolean() method in XMLAttributs class.
parent
7db9f609
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/ElementaryUtils/parser/XMLAttributs.cpp
View file @
0119700c
#include
"../../../include/ElementaryUtils/parser/XMLAttributs.h"
#include
<iostream>
#include
<s
tdexcept
>
#include
<utility>
#include
<sstream>
// needed
#include
<s
stream>
// 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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment