mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
@ -622,6 +622,12 @@ inline uint64_t StringTo(const std::string &s) {
|
||||
return std::stoull(s, nullptr, base);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int StringTo(const std::string &s) {
|
||||
int base = s.find("0x") != std::string::npos ? 16 : 10;
|
||||
return std::stoi(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
|
||||
|
@ -165,3 +165,17 @@ TEST_CASE("uint64 from string"){
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("int from string"){
|
||||
REQUIRE(StringTo<int>("-1") == -1);
|
||||
REQUIRE(StringTo<int>("-0x1") == -0x1);
|
||||
REQUIRE(StringTo<int>("-0x1") == -1);
|
||||
REQUIRE(StringTo<int>("0") == 0);
|
||||
REQUIRE(StringTo<int>("5") == 5);
|
||||
REQUIRE(StringTo<int>("16") == 16);
|
||||
REQUIRE(StringTo<int>("20") == 20);
|
||||
REQUIRE(StringTo<int>("0x14") == 20);
|
||||
REQUIRE(StringTo<int>("0x15") == 21);
|
||||
REQUIRE(StringTo<int>("0xffffff") == 0xffffff);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user