Use a stringstream instead of sscanf for ParseScalar
This commit is contained in:
parent
d65fc16219
commit
09b0065611
1 changed files with 6 additions and 4 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "yaml.h"
|
#include "yaml.h"
|
||||||
|
|
||||||
|
@ -115,16 +116,17 @@ struct ScalarParserTraits
|
||||||
/**
|
/**
|
||||||
* Parse a YAML scalar value into a native datatype.
|
* Parse a YAML scalar value into a native datatype.
|
||||||
*
|
*
|
||||||
* @param [in] scalarValue The YAML scalar value
|
* @param [in] scalar The YAML scalar value
|
||||||
* @param [out] value The parsed value of the scalar value
|
* @param [out] value The parsed value of the scalar value
|
||||||
* @return `true` if the conversion succeeded
|
* @return `true` if the conversion succeeded
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool
|
bool
|
||||||
ParseScalar(const std::string& scalarValue,
|
ParseScalar(const std::string& scalar,
|
||||||
T& value)
|
T& value)
|
||||||
{
|
{
|
||||||
return sscanf(scalarValue.c_str(), ScalarParserTraits<T>::fmt, &value) == EOF;
|
std::stringstream s(scalar);
|
||||||
|
return (bool)(s >> value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue