mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
other replacements for string
This commit is contained in:
@ -628,6 +628,12 @@ inline int StringTo(const std::string &s) {
|
||||
return std::stoi(s, nullptr, base);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int64_t StringTo(const std::string &s) {
|
||||
int base = s.find("0x") != std::string::npos ? 16 : 10;
|
||||
return std::stol(s, nullptr, base);
|
||||
}
|
||||
|
||||
/** For types with a .str() method use this for conversion */
|
||||
template <typename T>
|
||||
typename std::enable_if<has_str<T>::value, std::string>::type
|
||||
|
@ -179,3 +179,18 @@ TEST_CASE("int from string"){
|
||||
REQUIRE(StringTo<int>("0xffffff") == 0xffffff);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("int64_t from string"){
|
||||
REQUIRE(StringTo<int64_t>("-1") == -1);
|
||||
REQUIRE(StringTo<int64_t>("-0x1") == -0x1);
|
||||
REQUIRE(StringTo<int64_t>("-0x1") == -1);
|
||||
REQUIRE(StringTo<int64_t>("0") == 0);
|
||||
REQUIRE(StringTo<int64_t>("5") == 5);
|
||||
REQUIRE(StringTo<int64_t>("16") == 16);
|
||||
REQUIRE(StringTo<int64_t>("20") == 20);
|
||||
REQUIRE(StringTo<int64_t>("0x14") == 20);
|
||||
REQUIRE(StringTo<int64_t>("0x15") == 21);
|
||||
REQUIRE(StringTo<int64_t>("0xffffff") == 0xffffff);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user