add new split string implemantation

This commit is contained in:
chatlanin
2022-07-20 11:13:55 +03:00
parent 7ec159ac5f
commit e7d35b0e1d
4 changed files with 25 additions and 17 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}