rewrite GetLineValue() function

This commit is contained in:
Andrzej Rybczak
2009-04-29 16:01:09 +02:00
parent 4c8a70aef5
commit b0317b695a

View File

@@ -284,24 +284,16 @@ string FindSharedDir(const string &one, const string &two)
string GetLineValue(string &line, char a, char b, bool once) string GetLineValue(string &line, char a, char b, bool once)
{ {
int i = 0; int pos[2] = { -1, -1 };
int begin = -1, end = -1; size_t i;
for (string::iterator it = line.begin(); it != line.end() && (begin == -1 || end == -1); i++, it++) for (i = line.find(a); i != string::npos && pos[1] < 0; i = line.find(b, i))
{ {
if (*it == a || *it == b) if (once)
{ line[i] = 0;
if (once) pos[pos[0] >= 0] = i++;
*it = 0;
if (begin < 0)
begin = i+1;
else
end = i;
}
} }
if (begin >= 0 && end >= 0) pos[0]++;
return line.substr(begin, end-begin); return pos[0] >= 0 && pos[1] >= 0 ? line.substr(pos[0], pos[1]-pos[0]) : "";
else
return "";
} }
void RemoveTheWord(string &s) void RemoveTheWord(string &s)