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

« back to all changes in this revision

Viewing changes to src/modules/filters/greeklexattribs.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
 * greeklexattribs -    SWFilter descendant to set entry attributes for greek
 
4
 *                      lexicons
 
5
 */
 
6
 
 
7
 
 
8
#include <stdlib.h>
 
9
#include <ctype.h>
 
10
#include <string>
 
11
#include <greeklexattribs.h>
 
12
#include <swmodule.h>
 
13
 
 
14
using std::string;
 
15
 
 
16
SWORD_NAMESPACE_START
 
17
 
 
18
GreekLexAttribs::GreekLexAttribs() {
 
19
}
 
20
 
 
21
 
 
22
char GreekLexAttribs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
 
23
 
 
24
        if (module->isProcessEntryAttributes()) {
 
25
                const char *from;
 
26
                bool inAV = false;
 
27
                string phrase;
 
28
                string freq;
 
29
                char val[128], *valto;
 
30
                char wordstr[7];
 
31
                const char *currentPhrase = 0, *ch = 0;
 
32
                const char *currentPhraseEnd = 0;
 
33
                int number = 0;
 
34
 
 
35
 
 
36
                for (from = text.c_str(); *from; from++) {
 
37
                        if (inAV) {
 
38
                                if (currentPhrase == 0) {
 
39
                                        if (isalpha(*from))
 
40
                                                currentPhrase = from;
 
41
                                }
 
42
                                else {
 
43
                                        if ((!isalpha(*from)) && (*from != ' ') && (*from != '+') && (*from !='(') && (*from != ')') && (*from != '\'')) {
 
44
                                                if (*from == '<') {
 
45
                                                        if (!currentPhraseEnd)
 
46
                                                                currentPhraseEnd = from - 1;
 
47
                                                        for (; *from && *from != '>'; from++) {
 
48
                                                                if (!strncmp(from, "value=\"", 7)) {
 
49
                                                                        valto = val;
 
50
                                                                        from += 7;
 
51
                                                                        for (unsigned int i = 0; from[i] != '\"' && i < 127; i++)
 
52
                                                                                *valto++ = from[i];
 
53
                                                                        *valto = 0;
 
54
                                                                        sprintf(wordstr, "%03d", number+1);
 
55
                                                                        module->getEntryAttributes()["AVPhrase"][wordstr]["CompoundedWith"] = val;
 
56
                                                                        from += strlen(val);
 
57
                                                                }
 
58
                                                        }
 
59
                                                        continue;
 
60
                                                }
 
61
 
 
62
                                                phrase = "";
 
63
                                                phrase.append(currentPhrase, (int)(((currentPhraseEnd>currentPhrase)?currentPhraseEnd:from) - currentPhrase)-1);
 
64
                                                currentPhrase = from;
 
65
                                                while (*from && isdigit(*from)) from++;
 
66
                                                freq = "";
 
67
                                                freq.append(currentPhrase, (int)(from - currentPhrase));
 
68
                                                if ((freq.length() > 0) && (phrase.length() > 0)) {
 
69
                                                        sprintf(wordstr, "%03d", ++number);
 
70
                                                        if ((strchr(phrase.c_str(), '(') > phrase.c_str()) && (strchr(phrase.c_str(), ')') > phrase.c_str() + 1)) {
 
71
                                                                string tmp = phrase.substr(0, phrase.find_first_of("("));
 
72
                                                                phrase.erase(phrase.find_first_of("("), 1);
 
73
                                                                phrase.erase(phrase.find_first_of(")"), 1);
 
74
                                                                phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
 
75
                                                                module->getEntryAttributes()["AVPhrase"][wordstr]["Alt"] = phrase.c_str();
 
76
                                                                phrase = tmp;
 
77
                                                        }
 
78
                                                        phrase.erase(0,phrase.find_first_not_of("\r\n\v\t ")); phrase.erase(phrase.find_last_not_of("\r\n\v\t ")+1);
 
79
                                                        freq.erase(0,freq.find_first_not_of("\r\n\v\t ")); freq.erase(freq.find_last_not_of("\r\n\v\t ")+1);
 
80
                                                        module->getEntryAttributes()["AVPhrase"][wordstr]["Phrase"] = phrase.c_str();
 
81
                                                        module->getEntryAttributes()["AVPhrase"][wordstr]["Frequency"] = freq.c_str();
 
82
                                                        currentPhrase = 0;
 
83
                                                        currentPhraseEnd = 0;
 
84
                                                }
 
85
                                        }
 
86
                                }
 
87
                                if (*from == ';') inAV = false;
 
88
 
 
89
                        }
 
90
                        else if (!strncmp(from, "AV-", 3)) {
 
91
                                inAV = true;
 
92
                                from+=2;
 
93
                        }
 
94
                }
 
95
        }
 
96
        return 0;
 
97
}
 
98
 
 
99
 
 
100
SWORD_NAMESPACE_END