~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/modules/filters/osislemma.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *
 
3
 * osislemma          - SWFilter descendant to hide or show lemmata
 
4
 *                      in a OSIS module.
 
5
 */
 
6
 
 
7
 
 
8
#include <stdlib.h>
 
9
#include <osislemma.h>
 
10
#include <utilxml.h>
 
11
#ifndef __GNUC__
 
12
#else
 
13
#include <unixstr.h>
 
14
#endif
 
15
 
 
16
SWORD_NAMESPACE_START
 
17
 
 
18
const char oName[] = "Lemmas";
 
19
const char oTip[] = "Toggles Lemmas On and Off if they exist";
 
20
 
 
21
const SWBuf choices[3] = {"On", "Off", ""};
 
22
const StringList oValues(&choices[0], &choices[2]);
 
23
 
 
24
OSISLemma::OSISLemma() : SWOptionFilter(oName, oTip, &oValues) {
 
25
        setOptionValue("Off");
 
26
}
 
27
 
 
28
 
 
29
OSISLemma::~OSISLemma() {
 
30
}
 
31
 
 
32
 
 
33
char OSISLemma::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
 
34
        if (!option) {  // if we don't want lemmas
 
35
                const char *from;
 
36
                char token[2048]; // cheese.  Fix.
 
37
                int tokpos = 0;
 
38
                bool intoken = false;
 
39
                bool lastspace = false;
 
40
                SWBuf orig = text;
 
41
                from = orig.c_str();
 
42
 
 
43
                for (text = ""; *from; from++) {
 
44
                        if (*from == '<') {
 
45
                                intoken = true;
 
46
                                tokpos = 0;
 
47
                                token[0] = 0;
 
48
                                continue;
 
49
                        }
 
50
                        if (*from == '>') {     // process tokens
 
51
                                intoken = false;
 
52
                                XMLTag tag(token);
 
53
                                if ((!strcmp(tag.getName(), "w")) && (!tag.isEndTag())) {       // Lemma
 
54
                                        SWBuf lemma = tag.getAttribute("lemma");
 
55
                                        if (lemma.length()) {
 
56
                                                tag.setAttribute("lemma", 0);
 
57
                                                tag.setAttribute("savlm", lemma.c_str());
 
58
                                        }
 
59
                                }
 
60
                                // keep tag, possibly with the lemma removed
 
61
                                text += tag;
 
62
                                continue;
 
63
                        }
 
64
                        if (intoken) {
 
65
                                if (tokpos < 2045)
 
66
                                        token[tokpos++] = *from;
 
67
                                        token[tokpos] = 0;
 
68
                        }
 
69
                        else    {
 
70
                                text += *from;
 
71
                                lastspace = (*from == ' ');
 
72
                        }
 
73
                }
 
74
        }
 
75
        return 0;
 
76
}
 
77
 
 
78
SWORD_NAMESPACE_END