mirror of
https://github.com/MetaCubeX/subconverter.git
synced 2025-11-04 18:19:42 +08:00
parent
535d1d01e1
commit
55e765e7f9
@ -12,75 +12,29 @@
|
|||||||
|
|
||||||
std::vector<std::string> split(const std::string &s, const std::string &separator)
|
std::vector<std::string> split(const std::string &s, const std::string &separator)
|
||||||
{
|
{
|
||||||
|
string_size bpos = 0, epos = s.find(separator);
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
string_size i = 0;
|
while(bpos < s.size())
|
||||||
|
|
||||||
while(i != s.size())
|
|
||||||
{
|
{
|
||||||
int flag = 0;
|
if(epos == std::string::npos)
|
||||||
while(i != s.size() && flag == 0)
|
epos = s.size();
|
||||||
{
|
result.push_back(s.substr(bpos, epos - bpos));
|
||||||
flag = 1;
|
bpos = epos + separator.size();
|
||||||
for(char x : separator)
|
epos = s.find(separator, bpos);
|
||||||
if(s[i] == x)
|
|
||||||
{
|
|
||||||
++i;
|
|
||||||
flag = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
flag = 0;
|
|
||||||
string_size j = i;
|
|
||||||
while(j != s.size() && flag == 0)
|
|
||||||
{
|
|
||||||
for(char x : separator)
|
|
||||||
if(s[j] == x)
|
|
||||||
{
|
|
||||||
flag = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(flag == 0)
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
if(i != j)
|
|
||||||
{
|
|
||||||
result.push_back(s.substr(i, j-i));
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void split(std::vector<std::string_view> &result, std::string_view s, char separator)
|
void split(std::vector<std::string_view> &result, std::string_view s, char separator)
|
||||||
{
|
{
|
||||||
string_size i = 0;
|
string_size bpos = 0, epos = s.find(separator);
|
||||||
|
while(bpos < s.size())
|
||||||
while (i != s.size())
|
|
||||||
{
|
{
|
||||||
while(i != s.size())
|
if(epos == std::string_view::npos)
|
||||||
{
|
epos = s.size();
|
||||||
if(s[i] == separator)
|
result.push_back(s.substr(bpos, epos - bpos));
|
||||||
{
|
bpos = epos + 1;
|
||||||
++i;
|
epos = s.find(separator, bpos);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string_size j = i;
|
|
||||||
while(j != s.size())
|
|
||||||
{
|
|
||||||
if(s[j] == separator)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
if (i != j)
|
|
||||||
{
|
|
||||||
result.push_back(s.substr(i, j-i));
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user