mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 22:07:12 +02:00
moved string stuff to string_utils.h/.cpp
This commit is contained in:
@ -1,9 +1,41 @@
|
||||
|
||||
// #include <cstring>
|
||||
// namespace sls{
|
||||
#include <sstream>
|
||||
#include "string_utils.h"
|
||||
#include "container_utils.h"
|
||||
namespace sls{
|
||||
|
||||
// void strcpy_safe(char *dst, const char *src, size_t size){
|
||||
// strncpy(dst, src, size);
|
||||
// }
|
||||
|
||||
// };
|
||||
std::vector<std::string> split(const std::string& strToSplit, char delimeter)
|
||||
{
|
||||
std::stringstream ss(strToSplit);
|
||||
std::string item;
|
||||
std::vector<std::string> splittedStrings;
|
||||
while (std::getline(ss, item, delimeter)) {
|
||||
splittedStrings.push_back(item);
|
||||
}
|
||||
return splittedStrings;
|
||||
}
|
||||
|
||||
|
||||
std::string concatenateNonEmptyStrings(const std::vector<std::string>& vec){
|
||||
std::string ret;
|
||||
for (const auto& s : vec)
|
||||
if (!s.empty())
|
||||
ret += s + '+';
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string concatenateIfDifferent(std::vector<std::string> container)
|
||||
{
|
||||
if (allEqual(container)) {
|
||||
return container.front();
|
||||
} else {
|
||||
std::string result;
|
||||
for (const auto& s : container)
|
||||
result += s + '+';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
Reference in New Issue
Block a user