diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:49 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:49 -0400 |
commit | 8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch) | |
tree | da38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/modules/filters/gbfmorph.cpp | |
parent | 8d3fc864d094eeadc721f8e93436b37a5fab173e (diff) |
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/filters/gbfmorph.cpp')
-rw-r--r-- | src/modules/filters/gbfmorph.cpp | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/modules/filters/gbfmorph.cpp b/src/modules/filters/gbfmorph.cpp index f8d336e..996baf9 100644 --- a/src/modules/filters/gbfmorph.cpp +++ b/src/modules/filters/gbfmorph.cpp @@ -1,62 +1,47 @@ /****************************************************************************** * - * gbfmorph - SWFilter decendant to hide or show morph tags + * gbfmorph - SWFilter descendant to hide or show morph tags * in a GBF module. */ #include <stdlib.h> -#include <string.h> #include <gbfmorph.h> #ifndef __GNUC__ #else #include <unixstr.h> #endif +SWORD_NAMESPACE_START -const char GBFMorph::on[] = "On"; -const char GBFMorph::off[] = "Off"; -const char GBFMorph::optName[] = "Morphological Tags"; -const char GBFMorph::optTip[] = "Toggles Morphological Tags On and Off if they exist"; +const char oName[] = "Morphological Tags"; +const char oTip[] = "Toggles Morphological Tags On and Off if they exist"; +const SWBuf choices[3] = {"On", "Off", ""}; +const StringList oValues(&choices[0], &choices[2]); -GBFMorph::GBFMorph() { - option = false; - options.push_back(on); - options.push_back(off); +GBFMorph::GBFMorph() : SWOptionFilter(oName, oTip, &oValues) { + setOptionValue("Off"); } GBFMorph::~GBFMorph() { } -void GBFMorph::setOptionValue(const char *ival) -{ - option = (!stricmp(ival, on)); -} - -const char *GBFMorph::getOptionValue() -{ - return (option) ? on:off; -} -char GBFMorph::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) -{ +char GBFMorph::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (!option) { // if we don't want morph tags - char *to, *from, token[2048]; // cheese. Fix. + const char *from; + char token[2048]; // cheese. Fix. int tokpos = 0; bool intoken = false; int len; bool lastspace = false; - len = strlen(text) + 1; // shift string to right of buffer - if (len < maxlen) { - memmove(&text[maxlen - len], text, len); - from = &text[maxlen - len]; - } - else from = text; // ------------------------------- + SWBuf orig = text; + from = orig.c_str(); - for (to = text; *from; from++) { + for (text = ""; *from; from++) { if (*from == '<') { intoken = true; tokpos = 0; @@ -70,15 +55,14 @@ char GBFMorph::ProcessText(char *text, int maxlen, const SWKey *key, const SWMod if (*token == 'W' && token[1] == 'T') { // Morph if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) { if (lastspace) - to--; + text--; } continue; } // if not a morph tag token, keep token in text - *to++ = '<'; - for (char *tok = token; *tok; tok++) - *to++ = *tok; - *to++ = '>'; + text += '<'; + text += token; + text += '>'; continue; } if (intoken) { @@ -87,12 +71,12 @@ char GBFMorph::ProcessText(char *text, int maxlen, const SWKey *key, const SWMod token[tokpos+2] = 0; } else { - *to++ = *from; + text += *from; lastspace = (*from == ' '); } } - *to++ = 0; - *to = 0; } return 0; } + +SWORD_NAMESPACE_END |