diff options
Diffstat (limited to 'utilities/diatheke/thmlcgi.cpp')
-rw-r--r-- | utilities/diatheke/thmlcgi.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/utilities/diatheke/thmlcgi.cpp b/utilities/diatheke/thmlcgi.cpp index 1bcc5ba..9b85c35 100644 --- a/utilities/diatheke/thmlcgi.cpp +++ b/utilities/diatheke/thmlcgi.cpp @@ -1,11 +1,10 @@ -/*************************************************************************** - * thmlcgi.cpp - ThML to Diatheke/CGI format - * ------------------- - * begin : 2001-11-12 - * copyright : 2001 by CrossWire Bible Society +/****************************************************************************** * + * thmlcgi.cpp - ThMLCGI: ThML to Diatheke/CGI format filter * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * $Id: thmlcgi.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * + * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -23,11 +22,26 @@ #include <stdlib.h> #include <string.h> -#include "thmlcgi.h" +#include <map> #include <utilstr.h> +#include "thmlcgi.h" SWORD_NAMESPACE_START +typedef std::map<SWBuf, SWBuf> DualStringMap; + +namespace { + class MyUserData : public BasicFilterUserData { + public: + MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {} + DualStringMap properties; + }; +} + +BasicFilterUserData *ThMLCGI::createUserData(const SWModule *module, const SWKey *key) { + return new MyUserData(module, key); +} + ThMLCGI::ThMLCGI() { setTokenStart("<"); setTokenEnd(">"); @@ -39,7 +53,8 @@ ThMLCGI::ThMLCGI() { } -bool ThMLCGI::handleToken(SWBuf &buf, const char *token, DualStringMap &userData) { +bool ThMLCGI::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *baseUserData) { + MyUserData *userData = (MyUserData *) baseUserData; unsigned long i; if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution @@ -109,7 +124,7 @@ bool ThMLCGI::handleToken(SWBuf &buf, const char *token, DualStringMap &userData } else if (!strncmp(token, "scripRef p", 10) || !strncmp(token, "scripRef v", 10)) { - userData["inscriptRef"] = "true"; + userData->properties["inscriptRef"] = "true"; buf += "<a href=\"!DIATHEKE_URL!"; for (i = 9; i < strlen(token); i++) { if (!strncmp(token+i, "version=\"", 9)) { @@ -133,47 +148,47 @@ bool ThMLCGI::handleToken(SWBuf &buf, const char *token, DualStringMap &userData // we're starting a scripRef like "<scripRef>John 3:16</scripRef>" else if (!strcmp(token, "scripRef")) { - userData["inscriptRef"] = "false"; + userData->properties["inscriptRef"] = "false"; // let's stop text from going to output - userData["suspendTextPassThru"] = "true"; + userData->properties["suspendTextPassThru"] = "true"; } // we've ended a scripRef else if (!strcmp(token, "/scripRef")) { - if (userData["inscriptRef"] == "true") { // like "<scripRef passage="John 3:16">John 3:16</scripRef>" - userData["inscriptRef"] = "false"; + if (userData->properties["inscriptRef"] == "true") { // like "<scripRef passage="John 3:16">John 3:16</scripRef>" + userData->properties["inscriptRef"] = "false"; buf += "</a>"; } else { // like "<scripRef>John 3:16</scripRef>" buf += "<a href=\"!DIATHEKE_URL!verse="; - char* vref = (char*)userData["lastTextNode"].c_str(); + char* vref = (char*)userData->properties["lastTextNode"].c_str(); while (*vref) { if (*vref == ' ') buf += '+'; else buf += *vref; vref++; } buf += "\">"; - buf += userData["lastTextNode"].c_str(); + buf += userData->properties["lastTextNode"].c_str(); // let's let text resume to output again - userData["suspendTextPassThru"] = "false"; + userData->properties["suspendTextPassThru"] = "false"; buf += "</a>"; } } else if (!strncmp(token, "div class=\"sechead\"", 19)) { - userData["SecHead"] = "true"; + userData->properties["SecHead"] = "true"; buf += "<br /><b><i>"; } else if (!strncmp(token, "div class=\"title\"", 19)) { - userData["SecHead"] = "true"; + userData->properties["SecHead"] = "true"; buf += "<br /><b><i>"; } else if (!strncmp(token, "/div", 4)) { - if (userData["SecHead"] == "true") { + if (userData->properties["SecHead"] == "true") { buf += "</i></b><br />"; - userData["SecHead"] = "false"; + userData->properties["SecHead"] = "false"; } } |