1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * Copyright (C) 2002-2017 Németh László
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks.
17  *
18  * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno,
19  * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád,
20  * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter,
21  * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls,
22  * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 /*
38  * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada
39  * And Contributors.  All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  *
45  * 1. Redistributions of source code must retain the above copyright
46  *    notice, this list of conditions and the following disclaimer.
47  *
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  *
52  * 3. All modifications to the source code must be clearly marked as
53  *    such.  Binary redistributions based on modified source code
54  *    must be clearly marked as modified versions in the documentation
55  *    and/or other materials provided with the distribution.
56  *
57  * THIS SOFTWARE IS PROVIDED BY KEVIN B. HENDRICKS AND CONTRIBUTORS
58  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
59  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
60  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
61  * KEVIN B. HENDRICKS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
62  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
63  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  */
70 
71 #ifndef AFFIX_HXX_
72 #define AFFIX_HXX_
73 
74 #include "atypes.hxx"
75 #include "baseaffix.hxx"
76 #include "affixmgr.hxx"
77 
78 /* A Prefix Entry  */
79 
80 class PfxEntry : public AffEntry {
81  private:
82   PfxEntry(const PfxEntry&);
83   PfxEntry& operator=(const PfxEntry&);
84 
85  private:
86   AffixMgr* pmyMgr;
87 
88   PfxEntry* next;
89   PfxEntry* nexteq;
90   PfxEntry* nextne;
91   PfxEntry* flgnxt;
92 
93  public:
94   explicit PfxEntry(AffixMgr* pmgr);
95 
allowCross() const96   bool allowCross() const { return ((opts & aeXPRODUCT) != 0); }
97   struct hentry* checkword(const char* word,
98                            int len,
99                            char in_compound,
100                            const FLAG needflag = FLAG_NULL);
101 
102   struct hentry* check_twosfx(const char* word,
103                               int len,
104                               char in_compound,
105                               const FLAG needflag = FLAG_NULL);
106 
107   std::string check_morph(const char* word,
108                           int len,
109                           char in_compound,
110                           const FLAG needflag = FLAG_NULL);
111 
112   std::string check_twosfx_morph(const char* word,
113                                  int len,
114                                  char in_compound,
115                                  const FLAG needflag = FLAG_NULL);
116 
getFlag()117   FLAG getFlag() { return aflag; }
getKey()118   const char* getKey() { return appnd.c_str(); }
119   std::string add(const char* word, size_t len);
120 
getKeyLen()121   inline short getKeyLen() { return appnd.size(); }
122 
getMorph()123   inline const char* getMorph() { return morphcode; }
124 
getCont()125   inline const unsigned short* getCont() { return contclass; }
getContLen()126   inline short getContLen() { return contclasslen; }
127 
getNext()128   inline PfxEntry* getNext() { return next; }
getNextNE()129   inline PfxEntry* getNextNE() { return nextne; }
getNextEQ()130   inline PfxEntry* getNextEQ() { return nexteq; }
getFlgNxt()131   inline PfxEntry* getFlgNxt() { return flgnxt; }
132 
setNext(PfxEntry * ptr)133   inline void setNext(PfxEntry* ptr) { next = ptr; }
setNextNE(PfxEntry * ptr)134   inline void setNextNE(PfxEntry* ptr) { nextne = ptr; }
setNextEQ(PfxEntry * ptr)135   inline void setNextEQ(PfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(PfxEntry * ptr)136   inline void setFlgNxt(PfxEntry* ptr) { flgnxt = ptr; }
137 
138   inline char* nextchar(char* p);
139   inline int test_condition(const char* st);
140 };
141 
142 /* A Suffix Entry */
143 
144 class SfxEntry : public AffEntry {
145  private:
146   SfxEntry(const SfxEntry&);
147   SfxEntry& operator=(const SfxEntry&);
148 
149  private:
150   AffixMgr* pmyMgr;
151   std::string rappnd;
152 
153   SfxEntry* next;
154   SfxEntry* nexteq;
155   SfxEntry* nextne;
156   SfxEntry* flgnxt;
157 
158   SfxEntry* l_morph;
159   SfxEntry* r_morph;
160   SfxEntry* eq_morph;
161 
162  public:
163   explicit SfxEntry(AffixMgr* pmgr);
164 
allowCross() const165   bool allowCross() const { return ((opts & aeXPRODUCT) != 0); }
166   struct hentry* checkword(const char* word,
167                            int len,
168                            int optflags,
169                            PfxEntry* ppfx,
170                            const FLAG cclass,
171                            const FLAG needflag,
172                            const FLAG badflag);
173 
174   struct hentry* check_twosfx(const char* word,
175                               int len,
176                               int optflags,
177                               PfxEntry* ppfx,
178                               const FLAG needflag = FLAG_NULL);
179 
180   std::string check_twosfx_morph(const char* word,
181                                  int len,
182                                  int optflags,
183                                  PfxEntry* ppfx,
184                                  const FLAG needflag = FLAG_NULL);
185   struct hentry* get_next_homonym(struct hentry* he);
186   struct hentry* get_next_homonym(struct hentry* word,
187                                   int optflags,
188                                   PfxEntry* ppfx,
189                                   const FLAG cclass,
190                                   const FLAG needflag);
191 
getFlag()192   FLAG getFlag() { return aflag; }
getKey()193   const char* getKey() { return rappnd.c_str(); }
194   std::string add(const char* word, size_t len);
195 
getMorph()196   inline const char* getMorph() { return morphcode; }
197 
getCont()198   inline const unsigned short* getCont() { return contclass; }
getContLen()199   inline short getContLen() { return contclasslen; }
getAffix()200   inline const char* getAffix() { return appnd.c_str(); }
201 
getKeyLen()202   inline short getKeyLen() { return appnd.size(); }
203 
getNext()204   inline SfxEntry* getNext() { return next; }
getNextNE()205   inline SfxEntry* getNextNE() { return nextne; }
getNextEQ()206   inline SfxEntry* getNextEQ() { return nexteq; }
207 
getLM()208   inline SfxEntry* getLM() { return l_morph; }
getRM()209   inline SfxEntry* getRM() { return r_morph; }
getEQM()210   inline SfxEntry* getEQM() { return eq_morph; }
getFlgNxt()211   inline SfxEntry* getFlgNxt() { return flgnxt; }
212 
setNext(SfxEntry * ptr)213   inline void setNext(SfxEntry* ptr) { next = ptr; }
setNextNE(SfxEntry * ptr)214   inline void setNextNE(SfxEntry* ptr) { nextne = ptr; }
setNextEQ(SfxEntry * ptr)215   inline void setNextEQ(SfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(SfxEntry * ptr)216   inline void setFlgNxt(SfxEntry* ptr) { flgnxt = ptr; }
217   void initReverseWord();
218 
219   inline char* nextchar(char* p);
220   inline int test_condition(const char* st, const char* begin);
221 };
222 
223 #endif
224