mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Common: Modified split to be more pure function
This commit is contained in:
parent
801f39d2fa
commit
1e6412bcb1
3 changed files with 24 additions and 6 deletions
|
@ -29,6 +29,24 @@
|
|||
#include <iomanip>
|
||||
#include <math.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <std::string> split (const std::string& input, const char delimiter)
|
||||
{
|
||||
std::vector <std::string> results;
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start));
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <vector>
|
||||
|
||||
// text.cpp, Non-UTF-8 aware.
|
||||
std::vector <std::string> split (const std::string&, const char);
|
||||
void split (std::vector<std::string>&, const std::string&, const char);
|
||||
const std::string format (std::string&);
|
||||
const std::string format (const char*);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue