Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1115)

Side by Side Diff: google.patch

Issue 12328121: Use up to 8 affixes in Hunspell spellcheck suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/hunspell.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 Index: src/hunspell/affixmgr.cxx 1 Index: src/hunspell/affixmgr.cxx
2 =================================================================== 2 ===================================================================
3 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.cxx,v 3 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.cxx,v
4 retrieving revision 1.41 4 retrieving revision 1.41
5 diff -u -r1.41 affixmgr.cxx 5 diff -u -p -r1.41 affixmgr.cxx
6 --- src/hunspell/affixmgr.cxx 16 Dec 2011 09:15:34 -0000 1.41 6 --- src/hunspell/affixmgr.cxx 16 Dec 2011 09:15:34 -0000 1.41
7 +++ src/hunspell/affixmgr.cxx» 8 Jan 2013 00:30:25 -0000 7 +++ src/hunspell/affixmgr.cxx» 26 Feb 2013 23:13:13 -0000
8 @@ -14,8 +14,14 @@ 8 @@ -14,8 +14,14 @@
9 9
10 #include "csutil.hxx" 10 #include "csutil.hxx"
11 11
12 +#ifdef HUNSPELL_CHROME_CLIENT 12 +#ifdef HUNSPELL_CHROME_CLIENT
13 +AffixMgr::AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md) 13 +AffixMgr::AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md)
14 +{ 14 +{
15 + bdict_reader = reader; 15 + bdict_reader = reader;
16 +#else 16 +#else
17 AffixMgr::AffixMgr(const char * affpath, HashMgr** ptr, int * md, const char * key) 17 AffixMgr::AffixMgr(const char * affpath, HashMgr** ptr, int * md, const char * key)
18 { 18 {
19 +#endif 19 +#endif
20 // register hash manager and load affix data from aff file 20 // register hash manager and load affix data from aff file
21 pHMgr = ptr[0]; 21 pHMgr = ptr[0];
22 alldic = ptr; 22 alldic = ptr;
23 @@ -107,9 +113,17 @@ 23 @@ -107,9 +113,17 @@ AffixMgr::AffixMgr(const char * affpath,
24 sFlag[i] = NULL; 24 sFlag[i] = NULL;
25 } 25 }
26 26
27 +#ifdef HUNSPELL_CHROME_CLIENT 27 +#ifdef HUNSPELL_CHROME_CLIENT
28 + // Define dummy parameters for parse_file() to avoid changing the parameters 28 + // Define dummy parameters for parse_file() to avoid changing the parameters
29 + // of parse_file(). This may make it easier to merge the changes of the 29 + // of parse_file(). This may make it easier to merge the changes of the
30 + // original hunspell. 30 + // original hunspell.
31 + const char* affpath = NULL; 31 + const char* affpath = NULL;
32 + const char* key = NULL; 32 + const char* key = NULL;
33 +#else 33 +#else
34 for (int j=0; j < CONTSIZE; j++) { 34 for (int j=0; j < CONTSIZE; j++) {
35 contclasses[j] = 0; 35 contclasses[j] = 0;
36 } 36 }
37 +#endif 37 +#endif
38 38
39 if (parse_file(affpath, key)) { 39 if (parse_file(affpath, key)) {
40 HUNSPELL_WARNING(stderr, "Failure loading aff file %s\n",affpath); 40 HUNSPELL_WARNING(stderr, "Failure loading aff file %s\n",affpath);
41 @@ -269,6 +283,43 @@ 41 @@ -269,6 +283,43 @@ int AffixMgr::parse_file(const char * a
42 char * line; // io buffers 42 char * line; // io buffers
43 char ft; // affix type 43 char ft; // affix type
44 44
45 +#ifdef HUNSPELL_CHROME_CLIENT 45 +#ifdef HUNSPELL_CHROME_CLIENT
46 + // open the affix file 46 + // open the affix file
47 + // We're always UTF-8 47 + // We're always UTF-8
48 + utf8 = 1; 48 + utf8 = 1;
49 + 49 +
50 + // A BDICT file stores PFX and SFX lines in a special section and it provides 50 + // A BDICT file stores PFX and SFX lines in a special section and it provides
51 + // a special line iterator for reading PFX and SFX lines. 51 + // a special line iterator for reading PFX and SFX lines.
(...skipping 23 matching lines...) Expand all
75 + FileMgr * afflst = new FileMgr(&other_iterator); 75 + FileMgr * afflst = new FileMgr(&other_iterator);
76 + if (!afflst) { 76 + if (!afflst) {
77 + HUNSPELL_WARNING(stderr, 77 + HUNSPELL_WARNING(stderr,
78 + "error: could not create a FileMgr from an other line iterator.\n"); 78 + "error: could not create a FileMgr from an other line iterator.\n");
79 + return 1; 79 + return 1;
80 + } 80 + }
81 +#else 81 +#else
82 // checking flag duplication 82 // checking flag duplication
83 char dupflags[CONTSIZE]; 83 char dupflags[CONTSIZE];
84 char dupflags_ini = 1; 84 char dupflags_ini = 1;
85 @@ -282,6 +333,7 @@ 85 @@ -282,6 +333,7 @@ int AffixMgr::parse_file(const char * a
86 HUNSPELL_WARNING(stderr, "error: could not open affix description file %s\n ",affpath); 86 HUNSPELL_WARNING(stderr, "error: could not open affix description file %s\n ",affpath);
87 return 1; 87 return 1;
88 } 88 }
89 +#endif 89 +#endif
90 90
91 // step one is to parse the affix file building up the internal 91 // step one is to parse the affix file building up the internal
92 // affix data structures 92 // affix data structures
93 @@ -291,6 +343,7 @@ 93 @@ -291,6 +343,7 @@ int AffixMgr::parse_file(const char * a
94 while ((line = afflst->getline()) != NULL) { 94 while ((line = afflst->getline()) != NULL) {
95 mychomp(line); 95 mychomp(line);
96 96
97 +#ifndef HUNSPELL_CHROME_CLIENT 97 +#ifndef HUNSPELL_CHROME_CLIENT
98 /* remove byte order mark */ 98 /* remove byte order mark */
99 if (firstline) { 99 if (firstline) {
100 firstline = 0; 100 firstline = 0;
101 @@ -299,6 +352,7 @@ 101 @@ -299,6 +352,7 @@ int AffixMgr::parse_file(const char * a
102 memmove(line, line+3, strlen(line+3)+1); 102 memmove(line, line+3, strlen(line+3)+1);
103 } 103 }
104 } 104 }
105 +#endif 105 +#endif
106 106
107 /* parse in the keyboard string */ 107 /* parse in the keyboard string */
108 if (strncmp(line,"KEY",3) == 0) { 108 if (strncmp(line,"KEY",3) == 0) {
109 @@ -545,6 +599,7 @@ 109 @@ -545,6 +599,7 @@ int AffixMgr::parse_file(const char * a
110 } 110 }
111 } 111 }
112 112
113 +#ifndef HUNSPELL_CHROME_CLIENT 113 +#ifndef HUNSPELL_CHROME_CLIENT
114 /* parse in the typical fault correcting table */ 114 /* parse in the typical fault correcting table */
115 if (strncmp(line,"REP",3) == 0) { 115 if (strncmp(line,"REP",3) == 0) {
116 if (parse_reptable(line, afflst)) { 116 if (parse_reptable(line, afflst)) {
117 @@ -552,6 +607,7 @@ 117 @@ -552,6 +607,7 @@ int AffixMgr::parse_file(const char * a
118 return 1; 118 return 1;
119 } 119 }
120 } 120 }
121 +#endif 121 +#endif
122 122
123 /* parse in the input conversion table */ 123 /* parse in the input conversion table */
124 if (strncmp(line,"ICONV",5) == 0) { 124 if (strncmp(line,"ICONV",5) == 0) {
125 @@ -699,6 +755,7 @@ 125 @@ -699,6 +755,7 @@ int AffixMgr::parse_file(const char * a
126 checksharps=1; 126 checksharps=1;
127 } 127 }
128 128
129 +#ifndef HUNSPELL_CHROME_CLIENT 129 +#ifndef HUNSPELL_CHROME_CLIENT
130 /* parse this affix: P - prefix, S - suffix */ 130 /* parse this affix: P - prefix, S - suffix */
131 ft = ' '; 131 ft = ' ';
132 if (strncmp(line,"PFX",3) == 0) ft = complexprefixes ? 'S' : 'P'; 132 if (strncmp(line,"PFX",3) == 0) ft = complexprefixes ? 'S' : 'P';
133 @@ -713,6 +770,7 @@ 133 @@ -713,6 +770,7 @@ int AffixMgr::parse_file(const char * a
134 return 1; 134 return 1;
135 } 135 }
136 } 136 }
137 +#endif 137 +#endif
138 } 138 }
139 139
140 finishFileMgr(afflst); 140 finishFileMgr(afflst);
141 @@ -1307,6 +1365,26 @@ 141 @@ -1307,6 +1365,26 @@ int AffixMgr::cpdrep_check(const char *
142 const char * r; 142 const char * r;
143 int lenr, lenp; 143 int lenr, lenp;
144 144
145 +#ifdef HUNSPELL_CHROME_CLIENT 145 +#ifdef HUNSPELL_CHROME_CLIENT
146 + const char *pattern, *pattern2; 146 + const char *pattern, *pattern2;
147 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator (); 147 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator ();
148 + while (iterator.GetNext(&pattern, &pattern2)) { 148 + while (iterator.GetNext(&pattern, &pattern2)) {
149 + r = word; 149 + r = word;
150 + lenr = strlen(pattern2); 150 + lenr = strlen(pattern2);
151 + lenp = strlen(pattern); 151 + lenp = strlen(pattern);
152 + 152 +
153 + // search every occurence of the pattern in the word 153 + // search every occurence of the pattern in the word
154 + while ((r=strstr(r, pattern)) != NULL) { 154 + while ((r=strstr(r, pattern)) != NULL) {
155 + strcpy(candidate, word); 155 + strcpy(candidate, word);
156 + if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break; 156 + if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break;
157 + strcpy(candidate+(r-word), pattern2); 157 + strcpy(candidate+(r-word), pattern2);
158 + strcpy(candidate+(r-word)+lenr, r+lenp); 158 + strcpy(candidate+(r-word)+lenr, r+lenp);
159 + if (candidate_check(candidate,strlen(candidate))) return 1; 159 + if (candidate_check(candidate,strlen(candidate))) return 1;
160 + r++; // search for the next letter 160 + r++; // search for the next letter
161 + } 161 + }
162 + } 162 + }
163 + 163 +
164 +#else 164 +#else
165 if ((wl < 2) || !numrep) return 0; 165 if ((wl < 2) || !numrep) return 0;
166 166
167 for (int i=0; i < numrep; i++ ) { 167 for (int i=0; i < numrep; i++ ) {
168 @@ -1323,6 +1401,7 @@ 168 @@ -1323,6 +1401,7 @@ int AffixMgr::cpdrep_check(const char *
169 r++; // search for the next letter 169 r++; // search for the next letter
170 } 170 }
171 } 171 }
172 +#endif 172 +#endif
173 return 0; 173 return 0;
174 } 174 }
175 175
176 @@ -4219,6 +4298,7 @@ 176 @@ -4219,6 +4298,7 @@ int AffixMgr::parse_affix(char * line,
177 case 1: { 177 case 1: {
178 np++; 178 np++;
179 aflag = pHMgr->decode_flag(piece); 179 aflag = pHMgr->decode_flag(piece);
180 +#ifndef HUNSPELL_CHROME_CLIENT // We don't check for duplicates. 180 +#ifndef HUNSPELL_CHROME_CLIENT // We don't check for duplicates.
181 if (((at == 'S') && (dupflags[aflag] & dupSFX)) || 181 if (((at == 'S') && (dupflags[aflag] & dupSFX)) ||
182 ((at == 'P') && (dupflags[aflag] & dupPFX))) { 182 ((at == 'P') && (dupflags[aflag] & dupPFX))) {
183 HUNSPELL_WARNING(stderr, "error: line %d: multiple defi nitions of an affix flag\n", 183 HUNSPELL_WARNING(stderr, "error: line %d: multiple defi nitions of an affix flag\n",
184 @@ -4226,6 +4306,7 @@ 184 @@ -4226,6 +4306,7 @@ int AffixMgr::parse_affix(char * line,
185 // return 1; XXX permissive mode for bad dictionaries 185 // return 1; XXX permissive mode for bad dictionaries
186 } 186 }
187 dupflags[aflag] += (char) ((at == 'S') ? dupSFX : dupPFX); 187 dupflags[aflag] += (char) ((at == 'S') ? dupSFX : dupPFX);
188 +#endif 188 +#endif
189 break; 189 break;
190 } 190 }
191 // piece 3 - is cross product indicator 191 // piece 3 - is cross product indicator
192 Index: src/hunspell/affixmgr.hxx 192 Index: src/hunspell/affixmgr.hxx
193 =================================================================== 193 ===================================================================
194 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.hxx,v 194 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.hxx,v
195 retrieving revision 1.15 195 retrieving revision 1.15
196 diff -u -r1.15 affixmgr.hxx 196 diff -u -p -r1.15 affixmgr.hxx
197 --- src/hunspell/affixmgr.hxx 13 Oct 2011 13:41:54 -0000 1.15 197 --- src/hunspell/affixmgr.hxx 13 Oct 2011 13:41:54 -0000 1.15
198 +++ src/hunspell/affixmgr.hxx» 8 Jan 2013 00:30:25 -0000 198 +++ src/hunspell/affixmgr.hxx» 26 Feb 2013 23:13:13 -0000
199 @@ -18,6 +18,40 @@ 199 @@ -18,6 +18,40 @@
200 class PfxEntry; 200 class PfxEntry;
201 class SfxEntry; 201 class SfxEntry;
202 202
203 +#ifdef HUNSPELL_CHROME_CLIENT 203 +#ifdef HUNSPELL_CHROME_CLIENT
204 + 204 +
205 +#include <vector> 205 +#include <vector>
206 + 206 +
207 +// This class provides an implementation of the contclasses array in AffixMgr 207 +// This class provides an implementation of the contclasses array in AffixMgr
208 +// that is normally a large static array. We should almost never need more than 208 +// that is normally a large static array. We should almost never need more than
(...skipping 21 matching lines...) Expand all
230 + } 230 + }
231 + 231 +
232 + std::vector<char> data; 232 + std::vector<char> data;
233 +}; 233 +};
234 + 234 +
235 +#endif // HUNSPELL_CHROME_CLIENT 235 +#endif // HUNSPELL_CHROME_CLIENT
236 + 236 +
237 class LIBHUNSPELL_DLL_EXPORTED AffixMgr 237 class LIBHUNSPELL_DLL_EXPORTED AffixMgr
238 { 238 {
239 239
240 @@ -106,12 +140,20 @@ 240 @@ -106,12 +140,20 @@ class LIBHUNSPELL_DLL_EXPORTED AffixMgr
241 int fullstrip; 241 int fullstrip;
242 242
243 int havecontclass; // boolean variable 243 int havecontclass; // boolean variable
244 +#ifdef HUNSPELL_CHROME_CLIENT 244 +#ifdef HUNSPELL_CHROME_CLIENT
245 + ContClasses contclasses; 245 + ContClasses contclasses;
246 +#else 246 +#else
247 char contclasses[CONTSIZE]; // flags of possible continuing cl asses (twofold affix) 247 char contclasses[CONTSIZE]; // flags of possible continuing cl asses (twofold affix)
248 +#endif 248 +#endif
249 249
250 public: 250 public:
251 251
252 +#ifdef HUNSPELL_CHROME_CLIENT 252 +#ifdef HUNSPELL_CHROME_CLIENT
253 + AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md); 253 + AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md);
254 +#else 254 +#else
255 AffixMgr(const char * affpath, HashMgr** ptr, int * md, 255 AffixMgr(const char * affpath, HashMgr** ptr, int * md,
256 const char * key = NULL); 256 const char * key = NULL);
257 +#endif 257 +#endif
258 ~AffixMgr(); 258 ~AffixMgr();
259 struct hentry * affix_check(const char * word, int len, 259 struct hentry * affix_check(const char * word, int len,
260 const unsigned short needflag = (unsigned short) 0, 260 const unsigned short needflag = (unsigned short) 0,
261 @@ -218,6 +260,10 @@ 261 @@ -218,6 +260,10 @@ public:
262 int get_fullstrip() const; 262 int get_fullstrip() const;
263 263
264 private: 264 private:
265 +#ifdef HUNSPELL_CHROME_CLIENT 265 +#ifdef HUNSPELL_CHROME_CLIENT
266 + // Not owned by us, owned by the Hunspell object. 266 + // Not owned by us, owned by the Hunspell object.
267 + hunspell::BDictReader* bdict_reader; 267 + hunspell::BDictReader* bdict_reader;
268 +#endif 268 +#endif
269 int parse_file(const char * affpath, const char * key); 269 int parse_file(const char * affpath, const char * key);
270 int parse_flag(char * line, unsigned short * out, FileMgr * af); 270 int parse_flag(char * line, unsigned short * out, FileMgr * af);
271 int parse_num(char * line, int * out, FileMgr * af); 271 int parse_num(char * line, int * out, FileMgr * af);
272 @@ -249,4 +295,3 @@ 272 @@ -249,4 +295,3 @@ private:
273 }; 273 };
274 274
275 #endif 275 #endif
276 - 276 -
277 Index: src/hunspell/filemgr.cxx 277 Index: src/hunspell/filemgr.cxx
278 =================================================================== 278 ===================================================================
279 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.cxx,v 279 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.cxx,v
280 retrieving revision 1.5 280 retrieving revision 1.5
281 diff -u -r1.5 filemgr.cxx 281 diff -u -p -r1.5 filemgr.cxx
282 --- src/hunspell/filemgr.cxx 23 Jun 2011 09:21:50 -0000 1.5 282 --- src/hunspell/filemgr.cxx 23 Jun 2011 09:21:50 -0000 1.5
283 +++ src/hunspell/filemgr.cxx» 8 Jan 2013 00:30:25 -0000 283 +++ src/hunspell/filemgr.cxx» 26 Feb 2013 23:13:13 -0000
284 @@ -7,6 +7,32 @@ 284 @@ -7,6 +7,32 @@
285 285
286 #include "filemgr.hxx" 286 #include "filemgr.hxx"
287 287
288 +#ifdef HUNSPELL_CHROME_CLIENT 288 +#ifdef HUNSPELL_CHROME_CLIENT
289 +#include "third_party/hunspell/google/bdict_reader.h" 289 +#include "third_party/hunspell/google/bdict_reader.h"
290 + 290 +
291 +FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { 291 +FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) {
292 +} 292 +}
293 + 293 +
(...skipping 13 matching lines...) Expand all
307 + // This function is used only for displaying a line number that causes a 307 + // This function is used only for displaying a line number that causes a
308 + // parser error. For a BDICT file, providing a line number doesn't help 308 + // parser error. For a BDICT file, providing a line number doesn't help
309 + // identifying the place where causes a parser error so much since it is a 309 + // identifying the place where causes a parser error so much since it is a
310 + // binary file. So, we just return 0. 310 + // binary file. So, we just return 0.
311 + return 0; 311 + return 0;
312 +} 312 +}
313 +#else 313 +#else
314 int FileMgr::fail(const char * err, const char * par) { 314 int FileMgr::fail(const char * err, const char * par) {
315 fprintf(stderr, err, par); 315 fprintf(stderr, err, par);
316 return -1; 316 return -1;
317 @@ -47,3 +73,4 @@ 317 @@ -47,3 +73,4 @@ char * FileMgr::getline() {
318 int FileMgr::getlinenum() { 318 int FileMgr::getlinenum() {
319 return linenum; 319 return linenum;
320 } 320 }
321 +#endif 321 +#endif
322 Index: src/hunspell/filemgr.hxx 322 Index: src/hunspell/filemgr.hxx
323 =================================================================== 323 ===================================================================
324 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.hxx,v 324 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.hxx,v
325 retrieving revision 1.3 325 retrieving revision 1.3
326 diff -u -r1.3 filemgr.hxx 326 diff -u -p -r1.3 filemgr.hxx
327 --- src/hunspell/filemgr.hxx 15 Apr 2010 11:22:08 -0000 1.3 327 --- src/hunspell/filemgr.hxx 15 Apr 2010 11:22:08 -0000 1.3
328 +++ src/hunspell/filemgr.hxx» 8 Jan 2013 00:30:25 -0000 328 +++ src/hunspell/filemgr.hxx» 26 Feb 2013 23:13:13 -0000
329 @@ -7,6 +7,30 @@ 329 @@ -7,6 +7,30 @@
330 #include "hunzip.hxx" 330 #include "hunzip.hxx"
331 #include <stdio.h> 331 #include <stdio.h>
332 332
333 +#ifdef HUNSPELL_CHROME_CLIENT 333 +#ifdef HUNSPELL_CHROME_CLIENT
334 +namespace hunspell { 334 +namespace hunspell {
335 +class LineIterator; 335 +class LineIterator;
336 +} // namespace hunspell 336 +} // namespace hunspell
337 + 337 +
338 +// A class which encapsulates operations of reading a BDICT file. 338 +// A class which encapsulates operations of reading a BDICT file.
(...skipping 11 matching lines...) Expand all
350 + int getlinenum(); 350 + int getlinenum();
351 + 351 +
352 + protected: 352 + protected:
353 + hunspell::LineIterator* iterator_; 353 + hunspell::LineIterator* iterator_;
354 + char line_[BUFSIZE + 50]; // input buffer 354 + char line_[BUFSIZE + 50]; // input buffer
355 +}; 355 +};
356 +#else 356 +#else
357 class LIBHUNSPELL_DLL_EXPORTED FileMgr 357 class LIBHUNSPELL_DLL_EXPORTED FileMgr
358 { 358 {
359 protected: 359 protected:
360 @@ -23,3 +47,4 @@ 360 @@ -23,3 +47,4 @@ public:
361 int getlinenum(); 361 int getlinenum();
362 }; 362 };
363 #endif 363 #endif
364 +#endif 364 +#endif
365 Index: src/hunspell/hashmgr.cxx 365 Index: src/hunspell/hashmgr.cxx
366 =================================================================== 366 ===================================================================
367 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.cxx,v 367 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.cxx,v
368 retrieving revision 1.12 368 retrieving revision 1.12
369 diff -u -r1.12 hashmgr.cxx 369 diff -u -p -r1.12 hashmgr.cxx
370 --- src/hunspell/hashmgr.cxx 23 Jun 2011 09:21:50 -0000 1.12 370 --- src/hunspell/hashmgr.cxx 23 Jun 2011 09:21:50 -0000 1.12
371 +++ src/hunspell/hashmgr.cxx» 8 Jan 2013 00:30:25 -0000 371 +++ src/hunspell/hashmgr.cxx» 26 Feb 2013 23:13:13 -0000
372 @@ -12,8 +12,14 @@ 372 @@ -12,8 +12,14 @@
373 373
374 // build a hash table from a munched word list 374 // build a hash table from a munched word list
375 375
376 +#ifdef HUNSPELL_CHROME_CLIENT 376 +#ifdef HUNSPELL_CHROME_CLIENT
377 +HashMgr::HashMgr(hunspell::BDictReader* reader) 377 +HashMgr::HashMgr(hunspell::BDictReader* reader)
378 +{ 378 +{
379 + bdict_reader = reader; 379 + bdict_reader = reader;
380 +#else 380 +#else
381 HashMgr::HashMgr(const char * tpath, const char * apath, const char * key) 381 HashMgr::HashMgr(const char * tpath, const char * apath, const char * key)
382 { 382 {
383 +#endif 383 +#endif
384 tablesize = 0; 384 tablesize = 0;
385 tableptr = NULL; 385 tableptr = NULL;
386 flag_mode = FLAG_CHAR; 386 flag_mode = FLAG_CHAR;
387 @@ -31,8 +37,14 @@ 387 @@ -31,8 +37,14 @@ HashMgr::HashMgr(const char * tpath, con
388 numaliasm = 0; 388 numaliasm = 0;
389 aliasm = NULL; 389 aliasm = NULL;
390 forbiddenword = FORBIDDENWORD; // forbidden word signing flag 390 forbiddenword = FORBIDDENWORD; // forbidden word signing flag
391 +#ifdef HUNSPELL_CHROME_CLIENT 391 +#ifdef HUNSPELL_CHROME_CLIENT
392 + // No tables to load, just the AF lines. 392 + // No tables to load, just the AF lines.
393 + load_config(NULL, NULL); 393 + load_config(NULL, NULL);
394 + int ec = LoadAFLines(); 394 + int ec = LoadAFLines();
395 +#else 395 +#else
396 load_config(apath, key); 396 load_config(apath, key);
397 int ec = load_tables(tpath, key); 397 int ec = load_tables(tpath, key);
398 +#endif 398 +#endif
399 if (ec) { 399 if (ec) {
400 /* error condition - what should we do here */ 400 /* error condition - what should we do here */
401 HUNSPELL_WARNING(stderr, "Hash Manager Error : %d\n",ec); 401 HUNSPELL_WARNING(stderr, "Hash Manager Error : %d\n",ec);
402 @@ -91,15 +103,58 @@ 402 @@ -91,15 +103,58 @@ HashMgr::~HashMgr()
403 if (ignorechars) free(ignorechars); 403 if (ignorechars) free(ignorechars);
404 if (ignorechars_utf16) free(ignorechars_utf16); 404 if (ignorechars_utf16) free(ignorechars_utf16);
405 405
406 +#ifdef HUNSPELL_CHROME_CLIENT 406 +#ifdef HUNSPELL_CHROME_CLIENT
407 + EmptyHentryCache(); 407 + EmptyHentryCache();
408 + for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin(); 408 + for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin();
409 + it != pointer_to_strings_.end(); ++it) { 409 + it != pointer_to_strings_.end(); ++it) {
410 + delete *it; 410 + delete *it;
411 + } 411 + }
412 +#endif 412 +#endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 + static const int kMaxWordLen = 128; 451 + static const int kMaxWordLen = 128;
452 + static char word_buf[kMaxWordLen]; 452 + static char word_buf[kMaxWordLen];
453 + // To take account of null-termination, we use upto 127. 453 + // To take account of null-termination, we use upto 127.
454 + strncpy(word_buf, word, kMaxWordLen - 1); 454 + strncpy(word_buf, word, kMaxWordLen - 1);
455 + 455 +
456 + return AffixIDsToHentry(word_buf, affix_ids, affix_count); 456 + return AffixIDsToHentry(word_buf, affix_ids, affix_count);
457 +#else 457 +#else
458 struct hentry * dp; 458 struct hentry * dp;
459 if (tableptr) { 459 if (tableptr) {
460 dp = tableptr[hash(word)]; 460 dp = tableptr[hash(word)];
461 @@ -109,12 +164,14 @@ 461 @@ -109,12 +164,14 @@ struct hentry * HashMgr::lookup(const ch
462 } 462 }
463 } 463 }
464 return NULL; 464 return NULL;
465 +#endif 465 +#endif
466 } 466 }
467 467
468 // add a word to the hash table (private) 468 // add a word to the hash table (private)
469 int HashMgr::add_word(const char * word, int wbl, int wcl, unsigned short * aff , 469 int HashMgr::add_word(const char * word, int wbl, int wcl, unsigned short * aff ,
470 int al, const char * desc, bool onlyupcase) 470 int al, const char * desc, bool onlyupcase)
471 { 471 {
472 +#ifndef HUNSPELL_CHROME_CLIENT 472 +#ifndef HUNSPELL_CHROME_CLIENT
473 bool upcasehomonym = false; 473 bool upcasehomonym = false;
474 int descl = desc ? (aliasm ? sizeof(short) : strlen(desc) + 1) : 0; 474 int descl = desc ? (aliasm ? sizeof(short) : strlen(desc) + 1) : 0;
475 // variable-length hash record with word and optional fields 475 // variable-length hash record with word and optional fields
476 @@ -206,6 +263,17 @@ 476 @@ -206,6 +263,17 @@ int HashMgr::add_word(const char * word,
477 if (hp->astr) free(hp->astr); 477 if (hp->astr) free(hp->astr);
478 free(hp); 478 free(hp);
479 } 479 }
480 +#else 480 +#else
481 + std::map<base::StringPiece, int>::iterator iter = 481 + std::map<base::StringPiece, int>::iterator iter =
482 + custom_word_to_affix_id_map_.find(word); 482 + custom_word_to_affix_id_map_.find(word);
483 + if(iter == custom_word_to_affix_id_map_.end()) { // word needs to be added 483 + if(iter == custom_word_to_affix_id_map_.end()) { // word needs to be added
484 + std::string* new_string_word = new std::string(word); 484 + std::string* new_string_word = new std::string(word);
485 + pointer_to_strings_.push_back(new_string_word); 485 + pointer_to_strings_.push_back(new_string_word);
486 + base::StringPiece sp(*(new_string_word)); 486 + base::StringPiece sp(*(new_string_word));
487 + custom_word_to_affix_id_map_[sp] = 0; // no affixes for custom words 487 + custom_word_to_affix_id_map_[sp] = 0; // no affixes for custom words
488 + return 1; 488 + return 1;
489 + } 489 + }
490 +#endif 490 +#endif
491 return 0; 491 return 0;
492 } 492 }
493 493
494 @@ -256,6 +324,12 @@ 494 @@ -256,6 +324,12 @@ int HashMgr::get_clen_and_captype(const
495 // remove word (personal dictionary function for standalone applications) 495 // remove word (personal dictionary function for standalone applications)
496 int HashMgr::remove(const char * word) 496 int HashMgr::remove(const char * word)
497 { 497 {
498 +#ifdef HUNSPELL_CHROME_CLIENT 498 +#ifdef HUNSPELL_CHROME_CLIENT
499 + std::map<base::StringPiece, int>::iterator iter = 499 + std::map<base::StringPiece, int>::iterator iter =
500 + custom_word_to_affix_id_map_.find(word); 500 + custom_word_to_affix_id_map_.find(word);
501 + if (iter != custom_word_to_affix_id_map_.end()) 501 + if (iter != custom_word_to_affix_id_map_.end())
502 + custom_word_to_affix_id_map_.erase(iter); 502 + custom_word_to_affix_id_map_.erase(iter);
503 +#else 503 +#else
504 struct hentry * dp = lookup(word); 504 struct hentry * dp = lookup(word);
505 while (dp) { 505 while (dp) {
506 if (dp->alen == 0 || !TESTAFF(dp->astr, forbiddenword, dp->alen)) { 506 if (dp->alen == 0 || !TESTAFF(dp->astr, forbiddenword, dp->alen)) {
507 @@ -270,6 +344,7 @@ 507 @@ -270,6 +344,7 @@ int HashMgr::remove(const char * word)
508 } 508 }
509 dp = dp->next_homonym; 509 dp = dp->next_homonym;
510 } 510 }
511 +#endif 511 +#endif
512 return 0; 512 return 0;
513 } 513 }
514 514
515 @@ -339,6 +414,44 @@ 515 @@ -339,6 +414,44 @@ int HashMgr::add_with_affix(const char *
516 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp); 516 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp);
517 struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const 517 struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const
518 { 518 {
519 +#ifdef HUNSPELL_CHROME_CLIENT 519 +#ifdef HUNSPELL_CHROME_CLIENT
520 + // Return NULL if dictionary is not valid. 520 + // Return NULL if dictionary is not valid.
521 + if (!bdict_reader->IsValid()) 521 + if (!bdict_reader->IsValid())
522 + return NULL; 522 + return NULL;
523 + 523 +
524 + // This function is only ever called by one place and not nested. We can 524 + // This function is only ever called by one place and not nested. We can
525 + // therefore keep static state between calls and use |col| as a "reset" flag 525 + // therefore keep static state between calls and use |col| as a "reset" flag
(...skipping 24 matching lines...) Expand all
550 + hentry entry; 550 + hentry entry;
551 + char word[kMaxWordLen]; 551 + char word[kMaxWordLen];
552 + } hash_entry; 552 + } hash_entry;
553 + 553 +
554 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry), 554 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry),
555 + &word[0], word_len, affix_ids[0]); 555 + &word[0], word_len, affix_ids[0]);
556 +#else 556 +#else
557 if (hp && hp->next != NULL) return hp->next; 557 if (hp && hp->next != NULL) return hp->next;
558 for (col++; col < tablesize; col++) { 558 for (col++; col < tablesize; col++) {
559 if (tableptr[col]) return tableptr[col]; 559 if (tableptr[col]) return tableptr[col];
560 @@ -346,11 +459,13 @@ 560 @@ -346,11 +459,13 @@ struct hentry * HashMgr::walk_hashtable(
561 // null at end and reset to start 561 // null at end and reset to start
562 col = -1; 562 col = -1;
563 return NULL; 563 return NULL;
564 +#endif 564 +#endif
565 } 565 }
566 566
567 // load a munched word list and build a hash table on the fly 567 // load a munched word list and build a hash table on the fly
568 int HashMgr::load_tables(const char * tpath, const char * key) 568 int HashMgr::load_tables(const char * tpath, const char * key)
569 { 569 {
570 +#ifndef HUNSPELL_CHROME_CLIENT 570 +#ifndef HUNSPELL_CHROME_CLIENT
571 int al; 571 int al;
572 char * ap; 572 char * ap;
573 char * dp; 573 char * dp;
574 @@ -471,6 +586,7 @@ 574 @@ -471,6 +586,7 @@ int HashMgr::load_tables(const char * tp
575 } 575 }
576 576
577 delete dict; 577 delete dict;
578 +#endif 578 +#endif
579 return 0; 579 return 0;
580 } 580 }
581 581
582 @@ -479,6 +595,9 @@ 582 @@ -479,6 +595,9 @@ int HashMgr::load_tables(const char * tp
583 583
584 int HashMgr::hash(const char * word) const 584 int HashMgr::hash(const char * word) const
585 { 585 {
586 +#ifdef HUNSPELL_CHROME_CLIENT 586 +#ifdef HUNSPELL_CHROME_CLIENT
587 + return 0; 587 + return 0;
588 +#else 588 +#else
589 long hv = 0; 589 long hv = 0;
590 for (int i=0; i < 4 && *word != 0; i++) 590 for (int i=0; i < 4 && *word != 0; i++)
591 hv = (hv << 8) | (*word++); 591 hv = (hv << 8) | (*word++);
592 @@ -487,6 +606,7 @@ 592 @@ -487,6 +606,7 @@ int HashMgr::hash(const char * word) con
593 hv ^= (*word++); 593 hv ^= (*word++);
594 } 594 }
595 return (unsigned long) hv % tablesize; 595 return (unsigned long) hv % tablesize;
596 +#endif 596 +#endif
597 } 597 }
598 598
599 int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af) { 599 int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af) {
600 @@ -607,7 +727,12 @@ 600 @@ -607,7 +727,12 @@ int HashMgr::load_config(const char * a
601 int firstline = 1; 601 int firstline = 1;
602 602
603 // open the affix file 603 // open the affix file
604 +#ifdef HUNSPELL_CHROME_CLIENT 604 +#ifdef HUNSPELL_CHROME_CLIENT
605 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator(); 605 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator();
606 + FileMgr * afflst = new FileMgr(&iterator); 606 + FileMgr * afflst = new FileMgr(&iterator);
607 +#else 607 +#else
608 FileMgr * afflst = new FileMgr(affpath, key); 608 FileMgr * afflst = new FileMgr(affpath, key);
609 +#endif 609 +#endif
610 if (!afflst) { 610 if (!afflst) {
611 HUNSPELL_WARNING(stderr, "Error - could not open affix description file %s\ n",affpath); 611 HUNSPELL_WARNING(stderr, "Error - could not open affix description file %s\ n",affpath);
612 return 1; 612 return 1;
613 @@ -802,6 +927,121 @@ 613 @@ -802,6 +927,121 @@ int HashMgr::parse_aliasf(char * line,
614 return 0; 614 return 0;
615 } 615 }
616 616
617 +#ifdef HUNSPELL_CHROME_CLIENT 617 +#ifdef HUNSPELL_CHROME_CLIENT
618 +int HashMgr::LoadAFLines() 618 +int HashMgr::LoadAFLines()
619 +{ 619 +{
620 + utf8 = 1; // We always use UTF-8. 620 + utf8 = 1; // We always use UTF-8.
621 + 621 +
622 + // Read in all the AF lines which tell us the rules for each affix group ID. 622 + // Read in all the AF lines which tell us the rules for each affix group ID.
623 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator(); 623 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 +} 729 +}
730 +#endif 730 +#endif
731 + 731 +
732 int HashMgr::is_aliasf() { 732 int HashMgr::is_aliasf() {
733 return (aliasf != NULL); 733 return (aliasf != NULL);
734 } 734 }
735 Index: src/hunspell/hashmgr.hxx 735 Index: src/hunspell/hashmgr.hxx
736 =================================================================== 736 ===================================================================
737 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.hxx,v 737 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.hxx,v
738 retrieving revision 1.3 738 retrieving revision 1.3
739 diff -u -r1.3 hashmgr.hxx 739 diff -u -p -r1.3 hashmgr.hxx
740 --- src/hunspell/hashmgr.hxx 15 Apr 2010 11:22:08 -0000 1.3 740 --- src/hunspell/hashmgr.hxx 15 Apr 2010 11:22:08 -0000 1.3
741 +++ src/hunspell/hashmgr.hxx» 8 Jan 2013 00:30:25 -0000 741 +++ src/hunspell/hashmgr.hxx» 26 Feb 2013 23:13:13 -0000
742 @@ -8,10 +8,25 @@ 742 @@ -8,10 +8,25 @@
743 #include "htypes.hxx" 743 #include "htypes.hxx"
744 #include "filemgr.hxx" 744 #include "filemgr.hxx"
745 745
746 +#ifdef HUNSPELL_CHROME_CLIENT 746 +#ifdef HUNSPELL_CHROME_CLIENT
747 +#include <string> 747 +#include <string>
748 +#include <map> 748 +#include <map>
749 + 749 +
750 +#include "base/stl_util.h" 750 +#include "base/stl_util.h"
751 +#include "base/string_piece.h" 751 +#include "base/string_piece.h"
752 +#include "third_party/hunspell/google/bdict_reader.h" 752 +#include "third_party/hunspell/google/bdict_reader.h"
753 +#endif 753 +#endif
754 + 754 +
755 enum flag { FLAG_CHAR, FLAG_LONG, FLAG_NUM, FLAG_UNI }; 755 enum flag { FLAG_CHAR, FLAG_LONG, FLAG_NUM, FLAG_UNI };
756 756
757 class LIBHUNSPELL_DLL_EXPORTED HashMgr 757 class LIBHUNSPELL_DLL_EXPORTED HashMgr
758 { 758 {
759 +#ifdef HUNSPELL_CHROME_CLIENT 759 +#ifdef HUNSPELL_CHROME_CLIENT
760 + // Not owned by this class, owned by the Hunspell object. 760 + // Not owned by this class, owned by the Hunspell object.
761 + hunspell::BDictReader* bdict_reader; 761 + hunspell::BDictReader* bdict_reader;
762 + std::map<base::StringPiece, int> custom_word_to_affix_id_map_; 762 + std::map<base::StringPiece, int> custom_word_to_affix_id_map_;
763 + std::vector<std::string*> pointer_to_strings_; 763 + std::vector<std::string*> pointer_to_strings_;
764 +#endif 764 +#endif
765 int tablesize; 765 int tablesize;
766 struct hentry ** tableptr; 766 struct hentry ** tableptr;
767 int userword; 767 int userword;
768 @@ -34,7 +49,23 @@ 768 @@ -34,7 +49,23 @@ class LIBHUNSPELL_DLL_EXPORTED HashMgr
769 769
770 770
771 public: 771 public:
772 +#ifdef HUNSPELL_CHROME_CLIENT 772 +#ifdef HUNSPELL_CHROME_CLIENT
773 + HashMgr(hunspell::BDictReader* reader); 773 + HashMgr(hunspell::BDictReader* reader);
774 + 774 +
775 + // Return the hentry corresponding to the given word. Returns NULL if the 775 + // Return the hentry corresponding to the given word. Returns NULL if the
776 + // word is not there in the cache. 776 + // word is not there in the cache.
777 + hentry* GetHentryFromHEntryCache(char* word); 777 + hentry* GetHentryFromHEntryCache(char* word);
778 + 778 +
779 + // Called before we do a new operation. This will empty the cache of pointers 779 + // Called before we do a new operation. This will empty the cache of pointers
780 + // to hentries that we have cached. In Chrome, we make these on-demand, but 780 + // to hentries that we have cached. In Chrome, we make these on-demand, but
781 + // they must live as long as the single spellcheck operation that they're par t 781 + // they must live as long as the single spellcheck operation that they're par t
782 + // of since Hunspell will save pointers to various ones as it works. 782 + // of since Hunspell will save pointers to various ones as it works.
783 + // 783 + //
784 + // This function allows that cache to be emptied and not grow infinitely. 784 + // This function allows that cache to be emptied and not grow infinitely.
785 + void EmptyHentryCache(); 785 + void EmptyHentryCache();
786 +#else 786 +#else
787 HashMgr(const char * tpath, const char * apath, const char * key = NULL); 787 HashMgr(const char * tpath, const char * apath, const char * key = NULL);
788 +#endif 788 +#endif
789 ~HashMgr(); 789 ~HashMgr();
790 790
791 struct hentry * lookup(const char *) const; 791 struct hentry * lookup(const char *) const;
792 @@ -59,6 +90,40 @@ 792 @@ -59,6 +90,40 @@ private:
793 int al, const char * desc, bool onlyupcase); 793 int al, const char * desc, bool onlyupcase);
794 int load_config(const char * affpath, const char * key); 794 int load_config(const char * affpath, const char * key);
795 int parse_aliasf(char * line, FileMgr * af); 795 int parse_aliasf(char * line, FileMgr * af);
796 + 796 +
797 +#ifdef HUNSPELL_CHROME_CLIENT 797 +#ifdef HUNSPELL_CHROME_CLIENT
798 + // Loads the AF lines from a BDICT. 798 + // Loads the AF lines from a BDICT.
799 + // A BDICT file compresses its AF lines to save memory. 799 + // A BDICT file compresses its AF lines to save memory.
800 + // This function decompresses each AF line and call parse_aliasf(). 800 + // This function decompresses each AF line and call parse_aliasf().
801 + int LoadAFLines(); 801 + int LoadAFLines();
802 + 802 +
(...skipping 24 matching lines...) Expand all
827 + HEntryCache hentry_cache; 827 + HEntryCache hentry_cache;
828 +#endif 828 +#endif
829 + 829 +
830 int add_hidden_capitalized_word(char * word, int wbl, int wcl, 830 int add_hidden_capitalized_word(char * word, int wbl, int wcl,
831 unsigned short * flags, int al, char * dp, int captype); 831 unsigned short * flags, int al, char * dp, int captype);
832 int parse_aliasm(char * line, FileMgr * af); 832 int parse_aliasm(char * line, FileMgr * af);
833 Index: src/hunspell/htypes.hxx 833 Index: src/hunspell/htypes.hxx
834 =================================================================== 834 ===================================================================
835 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/htypes.hxx,v 835 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/htypes.hxx,v
836 retrieving revision 1.3 836 retrieving revision 1.3
837 diff -u -r1.3 htypes.hxx 837 diff -u -p -r1.3 htypes.hxx
838 --- src/hunspell/htypes.hxx 6 Sep 2010 07:58:53 -0000 1.3 838 --- src/hunspell/htypes.hxx 6 Sep 2010 07:58:53 -0000 1.3
839 +++ src/hunspell/htypes.hxx» 8 Jan 2013 00:30:25 -0000 839 +++ src/hunspell/htypes.hxx» 26 Feb 2013 23:13:13 -0000
840 @@ -1,6 +1,16 @@ 840 @@ -1,6 +1,16 @@
841 #ifndef _HTYPES_HXX_ 841 #ifndef _HTYPES_HXX_
842 #define _HTYPES_HXX_ 842 #define _HTYPES_HXX_
843 843
844 +#ifdef HUNSPELL_CHROME_CLIENT 844 +#ifdef HUNSPELL_CHROME_CLIENT
845 +// This is a workaround for preventing errors in parsing Turkish BDICs, which 845 +// This is a workaround for preventing errors in parsing Turkish BDICs, which
846 +// contain very long AF lines (~ 12,000 chars). 846 +// contain very long AF lines (~ 12,000 chars).
847 +// TODO(hbono) change the HashMgr::parse_aliasf() function to be able to parse 847 +// TODO(hbono) change the HashMgr::parse_aliasf() function to be able to parse
848 +// longer lines than MAXDELEN. 848 +// longer lines than MAXDELEN.
849 +#define MAXDELEN (8192 * 2) 849 +#define MAXDELEN (8192 * 2)
850 +#else 850 +#else
851 +#define MAXDELEN 8192 851 +#define MAXDELEN 8192
852 +#endif // HUNSPELL_CHROME_CLIENT 852 +#endif // HUNSPELL_CHROME_CLIENT
853 + 853 +
854 #define ROTATE_LEN 5 854 #define ROTATE_LEN 5
855 855
856 #define ROTATE(v,q) \ 856 #define ROTATE(v,q) \
857 Index: src/hunspell/hunspell.cxx 857 Index: src/hunspell/hunspell.cxx
858 =================================================================== 858 ===================================================================
859 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.cxx,v 859 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.cxx,v
860 retrieving revision 1.29 860 retrieving revision 1.29
861 diff -u -r1.29 hunspell.cxx 861 diff -u -p -r1.29 hunspell.cxx
862 --- src/hunspell/hunspell.cxx 23 Jun 2011 09:21:50 -0000 1.29 862 --- src/hunspell/hunspell.cxx 23 Jun 2011 09:21:50 -0000 1.29
863 +++ src/hunspell/hunspell.cxx» 8 Jan 2013 00:30:25 -0000 863 +++ src/hunspell/hunspell.cxx» 26 Feb 2013 23:13:13 -0000
864 @@ -7,20 +7,37 @@ 864 @@ -7,20 +7,37 @@
865 865
866 #include "hunspell.hxx" 866 #include "hunspell.hxx"
867 #include "hunspell.h" 867 #include "hunspell.h"
868 +#ifndef HUNSPELL_CHROME_CLIENT 868 +#ifndef HUNSPELL_CHROME_CLIENT
869 #ifndef MOZILLA_CLIENT 869 #ifndef MOZILLA_CLIENT
870 # include "config.h" 870 # include "config.h"
871 #endif 871 #endif
872 +#endif 872 +#endif
873 #include "csutil.hxx" 873 #include "csutil.hxx"
(...skipping 18 matching lines...) Expand all
892 + bdict_reader->Init(bdict_data, bdict_length); 892 + bdict_reader->Init(bdict_data, bdict_length);
893 + 893 +
894 + pHMgr[0] = new HashMgr(bdict_reader); 894 + pHMgr[0] = new HashMgr(bdict_reader);
895 + if (pHMgr[0]) maxdic = 1; 895 + if (pHMgr[0]) maxdic = 1;
896 + 896 +
897 + pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic); 897 + pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic);
898 +#else 898 +#else
899 /* first set up the hash manager */ 899 /* first set up the hash manager */
900 pHMgr[0] = new HashMgr(dpath, affpath, key); 900 pHMgr[0] = new HashMgr(dpath, affpath, key);
901 if (pHMgr[0]) maxdic = 1; 901 if (pHMgr[0]) maxdic = 1;
902 @@ -28,6 +45,7 @@ 902 @@ -28,6 +45,7 @@ Hunspell::Hunspell(const char * affpath,
903 /* next set up the affix manager */ 903 /* next set up the affix manager */
904 /* it needs access to the hash manager lookup methods */ 904 /* it needs access to the hash manager lookup methods */
905 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key); 905 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key);
906 +#endif 906 +#endif
907 907
908 /* get the preferred try string and the dictionary */ 908 /* get the preferred try string and the dictionary */
909 /* encoding from the Affix Manager for that dictionary */ 909 /* encoding from the Affix Manager for that dictionary */
910 @@ -41,7 +59,11 @@ 910 @@ -41,7 +59,11 @@ Hunspell::Hunspell(const char * affpath,
911 wordbreak = pAMgr->get_breaktable(); 911 wordbreak = pAMgr->get_breaktable();
912 912
913 /* and finally set up the suggestion manager */ 913 /* and finally set up the suggestion manager */
914 +#ifdef HUNSPELL_CHROME_CLIENT 914 +#ifdef HUNSPELL_CHROME_CLIENT
915 + pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr); 915 + pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr);
916 +#else 916 +#else
917 pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr); 917 pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr);
918 +#endif 918 +#endif
919 if (try_string) free(try_string); 919 if (try_string) free(try_string);
920 } 920 }
921 921
922 @@ -59,10 +81,16 @@ 922 @@ -59,10 +81,16 @@ Hunspell::~Hunspell()
923 csconv= NULL; 923 csconv= NULL;
924 if (encoding) free(encoding); 924 if (encoding) free(encoding);
925 encoding = NULL; 925 encoding = NULL;
926 +#ifdef HUNSPELL_CHROME_CLIENT 926 +#ifdef HUNSPELL_CHROME_CLIENT
927 + if (bdict_reader) delete bdict_reader; 927 + if (bdict_reader) delete bdict_reader;
928 + bdict_reader = NULL; 928 + bdict_reader = NULL;
929 +#else 929 +#else
930 if (affixpath) free(affixpath); 930 if (affixpath) free(affixpath);
931 affixpath = NULL; 931 affixpath = NULL;
932 +#endif 932 +#endif
933 } 933 }
934 934
935 +#ifndef HUNSPELL_CHROME_CLIENT 935 +#ifndef HUNSPELL_CHROME_CLIENT
936 // load extra dictionaries 936 // load extra dictionaries
937 int Hunspell::add_dic(const char * dpath, const char * key) { 937 int Hunspell::add_dic(const char * dpath, const char * key) {
938 if (maxdic == MAXDIC || !affixpath) return 1; 938 if (maxdic == MAXDIC || !affixpath) return 1;
939 @@ -70,6 +98,7 @@ 939 @@ -70,6 +98,7 @@ int Hunspell::add_dic(const char * dpath
940 if (pHMgr[maxdic]) maxdic++; else return 1; 940 if (pHMgr[maxdic]) maxdic++; else return 1;
941 return 0; 941 return 0;
942 } 942 }
943 +#endif 943 +#endif
944 944
945 // make a copy of src at destination while removing all leading 945 // make a copy of src at destination while removing all leading
946 // blanks and removing any trailing periods after recording 946 // blanks and removing any trailing periods after recording
947 @@ -322,6 +351,9 @@ 947 @@ -322,6 +351,9 @@ int Hunspell::insert_sug(char ***slst, c
948 948
949 int Hunspell::spell(const char * word, int * info, char ** root) 949 int Hunspell::spell(const char * word, int * info, char ** root)
950 { 950 {
951 +#ifdef HUNSPELL_CHROME_CLIENT 951 +#ifdef HUNSPELL_CHROME_CLIENT
952 + if (pHMgr) pHMgr[0]->EmptyHentryCache(); 952 + if (pHMgr) pHMgr[0]->EmptyHentryCache();
953 +#endif 953 +#endif
954 struct hentry * rv=NULL; 954 struct hentry * rv=NULL;
955 // need larger vector. For example, Turkish capital letter I converted a 955 // need larger vector. For example, Turkish capital letter I converted a
956 // 2-byte UTF-8 character (dotless i) by mkallsmall. 956 // 2-byte UTF-8 character (dotless i) by mkallsmall.
957 @@ -586,6 +618,13 @@ 957 @@ -586,6 +618,13 @@ struct hentry * Hunspell::checkword(cons
958 if (!len) 958 if (!len)
959 return NULL; 959 return NULL;
960 960
961 +#ifdef HUNSPELL_CHROME_CLIENT 961 +#ifdef HUNSPELL_CHROME_CLIENT
962 + // We need to check if the word length is valid to make coverity (Event 962 + // We need to check if the word length is valid to make coverity (Event
963 + // fixed_size_dest: Possible overrun of N byte fixed size buffer) happy. 963 + // fixed_size_dest: Possible overrun of N byte fixed size buffer) happy.
964 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX WORDLEN)) 964 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX WORDLEN))
965 + return NULL; 965 + return NULL;
966 +#endif 966 +#endif
967 + 967 +
968 // word reversing wrapper for complex prefixes 968 // word reversing wrapper for complex prefixes
969 if (complexprefixes) { 969 if (complexprefixes) {
970 if (word != w2) { 970 if (word != w2) {
971 @@ -675,6 +714,9 @@ 971 @@ -675,6 +714,9 @@ struct hentry * Hunspell::checkword(cons
972 972
973 int Hunspell::suggest(char*** slst, const char * word) 973 int Hunspell::suggest(char*** slst, const char * word)
974 { 974 {
975 +#ifdef HUNSPELL_CHROME_CLIENT 975 +#ifdef HUNSPELL_CHROME_CLIENT
976 + if (pHMgr) pHMgr[0]->EmptyHentryCache(); 976 + if (pHMgr) pHMgr[0]->EmptyHentryCache();
977 +#endif 977 +#endif
978 int onlycmpdsug = 0; 978 int onlycmpdsug = 0;
979 char cw[MAXWORDUTF8LEN]; 979 char cw[MAXWORDUTF8LEN];
980 char wspace[MAXWORDUTF8LEN]; 980 char wspace[MAXWORDUTF8LEN];
981 @@ -1921,13 +1963,21 @@ 981 @@ -1921,13 +1963,21 @@ char * Hunspell::morph_with_correction(c
982 982
983 Hunhandle *Hunspell_create(const char * affpath, const char * dpath) 983 Hunhandle *Hunspell_create(const char * affpath, const char * dpath)
984 { 984 {
985 +#ifdef HUNSPELL_CHROME_CLIENT 985 +#ifdef HUNSPELL_CHROME_CLIENT
986 + return NULL; 986 + return NULL;
987 +#else 987 +#else
988 return (Hunhandle*)(new Hunspell(affpath, dpath)); 988 return (Hunhandle*)(new Hunspell(affpath, dpath));
989 +#endif 989 +#endif
990 } 990 }
991 991
992 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath, 992 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath,
993 const char * key) 993 const char * key)
994 { 994 {
995 +#ifdef HUNSPELL_CHROME_CLIENT 995 +#ifdef HUNSPELL_CHROME_CLIENT
996 + return NULL; 996 + return NULL;
997 +#else 997 +#else
998 return (Hunhandle*)(new Hunspell(affpath, dpath, key)); 998 return (Hunhandle*)(new Hunspell(affpath, dpath, key));
999 +#endif 999 +#endif
1000 } 1000 }
1001 1001
1002 void Hunspell_destroy(Hunhandle *pHunspell) 1002 void Hunspell_destroy(Hunhandle *pHunspell)
1003 Index: src/hunspell/hunspell.hxx 1003 Index: src/hunspell/hunspell.hxx
1004 =================================================================== 1004 ===================================================================
1005 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.hxx,v 1005 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.hxx,v
1006 retrieving revision 1.6 1006 retrieving revision 1.6
1007 diff -u -r1.6 hunspell.hxx 1007 diff -u -p -r1.6 hunspell.hxx
1008 --- src/hunspell/hunspell.hxx 21 Jan 2011 17:30:41 -0000 1.6 1008 --- src/hunspell/hunspell.hxx 21 Jan 2011 17:30:41 -0000 1.6
1009 +++ src/hunspell/hunspell.hxx» 8 Jan 2013 00:30:25 -0000 1009 +++ src/hunspell/hunspell.hxx» 26 Feb 2013 23:13:13 -0000
1010 @@ -5,6 +5,10 @@ 1010 @@ -5,6 +5,10 @@
1011 #include "suggestmgr.hxx" 1011 #include "suggestmgr.hxx"
1012 #include "langnum.hxx" 1012 #include "langnum.hxx"
1013 1013
1014 +#ifdef HUNSPELL_CHROME_CLIENT 1014 +#ifdef HUNSPELL_CHROME_CLIENT
1015 +#include "third_party/hunspell/google/bdict_reader.h" 1015 +#include "third_party/hunspell/google/bdict_reader.h"
1016 +#endif 1016 +#endif
1017 + 1017 +
1018 #define SPELL_XML "<?xml?>" 1018 #define SPELL_XML "<?xml?>"
1019 1019
1020 #define MAXDIC 20 1020 #define MAXDIC 20
1021 @@ -23,7 +27,9 @@ 1021 @@ -23,7 +27,9 @@ class LIBHUNSPELL_DLL_EXPORTED Hunspell
1022 HashMgr* pHMgr[MAXDIC]; 1022 HashMgr* pHMgr[MAXDIC];
1023 int maxdic; 1023 int maxdic;
1024 SuggestMgr* pSMgr; 1024 SuggestMgr* pSMgr;
1025 +#ifndef HUNSPELL_CHROME_CLIENT // We are using BDict instead. 1025 +#ifndef HUNSPELL_CHROME_CLIENT // We are using BDict instead.
1026 char * affixpath; 1026 char * affixpath;
1027 +#endif 1027 +#endif
1028 char * encoding; 1028 char * encoding;
1029 struct cs_info * csconv; 1029 struct cs_info * csconv;
1030 int langnum; 1030 int langnum;
1031 @@ -31,17 +37,28 @@ 1031 @@ -31,17 +37,28 @@ class LIBHUNSPELL_DLL_EXPORTED Hunspell
1032 int complexprefixes; 1032 int complexprefixes;
1033 char** wordbreak; 1033 char** wordbreak;
1034 1034
1035 +#ifdef HUNSPELL_CHROME_CLIENT 1035 +#ifdef HUNSPELL_CHROME_CLIENT
1036 + // Not owned by us, owned by the Hunspell object. 1036 + // Not owned by us, owned by the Hunspell object.
1037 + hunspell::BDictReader* bdict_reader; 1037 + hunspell::BDictReader* bdict_reader;
1038 +#endif 1038 +#endif
1039 + 1039 +
1040 public: 1040 public:
1041 1041
(...skipping 12 matching lines...) Expand all
1054 /* load extra dictionaries (only dic files) */ 1054 /* load extra dictionaries (only dic files) */
1055 int add_dic(const char * dpath, const char * key = NULL); 1055 int add_dic(const char * dpath, const char * key = NULL);
1056 +#endif 1056 +#endif
1057 1057
1058 /* spell(word) - spellcheck word 1058 /* spell(word) - spellcheck word
1059 * output: 0 = bad word, not 0 = good word 1059 * output: 0 = bad word, not 0 = good word
1060 Index: src/hunspell/replist.hxx 1060 Index: src/hunspell/replist.hxx
1061 =================================================================== 1061 ===================================================================
1062 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/replist.hxx,v 1062 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/replist.hxx,v
1063 retrieving revision 1.2 1063 retrieving revision 1.2
1064 diff -u -r1.2 replist.hxx 1064 diff -u -p -r1.2 replist.hxx
1065 --- src/hunspell/replist.hxx 15 Apr 2010 11:22:09 -0000 1.2 1065 --- src/hunspell/replist.hxx 15 Apr 2010 11:22:09 -0000 1.2
1066 +++ src/hunspell/replist.hxx» 8 Jan 2013 00:30:25 -0000 1066 +++ src/hunspell/replist.hxx» 26 Feb 2013 23:13:13 -0000
1067 @@ -2,6 +2,12 @@ 1067 @@ -2,6 +2,12 @@
1068 #ifndef _REPLIST_HXX_ 1068 #ifndef _REPLIST_HXX_
1069 #define _REPLIST_HXX_ 1069 #define _REPLIST_HXX_
1070 1070
1071 +#ifdef HUNSPELL_CHROME_CLIENT 1071 +#ifdef HUNSPELL_CHROME_CLIENT
1072 +// Compilation issues in spellchecker.cc think near is a macro, therefore 1072 +// Compilation issues in spellchecker.cc think near is a macro, therefore
1073 +// removing it here solves that problem. 1073 +// removing it here solves that problem.
1074 +#undef near 1074 +#undef near
1075 +#endif 1075 +#endif
1076 + 1076 +
1077 #include "hunvisapi.h" 1077 #include "hunvisapi.h"
1078 1078
1079 #include "w_char.hxx" 1079 #include "w_char.hxx"
1080 Index: src/hunspell/suggestmgr.cxx 1080 Index: src/hunspell/suggestmgr.cxx
1081 =================================================================== 1081 ===================================================================
1082 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.cxx,v 1082 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.cxx,v
1083 retrieving revision 1.24 1083 retrieving revision 1.24
1084 diff -u -r1.24 suggestmgr.cxx 1084 diff -u -p -r1.24 suggestmgr.cxx
1085 --- src/hunspell/suggestmgr.cxx 14 Feb 2011 21:47:24 -0000 1.24 1085 --- src/hunspell/suggestmgr.cxx 14 Feb 2011 21:47:24 -0000 1.24
1086 +++ src/hunspell/suggestmgr.cxx»8 Jan 2013 00:30:26 -0000 1086 +++ src/hunspell/suggestmgr.cxx»26 Feb 2013 23:13:13 -0000
1087 @@ -12,9 +12,110 @@ 1087 @@ -12,9 +12,114 @@
1088 1088
1089 const w_char W_VLINE = { '\0', '|' }; 1089 const w_char W_VLINE = { '\0', '|' };
1090 1090
1091 +#ifdef HUNSPELL_CHROME_CLIENT 1091 +#ifdef HUNSPELL_CHROME_CLIENT
1092 +namespace { 1092 +namespace {
1093 +// A simple class which creates temporary hentry objects which are available 1093 +// A simple class which creates temporary hentry objects which are available
1094 +// only in a scope. To conceal memory operations from SuggestMgr functions, 1094 +// only in a scope. To conceal memory operations from SuggestMgr functions,
1095 +// this object automatically deletes all hentry objects created through 1095 +// this object automatically deletes all hentry objects created through
1096 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet 1096 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet
1097 +// raises a memory error. 1097 +// raises a memory error.
(...skipping 25 matching lines...) Expand all
1123 + hentry* CreateScopedHashEntry(int index, const hentry* source); 1123 + hentry* CreateScopedHashEntry(int index, const hentry* source);
1124 + 1124 +
1125 + private: 1125 + private:
1126 + // A struct which encapsulates the new hentry struct introduced in hunspell 1126 + // A struct which encapsulates the new hentry struct introduced in hunspell
1127 + // 1.2.8. For a pointer to an hentry struct 'h', hunspell 1.2.8 stores a word 1127 + // 1.2.8. For a pointer to an hentry struct 'h', hunspell 1.2.8 stores a word
1128 + // (including a NUL character) into 'h->word[0]',...,'h->word[h->blen]' even 1128 + // (including a NUL character) into 'h->word[0]',...,'h->word[h->blen]' even
1129 + // though arraysize(h->word[]) is 1. Also, it changed 'astr' to a pointer so 1129 + // though arraysize(h->word[]) is 1. Also, it changed 'astr' to a pointer so
1130 + // it can store affix flags into 'h->astr[0]',...,'h->astr[alen-1]'. To handl e 1130 + // it can store affix flags into 'h->astr[0]',...,'h->astr[alen-1]'. To handl e
1131 + // this new hentry struct, we define a struct which combines three values: an 1131 + // this new hentry struct, we define a struct which combines three values: an
1132 + // hentry struct 'hentry'; a char array 'word[kMaxWordLen]', and; an unsigned 1132 + // hentry struct 'hentry'; a char array 'word[kMaxWordLen]', and; an unsigned
1133 + // short value 'astr' so a hentry struct 'h' returned from 1133 + // short array 'astr' so a hentry struct 'h' returned from
1134 + // CreateScopedHashEntry() satisfies the following equations: 1134 + // CreateScopedHashEntry() satisfies the following equations:
1135 + // hentry* h = factory.CreateScopedHashEntry(0, source); 1135 + // hentry* h = factory.CreateScopedHashEntry(0, source);
1136 + // h->word[0] == ((HashEntryItem*)h)->entry.word[0]. 1136 + // h->word[0] == ((HashEntryItem*)h)->entry.word[0].
1137 + // h->word[1] == ((HashEntryItem*)h)->word[0]. 1137 + // h->word[1] == ((HashEntryItem*)h)->word[0].
1138 + // ... 1138 + // ...
1139 + // h->word[h->blen] == ((HashEntryItem*)h)->word[h->blen-1]. 1139 + // h->word[h->blen] == ((HashEntryItem*)h)->word[h->blen-1].
1140 + // h->astr[0] == ((HashEntryItem*)h)->astr. 1140 + // h->astr[0] == ((HashEntryItem*)h)->astr[0].
1141 + // Our BDICT does not use affix flags longer than one for now since they are 1141 + // h->astr[1] == ((HashEntryItem*)h)->astr[1].
1142 + // discarded by convert_dict, i.e. 'h->astr' is always <= 1. Therefore, this 1142 + // ...
1143 + // struct does not use an array for 'astr'. 1143 + // h->astr[h->alen-1] == ((HashEntryItem*)h)->astr[h->alen-1].
1144 + enum { 1144 + enum {
1145 + kMaxWordLen = 128, 1145 + kMaxWordLen = 128,
1146 + kMaxAffixLen = 8,
1146 + }; 1147 + };
1147 + struct HashEntryItem { 1148 + struct HashEntryItem {
1148 + hentry entry; 1149 + hentry entry;
1149 + char word[kMaxWordLen]; 1150 + char word[kMaxWordLen];
1150 + unsigned short astr; 1151 + unsigned short astr[kMaxAffixLen];
1151 + }; 1152 + };
1152 + 1153 +
1153 + HashEntryItem hash_items_[MAX_ROOTS]; 1154 + HashEntryItem hash_items_[MAX_ROOTS];
1154 +}; 1155 +};
1155 + 1156 +
1156 +ScopedHashEntryFactory::ScopedHashEntryFactory() { 1157 +ScopedHashEntryFactory::ScopedHashEntryFactory() {
1157 + memset(&hash_items_[0], 0, sizeof(hash_items_)); 1158 + memset(&hash_items_[0], 0, sizeof(hash_items_));
1158 +} 1159 +}
1159 + 1160 +
1160 +ScopedHashEntryFactory::~ScopedHashEntryFactory() { 1161 +ScopedHashEntryFactory::~ScopedHashEntryFactory() {
1161 +} 1162 +}
1162 + 1163 +
1163 +hentry* ScopedHashEntryFactory::CreateScopedHashEntry(int index, 1164 +hentry* ScopedHashEntryFactory::CreateScopedHashEntry(int index,
1164 + const hentry* source) { 1165 + const hentry* source) {
1165 + if (index >= MAX_ROOTS || source->blen >= kMaxWordLen || source->alen > 1) 1166 + if (index >= MAX_ROOTS || source->blen >= kMaxWordLen)
1166 + return NULL; 1167 + return NULL;
1167 + 1168 +
1168 + // Retrieve a HashEntryItem struct from our spool, initialize it, and 1169 + // Retrieve a HashEntryItem struct from our spool, initialize it, and
1169 + // returns the address of its 'hentry' member. 1170 + // returns the address of its 'hentry' member.
1170 + size_t source_size = sizeof(hentry) + source->blen + 1; 1171 + size_t source_size = sizeof(hentry) + source->blen + 1;
1171 + HashEntryItem* hash_item = &hash_items_[index]; 1172 + HashEntryItem* hash_item = &hash_items_[index];
1172 + memcpy(&hash_item->entry, source, source_size); 1173 + memcpy(&hash_item->entry, source, source_size);
1173 + if (source->astr) { 1174 + if (source->astr) {
1174 + hash_item->astr = *source->astr; 1175 + hash_item->entry.alen = source->alen;
1175 + hash_item->entry.astr = &hash_item->astr; 1176 + if (source->alen > kMaxAffixLen)
1177 + hash_item->entry.alen = kMaxAffixLen;
1178 + memcpy(hash_item->astr, source->astr, hash_item->entry.alen * sizeof(unsign ed short));
1179 + hash_item->entry.astr = &hash_item->astr[0];
1176 + } 1180 + }
1177 + return &hash_item->entry; 1181 + return &hash_item->entry;
1178 +} 1182 +}
1179 + 1183 +
1180 +} // namespace 1184 +} // namespace
1181 +#endif 1185 +#endif
1182 + 1186 +
1183 + 1187 +
1184 +#ifdef HUNSPELL_CHROME_CLIENT 1188 +#ifdef HUNSPELL_CHROME_CLIENT
1185 +SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, 1189 +SuggestMgr::SuggestMgr(hunspell::BDictReader* reader,
1186 + const char * tryme, int maxn, 1190 + const char * tryme, int maxn,
1187 + AffixMgr * aptr) 1191 + AffixMgr * aptr)
1188 +{ 1192 +{
1189 + bdict_reader = reader; 1193 + bdict_reader = reader;
1190 +#else 1194 +#else
1191 SuggestMgr::SuggestMgr(const char * tryme, int maxn, 1195 SuggestMgr::SuggestMgr(const char * tryme, int maxn,
1192 AffixMgr * aptr) 1196 AffixMgr * aptr)
1193 { 1197 {
1194 +#endif 1198 +#endif
1195 1199
1196 // register affix manager and check in string of chars to 1200 // register affix manager and check in string of chars to
1197 // try when building candidate suggestions 1201 // try when building candidate suggestions
1198 @@ -407,6 +508,49 @@ 1202 @@ -407,6 +512,49 @@ int SuggestMgr::replchars(char** wlst, c
1199 int lenr, lenp; 1203 int lenr, lenp;
1200 int wl = strlen(word); 1204 int wl = strlen(word);
1201 if (wl < 2 || ! pAMgr) return ns; 1205 if (wl < 2 || ! pAMgr) return ns;
1202 + 1206 +
1203 +#ifdef HUNSPELL_CHROME_CLIENT 1207 +#ifdef HUNSPELL_CHROME_CLIENT
1204 + const char *pattern, *pattern2; 1208 + const char *pattern, *pattern2;
1205 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator (); 1209 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator ();
1206 + while (iterator.GetNext(&pattern, &pattern2)) { 1210 + while (iterator.GetNext(&pattern, &pattern2)) {
1207 + r = word; 1211 + r = word;
1208 + lenr = strlen(pattern2); 1212 + lenr = strlen(pattern2);
(...skipping 29 matching lines...) Expand all
1238 + sp = strchr(prev, ' '); 1242 + sp = strchr(prev, ' ');
1239 + } 1243 + }
1240 + } 1244 + }
1241 + r++; // search for the next letter 1245 + r++; // search for the next letter
1242 + } 1246 + }
1243 + } 1247 + }
1244 +#else 1248 +#else
1245 int numrep = pAMgr->get_numrep(); 1249 int numrep = pAMgr->get_numrep();
1246 struct replentry* reptable = pAMgr->get_reptable(); 1250 struct replentry* reptable = pAMgr->get_reptable();
1247 if (reptable==NULL) return ns; 1251 if (reptable==NULL) return ns;
1248 @@ -448,6 +592,7 @@ 1252 @@ -448,6 +596,7 @@ int SuggestMgr::replchars(char** wlst, c
1249 r++; // search for the next letter 1253 r++; // search for the next letter
1250 } 1254 }
1251 } 1255 }
1252 +#endif 1256 +#endif
1253 return ns; 1257 return ns;
1254 } 1258 }
1255 1259
1256 @@ -678,7 +823,9 @@ 1260 @@ -678,7 +827,9 @@ int SuggestMgr::extrachar(char** wlst, c
1257 // error is missing a letter it needs 1261 // error is missing a letter it needs
1258 int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsugg est) 1262 int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsugg est)
1259 { 1263 {
1260 - char candidate[MAXSWUTF8L]; 1264 - char candidate[MAXSWUTF8L];
1261 + // TODO(rouslan): Remove the interim change below when this patch lands: 1265 + // TODO(rouslan): Remove the interim change below when this patch lands:
1262 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639 5 1266 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639 5
1263 + char candidate[MAXSWUTF8L + 4]; 1267 + char candidate[MAXSWUTF8L + 4];
1264 char * p; 1268 char * p;
1265 clock_t timelimit = clock(); 1269 clock_t timelimit = clock();
1266 int timer = MINTIMER; 1270 int timer = MINTIMER;
1267 @@ -700,8 +847,10 @@ 1271 @@ -700,8 +851,10 @@ int SuggestMgr::forgotchar(char ** wlst,
1268 // error is missing a letter it needs 1272 // error is missing a letter it needs
1269 int SuggestMgr::forgotchar_utf(char ** wlst, const w_char * word, int wl, int n s, int cpdsuggest) 1273 int SuggestMgr::forgotchar_utf(char ** wlst, const w_char * word, int wl, int n s, int cpdsuggest)
1270 { 1274 {
1271 - w_char candidate_utf[MAXSWL]; 1275 - w_char candidate_utf[MAXSWL];
1272 - char candidate[MAXSWUTF8L]; 1276 - char candidate[MAXSWUTF8L];
1273 + // TODO(rouslan): Remove the interim change below when this patch lands: 1277 + // TODO(rouslan): Remove the interim change below when this patch lands:
1274 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639 5 1278 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639 5
1275 + w_char candidate_utf[MAXSWL + 1]; 1279 + w_char candidate_utf[MAXSWL + 1];
1276 + char candidate[MAXSWUTF8L + 4]; 1280 + char candidate[MAXSWUTF8L + 4];
1277 w_char * p; 1281 w_char * p;
1278 clock_t timelimit = clock(); 1282 clock_t timelimit = clock();
1279 int timer = MINTIMER; 1283 int timer = MINTIMER;
1280 @@ -1057,6 +1206,9 @@ 1284 @@ -1057,6 +1210,9 @@ int SuggestMgr::ngsuggest(char** wlst, c
1281 1285
1282 struct hentry* hp = NULL; 1286 struct hentry* hp = NULL;
1283 int col = -1; 1287 int col = -1;
1284 +#ifdef HUNSPELL_CHROME_CLIENT 1288 +#ifdef HUNSPELL_CHROME_CLIENT
1285 + ScopedHashEntryFactory hash_entry_factory; 1289 + ScopedHashEntryFactory hash_entry_factory;
1286 +#endif 1290 +#endif
1287 phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL; 1291 phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL;
1288 char target[MAXSWUTF8L]; 1292 char target[MAXSWUTF8L];
1289 char candidate[MAXSWUTF8L]; 1293 char candidate[MAXSWUTF8L];
1290 @@ -1115,7 +1267,11 @@ 1294 @@ -1115,7 +1271,11 @@ int SuggestMgr::ngsuggest(char** wlst, c
1291 1295
1292 if (sc > scores[lp]) { 1296 if (sc > scores[lp]) {
1293 scores[lp] = sc; 1297 scores[lp] = sc;
1294 +#ifdef HUNSPELL_CHROME_CLIENT 1298 +#ifdef HUNSPELL_CHROME_CLIENT
1295 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp); 1299 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp);
1296 +#else 1300 +#else
1297 roots[lp] = hp; 1301 roots[lp] = hp;
1298 +#endif 1302 +#endif
1299 lval = sc; 1303 lval = sc;
1300 for (j=0; j < MAX_ROOTS; j++) 1304 for (j=0; j < MAX_ROOTS; j++)
1301 if (scores[j] < lval) { 1305 if (scores[j] < lval) {
1302 Index: src/hunspell/suggestmgr.hxx 1306 Index: src/hunspell/suggestmgr.hxx
1303 =================================================================== 1307 ===================================================================
1304 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.hxx,v 1308 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.hxx,v
1305 retrieving revision 1.5 1309 retrieving revision 1.5
1306 diff -u -r1.5 suggestmgr.hxx 1310 diff -u -p -r1.5 suggestmgr.hxx
1307 --- src/hunspell/suggestmgr.hxx 21 Jan 2011 22:10:24 -0000 1.5 1311 --- src/hunspell/suggestmgr.hxx 21 Jan 2011 22:10:24 -0000 1.5
1308 +++ src/hunspell/suggestmgr.hxx»8 Jan 2013 00:30:26 -0000 1312 +++ src/hunspell/suggestmgr.hxx»26 Feb 2013 23:13:13 -0000
1309 @@ -52,7 +52,11 @@ 1313 @@ -52,7 +52,11 @@ class LIBHUNSPELL_DLL_EXPORTED SuggestMg
1310 1314
1311 1315
1312 public: 1316 public:
1313 +#ifdef HUNSPELL_CHROME_CLIENT 1317 +#ifdef HUNSPELL_CHROME_CLIENT
1314 + SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, Affix Mgr *aptr); 1318 + SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, Affix Mgr *aptr);
1315 +#else 1319 +#else
1316 SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr); 1320 SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr);
1317 +#endif 1321 +#endif
1318 ~SuggestMgr(); 1322 ~SuggestMgr();
1319 1323
1320 int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug); 1324 int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug);
1321 @@ -66,6 +70,10 @@ 1325 @@ -66,6 +70,10 @@ public:
1322 char * suggest_morph_for_spelling_error(const char * word); 1326 char * suggest_morph_for_spelling_error(const char * word);
1323 1327
1324 private: 1328 private:
1325 +#ifdef HUNSPELL_CHROME_CLIENT 1329 +#ifdef HUNSPELL_CHROME_CLIENT
1326 + // Not owned by us, owned by the Hunspell object. 1330 + // Not owned by us, owned by the Hunspell object.
1327 + hunspell::BDictReader* bdict_reader; 1331 + hunspell::BDictReader* bdict_reader;
1328 +#endif 1332 +#endif
1329 int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsugg est, 1333 int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsugg est,
1330 int * timer, clock_t * timelimit); 1334 int * timer, clock_t * timelimit);
1331 int checkword(const char *, int, int, int *, clock_t *); 1335 int checkword(const char *, int, int, int *, clock_t *);
OLDNEW
« no previous file with comments | « README.chromium ('k') | src/hunspell/suggestmgr.cxx » ('j') | src/hunspell/suggestmgr.cxx » ('J')

Powered by Google App Engine
This is Rietveld 408576698