基本可用。
This commit is contained in:
24
bf.util.cpp
24
bf.util.cpp
@@ -80,3 +80,27 @@ std::string BF_Util::urlEncode(const std::string& data)
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::vector<std::string> BF_Util::split(const std::string& str, const std::string& delim)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
size_t start = 0;
|
||||
size_t end = str.find(delim);
|
||||
while (end != std::string::npos) {
|
||||
ret.push_back(str.substr(start, end - start));
|
||||
start = end + delim.length();
|
||||
end = str.find(delim, start);
|
||||
}
|
||||
ret.push_back(str.substr(start));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BF_Util::trim(std::string& str)
|
||||
{
|
||||
auto left = std::find_if_not(str.begin(), str.end(), [](unsigned char ch) { return std::isspace(ch); });
|
||||
str.erase(str.begin(), left);
|
||||
if (!str.empty()) {
|
||||
auto right = std::find_if_not(str.rbegin(), str.rend(), [](unsigned char ch) { return std::isspace(ch); }).base();
|
||||
str.erase(right, str.end());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user