- 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:
Paul Beckingham 2008-12-14 15:18:33 -05:00
parent 50ccb67185
commit 3d4beaf41f
5 changed files with 73 additions and 28 deletions

View file

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