mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-25 06:41:08 +02:00
Clean up split() utility function
Remove fourth argument, which was never used and had a confusing name. Change return type to void, since the returned value was never used. Simplify the actual splitting code. Add documentation comment.
This commit is contained in:
parent
a03f8957aa
commit
f0f3684826
@ -202,39 +202,20 @@ int evalIntConf (ConfIntHash& hash, const std::string &key, int def, int imin, i
|
||||
}
|
||||
}
|
||||
|
||||
bool split (vector<string> &vec, const string &str, const string &delim, bool destructive) {
|
||||
void split(vector<string>& vec, string const& str, string const& delim) {
|
||||
vec.clear();
|
||||
|
||||
if (delim.empty()) {
|
||||
vec.push_back(str);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string::size_type i = 0;
|
||||
std::string::size_type j = 0;
|
||||
|
||||
while(1) {
|
||||
j = str.find(delim,i);
|
||||
if (j==std::string::npos) {
|
||||
vec.push_back(str.substr(i));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!destructive)
|
||||
j += delim.size();
|
||||
|
||||
vec.push_back(str.substr(i,j-i));
|
||||
|
||||
if (destructive)
|
||||
i = j + delim.size();
|
||||
|
||||
if (i==str.size()) {
|
||||
vec.push_back(std::string());
|
||||
break;
|
||||
}
|
||||
string::size_type i = 0, j;
|
||||
while ((j = str.find(delim, i)) != string::npos) {
|
||||
vec.push_back(str.substr(i, j - i));
|
||||
i = j + delim.size();
|
||||
}
|
||||
|
||||
return true;
|
||||
vec.push_back(str.substr(i));
|
||||
}
|
||||
|
||||
string strreplace (string orig, const string &search, const string &replace) {
|
||||
|
@ -85,8 +85,16 @@ int constrain(int x, int imin, int imax);
|
||||
|
||||
int evalIntConf(ConfIntHash& hash, const std::string &key, int def, int imin, int imax);
|
||||
|
||||
bool split(std::vector<std::string> &vec, const std::string &str,
|
||||
const std::string &delim, bool destructive=true);
|
||||
/**
|
||||
* Splits the given string on the given delimiter, returning the split elements
|
||||
* in the given vector.
|
||||
* A delimiter can be a string of multiple characters, in which case that
|
||||
* entire delimiter string acts as a single delimiter.
|
||||
* If the delimiter is empty, the entire string is returned as a single element.
|
||||
* Any previous contents of the vector are discarded.
|
||||
*/
|
||||
void split(std::vector<std::string>& vec, std::string const& str,
|
||||
std::string const& delim);
|
||||
|
||||
int intTransition(int from, int to, long int tickStart, long duration=500,
|
||||
long tickNow=-1);
|
||||
|
Loading…
Reference in New Issue
Block a user