53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#ifndef GERMANAIRLINESVA_GACONNECTOR_STRINGEXTENSIONS_H
|
|
#define GERMANAIRLINESVA_GACONNECTOR_STRINGEXTENSIONS_H
|
|
|
|
#include <algorithm>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// trim from start (in place)
|
|
static inline void ltrim(std::string &s)
|
|
{
|
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
|
return !std::isspace(ch);
|
|
}));
|
|
}
|
|
|
|
// trim from end (in place)
|
|
static inline void rtrim(std::string &s)
|
|
{
|
|
s.erase(std::find_if(s.rbegin(),
|
|
s.rend(),
|
|
[](unsigned char ch) { return !std::isspace(ch); })
|
|
.base(),
|
|
s.end());
|
|
}
|
|
|
|
static inline std::string rtrim_copy(std::string s)
|
|
{
|
|
rtrim(s);
|
|
return s;
|
|
}
|
|
|
|
// trim from both ends (in place)
|
|
static inline void trim(std::string &s)
|
|
{
|
|
ltrim(s);
|
|
rtrim(s);
|
|
}
|
|
|
|
static inline std::vector<std::string> split(const std::string &s, char delim)
|
|
{
|
|
std::vector<std::string> result;
|
|
std::stringstream ss(s);
|
|
std::string item;
|
|
|
|
while (getline(ss, item, delim)) {
|
|
result.push_back(item);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endif |