Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / extensions / spellcheck / hunspell / src / hunspell.hxx
blob4f0121050dac03956ea8ca29c82913d381196c69
1 /******* BEGIN LICENSE BLOCK *******
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Initial Developers of the Original Code are Kevin Hendricks (MySpell)
15 * and László Németh (Hunspell). Portions created by the Initial Developers
16 * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved.
18 * Contributor(s): Kevin Hendricks (kevin.hendricks@sympatico.ca)
19 * David Einstein (deinst@world.std.com)
20 * László Németh (nemethl@gyorsposta.hu)
21 * Davide Prina
22 * Giuseppe Modugno
23 * Gianluca Turconi
24 * Simon Brouwer
25 * Noll Janos
26 * Biro Arpad
27 * Goldman Eleonora
28 * Sarlos Tamas
29 * Bencsath Boldizsar
30 * Halacsy Peter
31 * Dvornik Laszlo
32 * Gefferth Andras
33 * Nagy Viktor
34 * Varga Daniel
35 * Chris Halls
36 * Rene Engelhard
37 * Bram Moolenaar
38 * Dafydd Jones
39 * Harri Pitkanen
40 * Andras Timar
41 * Tor Lillqvist
43 * Alternatively, the contents of this file may be used under the terms of
44 * either the GNU General Public License Version 2 or later (the "GPL"), or
45 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
46 * in which case the provisions of the GPL or the LGPL are applicable instead
47 * of those above. If you wish to allow use of your version of this file only
48 * under the terms of either the GPL or the LGPL, and not to allow others to
49 * use your version of this file under the terms of the MPL, indicate your
50 * decision by deleting the provisions above and replace them with the notice
51 * and other provisions required by the GPL or the LGPL. If you do not delete
52 * the provisions above, a recipient may use your version of this file under
53 * the terms of any one of the MPL, the GPL or the LGPL.
55 ******* END LICENSE BLOCK *******/
57 #include "affixmgr.hxx"
58 #include "hashmgr.hxx"
59 #include "langnum.hxx"
60 #include "suggestmgr.hxx"
62 #define SPELL_COMPOUND (1 << 0)
63 #define SPELL_FORBIDDEN (1 << 1)
64 #define SPELL_ALLCAP (1 << 2)
65 #define SPELL_NOCAP (1 << 3)
66 #define SPELL_INITCAP (1 << 4)
68 #define SPELL_XML "<?xml?>"
70 #define MAXDIC 20
71 #define MAXSUGGESTION 15
72 #define MAXSHARPS 5
74 #ifndef _MYSPELLMGR_HXX_
75 #define _MYSPELLMGR_HXX_
77 #ifdef HUNSPELL_STATIC
78 #define DLLEXPORT
79 #else
80 #ifdef HUNSPELL_EXPORTS
81 #define DLLEXPORT __declspec( dllexport )
82 #else
83 #define DLLEXPORT __declspec( dllimport )
84 #endif
85 #endif
87 #ifdef W32
88 class DLLEXPORT Hunspell
89 #else
90 class Hunspell
91 #endif
93 AffixMgr* pAMgr;
94 HashMgr* pHMgr[MAXDIC];
95 int maxdic;
96 SuggestMgr* pSMgr;
97 char * affixpath;
98 char * encoding;
99 struct cs_info * csconv;
100 int langnum;
101 int utf8;
102 int complexprefixes;
103 char** wordbreak;
105 public:
107 /* Hunspell(aff, dic) - constructor of Hunspell class
108 * input: path of affix file and dictionary file
111 Hunspell(const char * affpath, const char * dpath, const char * key = NULL);
112 ~Hunspell();
114 /* load extra dictionaries (only dic files) */
115 int add_dic(const char * dpath, const char * key = NULL);
117 /* spell(word) - spellcheck word
118 * output: 0 = bad word, not 0 = good word
120 * plus output:
121 * info: information bit array, fields:
122 * SPELL_COMPOUND = a compound word
123 * SPELL_FORBIDDEN = an explicit forbidden word
124 * root: root (stem), when input is a word with affix(es)
127 int spell(const char * word, int * info = NULL, char ** root = NULL);
129 /* suggest(suggestions, word) - search suggestions
130 * input: pointer to an array of strings pointer and the (bad) word
131 * array of strings pointer (here *slst) may not be initialized
132 * output: number of suggestions in string array, and suggestions in
133 * a newly allocated array of strings (*slts will be NULL when number
134 * of suggestion equals 0.)
137 int suggest(char*** slst, const char * word);
139 /* deallocate suggestion lists */
141 void free_list(char *** slst, int n);
143 char * get_dic_encoding();
145 /* morphological functions */
147 /* analyze(result, word) - morphological analysis of the word */
149 int analyze(char*** slst, const char * word);
151 /* stem(result, word) - stemmer function */
153 int stem(char*** slst, const char * word);
155 /* stem(result, analysis, n) - get stems from a morph. analysis
156 * example:
157 * char ** result, result2;
158 * int n1 = analyze(&result, "words");
159 * int n2 = stem(&result2, result, n1);
162 int stem(char*** slst, char ** morph, int n);
164 /* generate(result, word, word2) - morphological generation by example(s) */
166 int generate(char*** slst, const char * word, const char * word2);
168 /* generate(result, word, desc, n) - generation by morph. description(s)
169 * example:
170 * char ** result;
171 * char * affix = "is:plural"; // description depends from dictionaries, too
172 * int n = generate(&result, "word", &affix, 1);
173 * for (int i = 0; i < n; i++) printf("%s\n", result[i]);
176 int generate(char*** slst, const char * word, char ** desc, int n);
178 /* functions for run-time modification of the dictionary */
180 /* add word to the run-time dictionary */
182 int add(const char * word);
184 /* add word to the run-time dictionary with affix flags of
185 * the example (a dictionary word): Hunspell will recognize
186 * affixed forms of the new word, too.
189 int add_with_affix(const char * word, const char * example);
191 /* remove word from the run-time dictionary */
193 int remove(const char * word);
195 /* other */
197 /* get extra word characters definied in affix file for tokenization */
198 const char * get_wordchars();
199 unsigned short * get_wordchars_utf16(int * len);
201 struct cs_info * get_csconv();
202 const char * get_version();
204 /* experimental and deprecated functions */
206 #ifdef HUNSPELL_EXPERIMENTAL
207 /* suffix is an affix flag string, similarly in dictionary files */
208 int put_word_suffix(const char * word, const char * suffix);
209 char * morph_with_correction(const char * word);
211 /* spec. suggestions */
212 int suggest_auto(char*** slst, const char * word);
213 int suggest_pos_stems(char*** slst, const char * word);
214 char * get_possible_root();
215 #endif
217 private:
218 int cleanword(char *, const char *, int * pcaptype, int * pabbrev);
219 int cleanword2(char *, const char *, w_char *, int * w_len, int * pcaptype, int * pabbrev);
220 void mkinitcap(char *);
221 int mkinitcap2(char * p, w_char * u, int nc);
222 int mkinitsmall2(char * p, w_char * u, int nc);
223 void mkallcap(char *);
224 int mkallcap2(char * p, w_char * u, int nc);
225 void mkallsmall(char *);
226 int mkallsmall2(char * p, w_char * u, int nc);
227 struct hentry * checkword(const char *, int * info, char **root);
228 char * sharps_u8_l1(char * dest, char * source);
229 hentry * spellsharps(char * base, char *, int, int, char * tmp, int * info, char **root);
230 int is_keepcase(const hentry * rv);
231 int insert_sug(char ***slst, char * word, int ns);
232 void cat_result(char * result, char * st);
233 char * stem_description(const char * desc);
234 int spellml(char*** slst, const char * word);
235 int get_xml_par(char * dest, const char * par, int maxl);
236 const char * get_xml_pos(const char * s, const char * attr);
237 int get_xml_list(char ***slst, char * list, const char * tag);
238 int check_xml_par(const char * q, const char * attr, const char * value);
242 #endif