summaryrefslogtreecommitdiff
path: root/src/modules/filters/thmlstrongs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/thmlstrongs.cpp')
-rw-r--r--src/modules/filters/thmlstrongs.cpp83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/modules/filters/thmlstrongs.cpp b/src/modules/filters/thmlstrongs.cpp
index 8d0466c..4a53e25 100644
--- a/src/modules/filters/thmlstrongs.cpp
+++ b/src/modules/filters/thmlstrongs.cpp
@@ -1,50 +1,40 @@
/******************************************************************************
*
- * thmlstrongs - SWFilter decendant to hide or show strongs number
+ * thmlstrongs - SWFilter descendant to hide or show strongs number
* in a ThML module.
*/
#include <stdlib.h>
#include <stdio.h>
-#include <string.h>
#include <thmlstrongs.h>
#include <swmodule.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
#endif
+#include <ctype.h>
+SWORD_NAMESPACE_START
-const char ThMLStrongs::on[] = "On";
-const char ThMLStrongs::off[] = "Off";
-const char ThMLStrongs::optName[] = "Strong's Numbers";
-const char ThMLStrongs::optTip[] = "Toggles Strong's Numbers On and Off if they exist";
+const char oName[] = "Strong's Numbers";
+const char oTip[] = "Toggles Strong's Numbers On and Off if they exist";
+const SWBuf choices[3] = {"On", "Off", ""};
+const StringList oValues(&choices[0], &choices[2]);
-ThMLStrongs::ThMLStrongs() {
- option = false;
- options.push_back(on);
- options.push_back(off);
+ThMLStrongs::ThMLStrongs() : SWOptionFilter(oName, oTip, &oValues) {
+ setOptionValue("Off");
}
ThMLStrongs::~ThMLStrongs() {
}
-void ThMLStrongs::setOptionValue(const char *ival)
-{
- option = (!stricmp(ival, on));
-}
-
-const char *ThMLStrongs::getOptionValue()
-{
- return (option) ? on:off;
-}
-char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
-{
- char *to, *from, token[2048]; // cheese. Fix.
+char ThMLStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+ char token[2048]; // cheese. Fix.
+ const char *from;
int tokpos = 0;
bool intoken = false;
int len;
@@ -54,23 +44,21 @@ char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SW
char wordstr[5];
char *valto;
char *ch;
+ unsigned int textStart = 0, textEnd = 0;
+ SWBuf tmp;
+ bool newText = 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;
token[0] = 0;
token[1] = 0;
token[2] = 0;
+ textEnd = text.length();
continue;
}
if (*from == '>') { // process tokens
@@ -81,15 +69,28 @@ char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SW
for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
*valto++ = token[i];
*valto = 0;
- sprintf(wordstr, "%03d", word++);
- module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
+ if (atoi((!isdigit(*val))?val+1:val) < 5627) {
+ // normal strongs number
+ sprintf(wordstr, "%03d", word++);
+ module->getEntryAttributes()["Word"][wordstr]["Strongs"] = val;
+ tmp = "";
+ tmp.append(text.c_str()+textStart, (int)(textEnd - textStart));
+ module->getEntryAttributes()["Word"][wordstr]["Text"] = tmp;
+ newText = true;
+ }
+ else {
+ // verb morph
+ sprintf(wordstr, "%03d", word-1);
+ module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
+ }
}
if (!option) { // if we don't want strongs
if ((from[1] == ' ') || (from[1] == ',') || (from[1] == ';') || (from[1] == '.') || (from[1] == '?') || (from[1] == '!') || (from[1] == ')') || (from[1] == '\'') || (from[1] == '\"')) {
if (lastspace)
- to--;
+ text--;
}
+ if (newText) {textStart = text.length(); newText = false; }
continue;
}
}
@@ -116,10 +117,10 @@ char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SW
}
}
// if not a strongs token, keep token in text
- *to++ = '<';
- for (char *tok = token; *tok; tok++)
- *to++ = *tok;
- *to++ = '>';
+ text += '<';
+ text += token;
+ text += '>';
+ if (newText) {textStart = text.length(); newText = false; }
continue;
}
if (intoken) {
@@ -128,11 +129,11 @@ char ThMLStrongs::ProcessText(char *text, int maxlen, const SWKey *key, const SW
token[tokpos+2] = 0;
}
else {
- *to++ = *from;
+ text += *from;
lastspace = (*from == ' ');
}
}
- *to++ = 0;
- *to = 0;
return 0;
}
+
+SWORD_NAMESPACE_END