diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/domhelpers.h | 2 | ||||
-rw-r--r-- | src/tags.h | 4 | ||||
-rw-r--r-- | src/xmlcomposer.cpp | 62 |
3 files changed, 50 insertions, 18 deletions
diff --git a/src/domhelpers.h b/src/domhelpers.h index 2c29da0..7d3a94d 100644 --- a/src/domhelpers.h +++ b/src/domhelpers.h @@ -43,6 +43,7 @@ #include <map> #include <stack> #include <set> +#include <vector> /* * DOMHelpers @@ -101,6 +102,7 @@ public: // Some other handy types typedef std::set<string> StringSet; +typedef std::vector<string> StringArray; typedef std::stack<DOM::Node> NodeStack; /* @@ -89,7 +89,6 @@ static const char* kElBookmark = "bookmark"; static const char* kElRef = "ref"; static const char* kElFont = "font"; static const char* kElOptions = "options"; -static const char* kElLink = "link"; // Attributes static const char* kAtName = "name"; @@ -105,7 +104,6 @@ static const char* kAtStart = "start"; static const char* kAtId = "id"; static const char* kAtTo = "to"; static const char* kAtSize = "size"; -static const char* kAtHref = "href"; static const char* kAtAlign = "align"; static const char* kAtIndent = "indent"; @@ -118,6 +116,8 @@ static const char* kValUpperRoman = "upper-roman"; static const char* kValArabic = "arabic"; static const char* kValNull = ""; static const char* kValFootNote = "footnote"; +static const char* kValBookmark = "bookmark"; +static const char* kValHyperlink = "hyperlink"; static const char* kValList = "list"; static const char* kValPara = "para"; static const char* kValTable = "table"; 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]); } } } |