mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
WIP
This commit is contained in:
@ -53,4 +53,7 @@ std::vector<std::string> split(const std::string &strToSplit, char delimeter);
|
||||
std::string RemoveUnit(std::string &str);
|
||||
|
||||
bool is_int(const std::string &s);
|
||||
|
||||
bool replace_first(std::string *s, const std::string& substr, const std::string& repl);
|
||||
|
||||
} // namespace sls
|
||||
|
@ -36,4 +36,14 @@ bool is_int(const std::string &s) {
|
||||
}) == s.end();
|
||||
}
|
||||
|
||||
bool replace_first(std::string *s, const std::string& substr, const std::string& repl){
|
||||
auto pos = s->find(substr);
|
||||
if (pos != std::string::npos){
|
||||
s->replace(pos, substr.size(), repl);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace sls
|
@ -76,4 +76,33 @@ TEST_CASE("Check is string is integer") {
|
||||
REQUIRE_FALSE(sls::is_int(""));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Replace substring in string"){
|
||||
std::string s = "this string should be replaced";
|
||||
auto r = sls::replace_first(&s, "string ", "");
|
||||
REQUIRE(r == true);
|
||||
REQUIRE(s == "this should be replaced");
|
||||
}
|
||||
|
||||
TEST_CASE("Replace --help in command"){
|
||||
std::string s = "sls_detector_get --help exptime";
|
||||
auto r = sls::replace_first(&s, " --help", "");
|
||||
REQUIRE(r == true);
|
||||
REQUIRE(s == "sls_detector_get exptime");
|
||||
}
|
||||
|
||||
TEST_CASE("Replace -h in command"){
|
||||
std::string s = "sls_detector_get -h exptime";
|
||||
auto r = sls::replace_first(&s, " -h", "");
|
||||
REQUIRE(r == true);
|
||||
REQUIRE(s == "sls_detector_get exptime");
|
||||
}
|
||||
|
||||
TEST_CASE("replace --help"){
|
||||
std::string s = "list --help";
|
||||
auto r = sls::replace_first(&s, " --help", "");
|
||||
REQUIRE(r == true);
|
||||
REQUIRE(s == "list");
|
||||
}
|
||||
|
||||
// TEST_CASE("concat things not being strings")
|
Reference in New Issue
Block a user