add new split string implemantation
This commit is contained in:
@@ -2,20 +2,4 @@
|
||||
|
||||
namespace hack::string
|
||||
{
|
||||
v_str split_str(const std::string& str, char t)
|
||||
{
|
||||
v_str v;
|
||||
|
||||
std::string::size_type begin = 0;
|
||||
std::string::size_type end = str.find_first_of(t);
|
||||
|
||||
while(end != std::string::npos)
|
||||
{
|
||||
v.emplace_back(str.substr(begin, end - begin));
|
||||
begin = ++end;
|
||||
end = str.find_first_of(t, begin);
|
||||
}
|
||||
v.emplace_back(str.substr(begin));
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,21 @@ namespace hack::string
|
||||
{
|
||||
using v_str = std::vector<std::string>;
|
||||
|
||||
v_str split_str(const std::string& str, char t);
|
||||
template<typename T>
|
||||
v_str split_str(const std::string& str, T t)
|
||||
{
|
||||
v_str v;
|
||||
|
||||
std::string::size_type begin = 0;
|
||||
std::string::size_type end = str.find_first_of(t);
|
||||
|
||||
while(end != std::string::npos)
|
||||
{
|
||||
v.emplace_back(str.substr(begin, end - begin));
|
||||
begin = ++end;
|
||||
end = str.find_first_of(t, begin);
|
||||
}
|
||||
v.emplace_back(str.substr(begin));
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user