summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2005-06-08 23:02:04 +0000
committerStef Walter <stef@memberwebs.com>2005-06-08 23:02:04 +0000
commita0b518f62ffbf1bbaec8e62faec288f5d6103264 (patch)
tree9c55c739718b13e76c8b922524b9883f73f87b41
parent02c4a48288108c030e3f4929afcb25babcb0914d (diff)
Support for links to bookmarks.
-rw-r--r--ChangeLog2
-rw-r--r--src/domhelpers.h2
-rw-r--r--src/tags.h4
-rw-r--r--src/xmlcomposer.cpp62
4 files changed, 51 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 42c31c7..6534f6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,7 +7,7 @@ Version 0.9.6
- Now has option for pretty printing output XML
- Displays version with '-v' argument
- Fixed problems with Unicode
- - Support for bookmarks.
+ - Support for bookmarks and links to bookmarks.
Version 0.9.5
- Allow conversions on stdin and stdout
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;
/*
diff --git a/src/tags.h b/src/tags.h
index be140d1..ca02b4b 100644
--- a/src/tags.h
+++ b/src/tags.h
@@ -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]);
}
}
}