Skip to content

Commit

Permalink
Merge pull request #3 from 42tm/strtoken
Browse files Browse the repository at this point in the history
Improve strSplit
  • Loading branch information
dungwinux authored May 2, 2018
2 parents d002759 + 7d0c347 commit 1e9f81c
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/ctimmy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <chrono>
Expand Down Expand Up @@ -115,23 +116,10 @@ std::string strTrim(std::string s)
tStrArray strSplit(std::string s, char delimiter)
{
tStrArray splited;
s += delimiter;
std::string flagStr;
for (char iter : s)
if (iter != delimiter)
flagStr += iter;
else
{
if (flagStr.empty())
continue;
splited.push_back(flagStr);
flagStr.clear();
}
if (splited.empty())
{
splited.resize(1);
splited[0] = s;
}
std::string token;
std::istringstream iss(s);
while (std::getline(iss, token, delimiter))
splited.push_back(token);
return (splited);
}

Expand Down

0 comments on commit 1e9f81c

Please sign in to comment.