1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * Copyright (C) 2002-2022 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#ifndef MYSPELLMGR_HXX_
71#define MYSPELLMGR_HXX_
72
73#include "hunvisapi.h"
74#include "w_char.hxx"
75#include "atypes.hxx"
76#include <string>
77#include <vector>
78
79#define SPELL_XML "<?xml?>"
80
81#ifndef MAXSUGGESTION
82#define MAXSUGGESTION 15
83#endif
84
85#define MAXSHARPS 5
86
87#ifndef MAXWORDLEN
88#define MAXWORDLEN 100
89#endif
90
91#if defined __GNUC__ && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
92# define H_DEPRECATED __attribute__((__deprecated__))
93#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
94# define H_DEPRECATED __declspec(deprecated)
95#else
96# define H_DEPRECATED
97#endif
98
99class HunspellImpl;
100
101class LIBHUNSPELL_DLL_EXPORTED Hunspell {
102 private:
103 HunspellImpl* m_Impl;
104
105 public:
106 /* Hunspell(aff, dic) - constructor of Hunspell class
107 * input: path of affix file and dictionary file
108 *
109 * In WIN32 environment, use UTF-8 encoded paths started with the long path
110 * prefix \\\\?\\ to handle system-independent character encoding and very
111 * long path names (without the long path prefix Hunspell will use fopen()
112 * with system-dependent character encoding instead of _wfopen()).
113 */
114 Hunspell(const char* affpath, const char* dpath, const char* key = NULL);
115 Hunspell(const Hunspell&) = delete;
116 Hunspell& operator=(const Hunspell&) = delete;
117 ~Hunspell();
118
119 /* load extra dictionaries (only dic files) */
120 int add_dic(const char* dpath, const char* key = NULL);
121
122 /* spell(word) - spellcheck word
123 * output: false = bad word, true = good word
124 *
125 * plus output:
126 * info: information bit array, fields:
127 * SPELL_COMPOUND = a compound word
128 * SPELL_FORBIDDEN = an explicit forbidden word
129 * root: root (stem), when input is a word with affix(es)
130 */
131 bool spell(const std::string& word, int* info = NULL, std::string* root = NULL);
132 H_DEPRECATED int spell(const char* word, int* info = NULL, char** root = NULL);
133
134 /* suggest(suggestions, word) - search suggestions
135 * input: pointer to an array of strings pointer and the (bad) word
136 * array of strings pointer (here *slst) may not be initialized
137 * output: number of suggestions in string array, and suggestions in
138 * a newly allocated array of strings (*slts will be NULL when number
139 * of suggestion equals 0.)
140 */
141 std::vector<std::string> suggest(const std::string& word);
142 H_DEPRECATED int suggest(char*** slst, const char* word);
143
144 /* Suggest words from suffix rules
145 * suffix_suggest(suggestions, root_word)
146 * input: pointer to an array of strings pointer and the word
147 * array of strings pointer (here *slst) may not be initialized
148 * output: number of suggestions in string array, and suggestions in
149 * a newly allocated array of strings (*slts will be NULL when number
150 * of suggestion equals 0.)
151 */
152 std::vector<std::string> suffix_suggest(const std::string& root_word);
153 H_DEPRECATED int suffix_suggest(char*** slst, const char* root_word);
154
155 /* deallocate suggestion lists */
156 H_DEPRECATED void free_list(char*** slst, int n);
157
158 const std::string& get_dict_encoding() const;
159 char* get_dic_encoding();
160
161 /* morphological functions */
162
163 /* analyze(result, word) - morphological analysis of the word */
164 std::vector<std::string> analyze(const std::string& word);
165 H_DEPRECATED int analyze(char*** slst, const char* word);
166
167 /* stem(word) - stemmer function */
168 std::vector<std::string> stem(const std::string& word);
169 H_DEPRECATED int stem(char*** slst, const char* word);
170
171 /* stem(analysis, n) - get stems from a morph. analysis
172 * example:
173 * char ** result, result2;
174 * int n1 = analyze(&result, "words");
175 * int n2 = stem(&result2, result, n1);
176 */
177 std::vector<std::string> stem(const std::vector<std::string>& morph);
178 H_DEPRECATED int stem(char*** slst, char** morph, int n);
179
180 /* generate(result, word, word2) - morphological generation by example(s) */
181 std::vector<std::string> generate(const std::string& word, const std::string& word2);
182 H_DEPRECATED int generate(char*** slst, const char* word, const char* word2);
183
184 /* generate(result, word, desc, n) - generation by morph. description(s)
185 * example:
186 * char ** result;
187 * char * affix = "is:plural"; // description depends from dictionaries, too
188 * int n = generate(&result, "word", &affix, 1);
189 * for (int i = 0; i < n; i++) printf("%s\n", result[i]);
190 */
191 std::vector<std::string> generate(const std::string& word, const std::vector<std::string>& pl);
192 H_DEPRECATED int generate(char*** slst, const char* word, char** desc, int n);
193
194 /* functions for run-time modification of the dictionary */
195
196 /* add word to the run-time dictionary */
197
198 int add(const std::string& word);
199
200 /* add word to the run-time dictionary with affix flags of
201 * the example (a dictionary word): Hunspell will recognize
202 * affixed forms of the new word, too.
203 */
204
205 int add_with_affix(const std::string& word, const std::string& example);
206
207 /* remove word from the run-time dictionary */
208
209 int remove(const std::string& word);
210
211 /* other */
212
213 /* get extra word characters definied in affix file for tokenization */
214 const char* get_wordchars() const;
215 const std::string& get_wordchars_cpp() const;
216 const std::vector<w_char>& get_wordchars_utf16() const;
217
218 struct cs_info* get_csconv();
219
220 const char* get_version() const;
221 const std::string& get_version_cpp() const;
222
223 int get_langnum() const;
224
225 /* need for putdic */
226 bool input_conv(const std::string& word, std::string& dest);
227 H_DEPRECATED int input_conv(const char* word, char* dest, size_t destsize);
228};
229
230#endif
231

source code of include/hunspell/hunspell.hxx