diff options
author | Stef Walter <stef@memberwebs.com> | 2005-06-08 23:02:04 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2005-06-08 23:02:04 +0000 |
commit | a0b518f62ffbf1bbaec8e62faec288f5d6103264 (patch) | |
tree | 9c55c739718b13e76c8b922524b9883f73f87b41 /src/xmlcomposer.cpp | |
parent | 02c4a48288108c030e3f4929afcb25babcb0914d (diff) |
Support for links to bookmarks.
Diffstat (limited to 'src/xmlcomposer.cpp')
-rw-r--r-- | src/xmlcomposer.cpp | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp index b23a06c..36d9728 100644 --- a/src/xmlcomposer.cpp +++ b/src/xmlcomposer.cpp @@ -51,6 +51,36 @@ string formatInt(int num) return string(buff); } +void tokenize(const string& str, StringArray& tokens, + const string& delim = " ", bool trim = false) +{ + // Skip delimiters at beginning. + string::size_type lp = str.find_first_not_of(delim, 0); + + // Find first "non-delimiter". + string::size_type p = str.find_first_of(delim, lp); + + while(string::npos != p || string::npos != lp) + { + string s = str.substr(lp, p - lp); + + 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); + } + + tokens.push_back(s); + + lp = str.find_first_not_of(delim, p); + p = str.find_first_of(delim, lp); + } +} + /* ---------------------------------------------------------------------------------- * CONSTRUCTION */ @@ -1054,26 +1084,26 @@ ON_CONTROLWORD(Field) // And now we get to the precalculated field result... else if(cw == "fldrslt") { - // If we have a field code that we want to mess with ... - if(!fieldCode.empty()) + StringArray codes; + tokenize(fieldCode, codes, "\"", true); + + if(codes.size() >= 2 && codes[0].compare(kFieldHyperlink) == 0) { - // Try to find a field code we recognize - wstring::size_type p = fieldCode.find_first_not_of(" \t"); + AN_ELEMENT(kElRef); - if(fieldCode.compare(p, kFieldHyperlink.size(), kFieldHyperlink) == 0) + // is it a bookmark link? + if(codes.size() >= 4 && codes[1] == "\\l" && + !codes[2].empty()) { - p += kFieldHyperlink.size(); - - // Find first quote - p = fieldCode.find('"', p); - p = (p == string::npos) ? 0 : p + 1; - - // And the end quote - wstring::size_type e = fieldCode.find('"', p); - e = (e == string::npos) ? string::npos : e - p; + AN_ATTRIBUTE(kAtType, "bookmark"); + AN_ATTRIBUTE(kAtTo, codes[2]); + } - AN_ELEMENT(kElLink); - AN_ATTRIBUTE(kAtHref, fieldCode.substr(p, e)); + // A normal hyperlink + else + { + AN_ATTRIBUTE(kAtType, "hyperlink"); + AN_ATTRIBUTE(kAtTo, codes[1]); } } } |