diff options
author | Stef Walter <stef@memberwebs.com> | 2005-06-09 00:35:46 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2005-06-09 00:35:46 +0000 |
commit | 4385990c140d30559d88c016f79a7af6264781d1 (patch) | |
tree | b5703ee84beec011f87930e8bcd3c5436b945081 /src | |
parent | a0b518f62ffbf1bbaec8e62faec288f5d6103264 (diff) |
Fixes to the bookmarking code.
Diffstat (limited to 'src')
-rw-r--r-- | src/xmlcomposer.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp index 36d9728..2f77545 100644 --- a/src/xmlcomposer.cpp +++ b/src/xmlcomposer.cpp @@ -52,32 +52,30 @@ string formatInt(int num) } void tokenize(const string& str, StringArray& tokens, - const string& delim = " ", bool trim = false) + const string& delimiters = " \t", char quote = '\0') { - // Skip delimiters at beginning. - string::size_type lp = str.find_first_not_of(delim, 0); + string delim(delimiters); - // Find first "non-delimiter". - string::size_type p = str.find_first_of(delim, lp); + if(quote != '\0') + delim.append(1, quote); - while(string::npos != p || string::npos != lp) - { - string s = str.substr(lp, p - lp); + string::size_type p = 0; + string::size_type lp = 0; - if(trim) - { - string::size_type b = s.find_first_not_of(" \t"); - if(b != string::npos) - s.erase(0, b); - string::size_type e = s.find_last_not_of(" \t"); - if(e != string::npos) - s.erase(e + 1); - } + for(;;) + { + lp = str.find_first_not_of(delim, p); - tokens.push_back(s); + if(quote && lp != string::npos && lp != 0 && + str[lp - 1] == quote) + p = str.find(quote, lp); + else + p = str.find_first_of(delim, lp); + + if(string::npos == p && string::npos == lp) + break; - lp = str.find_first_not_of(delim, p); - p = str.find_first_of(delim, lp); + tokens.push_back(str.substr(lp, p - lp)); } } @@ -1085,24 +1083,24 @@ ON_CONTROLWORD(Field) else if(cw == "fldrslt") { StringArray codes; - tokenize(fieldCode, codes, "\"", true); + tokenize(fieldCode, codes, " ", '"'); if(codes.size() >= 2 && codes[0].compare(kFieldHyperlink) == 0) { AN_ELEMENT(kElRef); // is it a bookmark link? - if(codes.size() >= 4 && codes[1] == "\\l" && + if(codes.size() >= 3 && codes[1] == "\\l" && !codes[2].empty()) { - AN_ATTRIBUTE(kAtType, "bookmark"); + AN_ATTRIBUTE(kAtType, kValBookmark); AN_ATTRIBUTE(kAtTo, codes[2]); } // A normal hyperlink else { - AN_ATTRIBUTE(kAtType, "hyperlink"); + AN_ATTRIBUTE(kAtType, kValHyperlink); AN_ATTRIBUTE(kAtTo, codes[1]); } } |