mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
- Enhanced split algorithm to be non-destrutive, and therefore faster
- Added autoconf testing to detect Solaris - Added Solaris-specific flock implementation
This commit is contained in:
parent
50ccb67185
commit
3d4beaf41f
5 changed files with 73 additions and 28 deletions
34
src/text.cpp
34
src/text.cpp
|
@ -49,33 +49,39 @@ void wrapText (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (std::vector<std::string>& results, const std::string& input, const char delimiter)
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const char delimiter)
|
||||
{
|
||||
std::string temp = input;
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = temp.find (delimiter)) != std::string::npos)
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
std::string token = temp.substr (0, i);
|
||||
results.push_back (token);
|
||||
temp.erase (0, i + 1);
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
if (temp.length ()) results.push_back (temp);
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (std::vector<std::string>& results, const std::string& input, const std::string& delimiter)
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const std::string& delimiter)
|
||||
{
|
||||
std::string temp = input;
|
||||
std::string::size_type length = delimiter.length ();
|
||||
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = temp.find (delimiter)) != std::string::npos)
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
std::string token = temp.substr (0, i);
|
||||
results.push_back (token);
|
||||
temp.erase (0, i + delimiter.length ());
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + length;
|
||||
}
|
||||
|
||||
if (temp.length ()) results.push_back (temp);
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue