[sword-svn] r1884 - in trunk: include src/modules/filters
chrislit at crosswire.org
chrislit at crosswire.org
Wed Jan 11 12:48:05 MST 2006
Author: chrislit
Date: 2006-01-11 12:45:21 -0700 (Wed, 11 Jan 2006)
New Revision: 1884
Added:
trunk/include/osismorphsegmentation.h
trunk/src/modules/filters/osismorphsegmentation.cpp
Log:
added OSISMorphSegmentation files (from BibleTime) to repository; not integrated into projects/make system yet
Added: trunk/include/osismorphsegmentation.h
===================================================================
--- trunk/include/osismorphsegmentation.h 2006-01-06 15:18:31 UTC (rev 1883)
+++ trunk/include/osismorphsegmentation.h 2006-01-11 19:45:21 UTC (rev 1884)
@@ -0,0 +1,45 @@
+/******************************************************************************
+ *
+ * $Id: osismorphsegmentation.h,v 1.3 2005/09/02 22:15:30 joachim Exp $
+ *
+ * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#ifndef OSISMORPHSEGMENTATION_H
+#define OSISMORPHSEGMENTATION_H
+
+#include <swoptfilter.h>
+
+using namespace sword;
+
+namespace Filters {
+
+ /* This filters toggles splitting of morphemes
+ * (for morpheme segmented Hebrew in the WLC)
+ */
+
+class OSISMorphSegmentation : public SWOptionFilter {
+
+public:
+ OSISMorphSegmentation();
+ virtual ~OSISMorphSegmentation();
+
+ virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+ };
+
+}
+
+#endif
Added: trunk/src/modules/filters/osismorphsegmentation.cpp
===================================================================
--- trunk/src/modules/filters/osismorphsegmentation.cpp 2006-01-06 15:18:31 UTC (rev 1883)
+++ trunk/src/modules/filters/osismorphsegmentation.cpp 2006-01-11 19:45:21 UTC (rev 1884)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ *
+ * osismorphsegmentation - SWFilter descendant to toggle splitting of morphemes
+ * (for morpheme segmented Hebrew in the WLC)
+ */
+
+
+#include <osismorphsegmentation.h>
+#include <stdlib.h>
+#include <swmodule.h>
+#include <swbuf.h>
+#include <versekey.h>
+#include <utilxml.h>
+#include <utilstr.h>
+
+const char oName[] = "Morpheme segmentation";
+const char oTip[] = "Toggles morpheme segmentation, when present";
+
+const SWBuf choices[3] = {"Off", "On", ""
+ };
+
+const StringList oValues(&choices[0], &choices[2]);
+
+namespace Filters {
+
+OSISMorphSegmentation::OSISMorphSegmentation() : sword::SWOptionFilter(oName, oTip, &oValues) {
+ setOptionValue("Off");
+ }
+
+
+ OSISMorphSegmentation::~OSISMorphSegmentation() {}
+
+
+ char OSISMorphSegmentation::processText(SWBuf &text, const SWKey */*key*/, const SWModule */*module*/) {
+ SWBuf token;
+ bool intoken = false;
+ bool hide = false;
+
+ SWBuf orig( text );
+ const char *from = orig.c_str();
+
+ XMLTag tag;
+
+ for (text = ""; *from; ++from) {
+ if (*from == '<') {
+ intoken = true;
+ token = "";
+ continue;
+ }
+
+ if (*from == '>') { // process tokens
+ intoken = false;
+
+ if (!strncmp(token.c_str(), "seg ", 4) || !strncmp(token.c_str(), "/seg", 4)) {
+ tag = token;
+
+ if (!tag.isEndTag() && tag.getAttribute("type") && !strcmp("morph", tag.getAttribute("type"))) { //<seg type="morph"> start tag
+ hide = !option; //only hide if option is Off
+ }
+
+ if (hide) { //hides start and end tags as long as hide is set
+
+ if (tag.isEndTag()) { //</seg>
+ hide = false;
+ }
+
+ continue; //leave out the current token
+ }
+ } //end of seg tag handling
+
+ text.append('<');
+
+ text.append(token);
+
+ text.append('>');
+
+ hide = false;
+
+ continue;
+ } //end of intoken part
+
+ if (intoken) { //copy token
+ token.append(*from);
+ }
+ else { //copy text which is not inside of a tag
+ text.append(*from);
+ }
+ }
+
+ return 0;
+ }
+
+}
More information about the sword-cvs
mailing list