summaryrefslogtreecommitdiff
path: root/src/FbTk/StringUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/StringUtil.cc')
-rw-r--r--src/FbTk/StringUtil.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index bd9a2df..5d6c742 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: StringUtil.cc,v 1.1 2003/04/26 18:12:47 fluxgen Exp $ 22// $Id: StringUtil.cc,v 1.2 2003/06/12 15:14:02 rathnor Exp $
23 23
24#include "StringUtil.hh" 24#include "StringUtil.hh"
25 25
@@ -99,7 +99,7 @@ string expandFilename(const std::string &filename) {
99 was found. 99 was found.
100*/ 100*/
101int getStringBetween(std::string& out, const char *instr, const char first, const char last, 101int getStringBetween(std::string& out, const char *instr, const char first, const char last,
102 const char *ok_chars) { 102 const char *ok_chars, bool allow_nesting) {
103 assert(first); 103 assert(first);
104 assert(last); 104 assert(last);
105 assert(instr); 105 assert(instr);
@@ -117,17 +117,26 @@ int getStringBetween(std::string& out, const char *instr, const char first, cons
117 return -i; //return position to error 117 return -i; //return position to error
118 118
119 // find the end of the token 119 // find the end of the token
120 std::string::size_type j = i; 120 std::string::size_type j = i, k;
121 int nesting = 0;
121 while (1) { 122 while (1) {
123 k = in.find_first_of(first, j+1);
122 j = in.find_first_of(last, j+1); 124 j = in.find_first_of(last, j+1);
123 if (j==std::string::npos) 125 if (j==std::string::npos)
124 return -in.size(); //send negative size 126 return -in.size(); //send negative size
125 127
128 if (allow_nesting && k < j && in[k-1] != '\\') {
129 nesting++;
130 j = k;
131 continue;
132 }
126 //we found the last char, check so it doesn't have a '\' before 133 //we found the last char, check so it doesn't have a '\' before
127 if (j>1 && in[j-1] != '\\') 134 if (j>1 && in[j-1] != '\\') {
128 break; 135 if (allow_nesting && nesting > 0) nesting--;
129 else if (j>1) { 136 else
130 in.erase(j-1, 1); //remove the '\' 137 break;
138 } else if (j>1 && !allow_nesting) { // we leave escapes if we're allowing nesting
139 in.erase(j-1, 1); //remove the '\'
131 j--; 140 j--;
132 total_add++; //save numchars removed so we can calculate totalpos 141 total_add++; //save numchars removed so we can calculate totalpos
133 } 142 }