diff options
Diffstat (limited to 'src/modules/filters/thmllemma.cpp')
-rw-r--r-- | src/modules/filters/thmllemma.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/modules/filters/thmllemma.cpp b/src/modules/filters/thmllemma.cpp new file mode 100644 index 0000000..3e5761d --- /dev/null +++ b/src/modules/filters/thmllemma.cpp @@ -0,0 +1,65 @@ +/****************************************************************************** + * + * thmllemma - SWFilter descendant to hide or show lemmas + * in a ThML module. + */ + + +#include <stdlib.h> +#include <thmllemma.h> + +SWORD_NAMESPACE_START + +const char oName[] = "Lemmas"; +const char oTip[] = "Toggles Lemmas On and Off if they exist"; + +const SWBuf choices[3] = {"Off", "On", ""}; +const StringList oValues(&choices[0], &choices[2]); + +ThMLLemma::ThMLLemma() : SWOptionFilter(oName, oTip, &oValues) { + setOptionValue("Off"); +} + + +ThMLLemma::~ThMLLemma() { +} + + +char ThMLLemma::processText(SWBuf &text, const SWKey *key, const SWModule *module) { + if (!option) { // if we don't want lemmas + bool intoken = false; + + SWBuf token; + SWBuf orig = text; + const char *from = orig.c_str(); + for (text = ""; *from; from++) { + if (*from == '<') { + intoken = true; + token = ""; + continue; + } + if (*from == '>') { // process tokens + intoken = false; + if (!strncmp(token.c_str(), "sync ", 5) && strstr(token.c_str(), "type=\"lemma\"")) { // Lemma + continue; + } + + // if not a lemma token, keep token in text + text += '<'; + text += token; + text += '>'; + continue; + } + + if (intoken) { + token += *from; + } + else { + text += *from; + } + } + } + return 0; +} + +SWORD_NAMESPACE_END |