From b0317b695ad2cee33195d76778d62b15eb315218 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 29 Apr 2009 16:01:09 +0200 Subject: [PATCH] rewrite GetLineValue() function --- src/helpers.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index ce5b389a..253b666d 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -284,24 +284,16 @@ string FindSharedDir(const string &one, const string &two) string GetLineValue(string &line, char a, char b, bool once) { - int i = 0; - int begin = -1, end = -1; - for (string::iterator it = line.begin(); it != line.end() && (begin == -1 || end == -1); i++, it++) + int pos[2] = { -1, -1 }; + size_t i; + for (i = line.find(a); i != string::npos && pos[1] < 0; i = line.find(b, i)) { - if (*it == a || *it == b) - { - if (once) - *it = 0; - if (begin < 0) - begin = i+1; - else - end = i; - } + if (once) + line[i] = 0; + pos[pos[0] >= 0] = i++; } - if (begin >= 0 && end >= 0) - return line.substr(begin, end-begin); - else - return ""; + pos[0]++; + return pos[0] >= 0 && pos[1] >= 0 ? line.substr(pos[0], pos[1]-pos[0]) : ""; } void RemoveTheWord(string &s)