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

Side by Side Diff: google.patch

Issue 11639053: Bring Hunspell google.patch up to date (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/hunspell.git@master
Patch Set: Created 8 years 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
« no previous file with comments | « README.chromium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 -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» 23 Mar 2012 05:56:23 -0000 7 +++ src/hunspell/affixmgr.cxx» 20 Dec 2012 23:40:03 -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)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 -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» 23 Mar 2012 05:56:23 -0000 198 +++ src/hunspell/affixmgr.hxx» 20 Dec 2012 23:40:03 -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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 -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» 23 Mar 2012 05:56:23 -0000 283 +++ src/hunspell/filemgr.cxx» 20 Dec 2012 23:40:03 -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 24 matching lines...) Expand all
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 -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» 23 Mar 2012 05:56:23 -0000 328 +++ src/hunspell/filemgr.hxx» 20 Dec 2012 23:40:03 -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 22 matching lines...) Expand all
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 -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» 23 Mar 2012 05:56:23 -0000 371 +++ src/hunspell/hashmgr.cxx» 20 Dec 2012 23:40:03 -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)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 @@ -339,6 +407,44 @@ 494 @@ -256,6 +324,12 @@
495 // remove word (personal dictionary function for standalone applications)
496 int HashMgr::remove(const char * word)
497 {
498 +#ifdef HUNSPELL_CHROME_CLIENT
499 + std::map<base::StringPiece, int>::iterator iter =
500 + custom_word_to_affix_id_map_.find(word);
501 + if (iter != custom_word_to_affix_id_map_.end())
502 + custom_word_to_affix_id_map_.erase(iter);
503 +#else
504 struct hentry * dp = lookup(word);
505 while (dp) {
506 if (dp->alen == 0 || !TESTAFF(dp->astr, forbiddenword, dp->alen)) {
507 @@ -270,6 +344,7 @@
508 }
509 dp = dp->next_homonym;
510 }
511 +#endif
512 return 0;
513 }
514
515 @@ -339,6 +414,44 @@
495 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp); 516 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp);
496 struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const 517 struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const
497 { 518 {
498 +#ifdef HUNSPELL_CHROME_CLIENT 519 +#ifdef HUNSPELL_CHROME_CLIENT
499 + // Return NULL if dictionary is not valid. 520 + // Return NULL if dictionary is not valid.
500 + if (!bdict_reader->IsValid()) 521 + if (!bdict_reader->IsValid())
501 + return NULL; 522 + return NULL;
502 + 523 +
503 + // 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
504 + // 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
529 + hentry entry; 550 + hentry entry;
530 + char word[kMaxWordLen]; 551 + char word[kMaxWordLen];
531 + } hash_entry; 552 + } hash_entry;
532 + 553 +
533 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry), 554 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry),
534 + &word[0], word_len, affix_ids[0]); 555 + &word[0], word_len, affix_ids[0]);
535 +#else 556 +#else
536 if (hp && hp->next != NULL) return hp->next; 557 if (hp && hp->next != NULL) return hp->next;
537 for (col++; col < tablesize; col++) { 558 for (col++; col < tablesize; col++) {
538 if (tableptr[col]) return tableptr[col]; 559 if (tableptr[col]) return tableptr[col];
539 @@ -346,11 +452,13 @@ 560 @@ -346,11 +459,13 @@
540 // null at end and reset to start 561 // null at end and reset to start
541 col = -1; 562 col = -1;
542 return NULL; 563 return NULL;
543 +#endif 564 +#endif
544 } 565 }
545 566
546 // 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
547 int HashMgr::load_tables(const char * tpath, const char * key) 568 int HashMgr::load_tables(const char * tpath, const char * key)
548 { 569 {
549 +#ifndef HUNSPELL_CHROME_CLIENT 570 +#ifndef HUNSPELL_CHROME_CLIENT
550 int al; 571 int al;
551 char * ap; 572 char * ap;
552 char * dp; 573 char * dp;
553 @@ -471,6 +579,7 @@ 574 @@ -471,6 +586,7 @@
554 } 575 }
555 576
556 delete dict; 577 delete dict;
557 +#endif 578 +#endif
558 return 0; 579 return 0;
559 } 580 }
560 581
561 @@ -479,6 +588,9 @@ 582 @@ -479,6 +595,9 @@
562 583
563 int HashMgr::hash(const char * word) const 584 int HashMgr::hash(const char * word) const
564 { 585 {
565 +#ifdef HUNSPELL_CHROME_CLIENT 586 +#ifdef HUNSPELL_CHROME_CLIENT
566 + return 0; 587 + return 0;
567 +#else 588 +#else
568 long hv = 0; 589 long hv = 0;
569 for (int i=0; i < 4 && *word != 0; i++) 590 for (int i=0; i < 4 && *word != 0; i++)
570 hv = (hv << 8) | (*word++); 591 hv = (hv << 8) | (*word++);
571 @@ -487,6 +599,7 @@ 592 @@ -487,6 +606,7 @@
572 hv ^= (*word++); 593 hv ^= (*word++);
573 } 594 }
574 return (unsigned long) hv % tablesize; 595 return (unsigned long) hv % tablesize;
575 +#endif 596 +#endif
576 } 597 }
577 598
578 int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af) { 599 int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af) {
579 @@ -607,7 +720,12 @@ 600 @@ -607,7 +727,12 @@
580 int firstline = 1; 601 int firstline = 1;
581 602
582 // open the affix file 603 // open the affix file
583 +#ifdef HUNSPELL_CHROME_CLIENT 604 +#ifdef HUNSPELL_CHROME_CLIENT
584 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator(); 605 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator();
585 + FileMgr * afflst = new FileMgr(&iterator); 606 + FileMgr * afflst = new FileMgr(&iterator);
586 +#else 607 +#else
587 FileMgr * afflst = new FileMgr(affpath, key); 608 FileMgr * afflst = new FileMgr(affpath, key);
588 +#endif 609 +#endif
589 if (!afflst) { 610 if (!afflst) {
590 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);
591 return 1; 612 return 1;
592 @@ -802,6 +920,121 @@ 613 @@ -802,6 +927,121 @@
593 return 0; 614 return 0;
594 } 615 }
595 616
596 +#ifdef HUNSPELL_CHROME_CLIENT 617 +#ifdef HUNSPELL_CHROME_CLIENT
597 +int HashMgr::LoadAFLines() 618 +int HashMgr::LoadAFLines()
598 +{ 619 +{
599 + utf8 = 1; // We always use UTF-8. 620 + utf8 = 1; // We always use UTF-8.
600 + 621 +
601 + // 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.
602 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator(); 623 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 + 731 +
711 int HashMgr::is_aliasf() { 732 int HashMgr::is_aliasf() {
712 return (aliasf != NULL); 733 return (aliasf != NULL);
713 } 734 }
714 Index: src/hunspell/hashmgr.hxx 735 Index: src/hunspell/hashmgr.hxx
715 =================================================================== 736 ===================================================================
716 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.hxx,v 737 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.hxx,v
717 retrieving revision 1.3 738 retrieving revision 1.3
718 diff -u -r1.3 hashmgr.hxx 739 diff -u -r1.3 hashmgr.hxx
719 --- 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
720 +++ src/hunspell/hashmgr.hxx» 23 Mar 2012 05:56:23 -0000 741 +++ src/hunspell/hashmgr.hxx» 20 Dec 2012 23:40:03 -0000
721 @@ -8,10 +8,25 @@ 742 @@ -8,10 +8,25 @@
722 #include "htypes.hxx" 743 #include "htypes.hxx"
723 #include "filemgr.hxx" 744 #include "filemgr.hxx"
724 745
725 +#ifdef HUNSPELL_CHROME_CLIENT 746 +#ifdef HUNSPELL_CHROME_CLIENT
726 +#include <string> 747 +#include <string>
727 +#include <map> 748 +#include <map>
728 + 749 +
729 +#include "base/stl_util.h" 750 +#include "base/stl_util.h"
730 +#include "base/string_piece.h" 751 +#include "base/string_piece.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 + 829 +
809 int add_hidden_capitalized_word(char * word, int wbl, int wcl, 830 int add_hidden_capitalized_word(char * word, int wbl, int wcl,
810 unsigned short * flags, int al, char * dp, int captype); 831 unsigned short * flags, int al, char * dp, int captype);
811 int parse_aliasm(char * line, FileMgr * af); 832 int parse_aliasm(char * line, FileMgr * af);
812 Index: src/hunspell/htypes.hxx 833 Index: src/hunspell/htypes.hxx
813 =================================================================== 834 ===================================================================
814 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/htypes.hxx,v 835 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/htypes.hxx,v
815 retrieving revision 1.3 836 retrieving revision 1.3
816 diff -u -r1.3 htypes.hxx 837 diff -u -r1.3 htypes.hxx
817 --- 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
818 +++ src/hunspell/htypes.hxx» 23 Mar 2012 05:56:23 -0000 839 +++ src/hunspell/htypes.hxx» 20 Dec 2012 23:40:03 -0000
819 @@ -1,6 +1,16 @@ 840 @@ -1,6 +1,16 @@
820 #ifndef _HTYPES_HXX_ 841 #ifndef _HTYPES_HXX_
821 #define _HTYPES_HXX_ 842 #define _HTYPES_HXX_
822 843
823 +#ifdef HUNSPELL_CHROME_CLIENT 844 +#ifdef HUNSPELL_CHROME_CLIENT
824 +// 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
825 +// contain very long AF lines (~ 12,000 chars). 846 +// contain very long AF lines (~ 12,000 chars).
826 +// 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
827 +// longer lines than MAXDELEN. 848 +// longer lines than MAXDELEN.
828 +#define MAXDELEN (8192 * 2) 849 +#define MAXDELEN (8192 * 2)
829 +#else 850 +#else
830 +#define MAXDELEN 8192 851 +#define MAXDELEN 8192
831 +#endif // HUNSPELL_CHROME_CLIENT 852 +#endif // HUNSPELL_CHROME_CLIENT
832 + 853 +
833 #define ROTATE_LEN 5 854 #define ROTATE_LEN 5
834 855
835 #define ROTATE(v,q) \ 856 #define ROTATE(v,q) \
836 Index: src/hunspell/hunspell.cxx 857 Index: src/hunspell/hunspell.cxx
837 =================================================================== 858 ===================================================================
838 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.cxx,v 859 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.cxx,v
839 retrieving revision 1.29 860 retrieving revision 1.29
840 diff -u -r1.29 hunspell.cxx 861 diff -u -r1.29 hunspell.cxx
841 --- 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
842 +++ src/hunspell/hunspell.cxx» 23 Mar 2012 05:56:24 -0000 863 +++ src/hunspell/hunspell.cxx» 20 Dec 2012 23:40:03 -0000
843 @@ -12,15 +12,30 @@ 864 @@ -7,20 +7,37 @@
865
866 #include "hunspell.hxx"
867 #include "hunspell.h"
868 +#ifndef HUNSPELL_CHROME_CLIENT
869 #ifndef MOZILLA_CLIENT
870 # include "config.h"
844 #endif 871 #endif
872 +#endif
845 #include "csutil.hxx" 873 #include "csutil.hxx"
846 874
847 +#ifdef HUNSPELL_CHROME_CLIENT 875 +#ifdef HUNSPELL_CHROME_CLIENT
848 +Hunspell::Hunspell(const unsigned char* bdict_data, size_t bdict_length) 876 +Hunspell::Hunspell(const unsigned char* bdict_data, size_t bdict_length)
849 +#else 877 +#else
850 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key) 878 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
851 +#endif 879 +#endif
852 { 880 {
853 encoding = NULL; 881 encoding = NULL;
854 csconv = NULL; 882 csconv = NULL;
855 utf8 = 0; 883 utf8 = 0;
856 complexprefixes = 0; 884 complexprefixes = 0;
857 +#ifndef HUNSPELL_CHROME_CLIENT 885 +#ifndef HUNSPELL_CHROME_CLIENT
858 affixpath = mystrdup(affpath); 886 affixpath = mystrdup(affpath);
859 +#endif 887 +#endif
860 maxdic = 0; 888 maxdic = 0;
861 889
862 +#ifdef HUNSPELL_CHROME_CLIENT 890 +#ifdef HUNSPELL_CHROME_CLIENT
863 + bdict_reader = new hunspell::BDictReader; 891 + bdict_reader = new hunspell::BDictReader;
864 + bdict_reader->Init(bdict_data, bdict_length); 892 + bdict_reader->Init(bdict_data, bdict_length);
865 + 893 +
866 + pHMgr[0] = new HashMgr(bdict_reader); 894 + pHMgr[0] = new HashMgr(bdict_reader);
867 + if (pHMgr[0]) maxdic = 1; 895 + if (pHMgr[0]) maxdic = 1;
868 + 896 +
869 + pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic); 897 + pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic);
870 +#else 898 +#else
871 /* first set up the hash manager */ 899 /* first set up the hash manager */
872 pHMgr[0] = new HashMgr(dpath, affpath, key); 900 pHMgr[0] = new HashMgr(dpath, affpath, key);
873 if (pHMgr[0]) maxdic = 1; 901 if (pHMgr[0]) maxdic = 1;
874 @@ -28,6 +43,7 @@ 902 @@ -28,6 +45,7 @@
875 /* next set up the affix manager */ 903 /* next set up the affix manager */
876 /* it needs access to the hash manager lookup methods */ 904 /* it needs access to the hash manager lookup methods */
877 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key); 905 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key);
878 +#endif 906 +#endif
879 907
880 /* get the preferred try string and the dictionary */ 908 /* get the preferred try string and the dictionary */
881 /* encoding from the Affix Manager for that dictionary */ 909 /* encoding from the Affix Manager for that dictionary */
882 @@ -59,10 +75,16 @@ 910 @@ -41,7 +59,11 @@
911 wordbreak = pAMgr->get_breaktable();
912
913 /* and finally set up the suggestion manager */
914 +#ifdef HUNSPELL_CHROME_CLIENT
915 + pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr);
916 +#else
917 pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr);
918 +#endif
919 if (try_string) free(try_string);
920 }
921
922 @@ -59,10 +81,16 @@
883 csconv= NULL; 923 csconv= NULL;
884 if (encoding) free(encoding); 924 if (encoding) free(encoding);
885 encoding = NULL; 925 encoding = NULL;
886 +#ifdef HUNSPELL_CHROME_CLIENT 926 +#ifdef HUNSPELL_CHROME_CLIENT
887 + if (bdict_reader) delete bdict_reader; 927 + if (bdict_reader) delete bdict_reader;
888 + bdict_reader = NULL; 928 + bdict_reader = NULL;
889 +#else 929 +#else
890 if (affixpath) free(affixpath); 930 if (affixpath) free(affixpath);
891 affixpath = NULL; 931 affixpath = NULL;
892 +#endif 932 +#endif
893 } 933 }
894 934
895 +#ifndef HUNSPELL_CHROME_CLIENT 935 +#ifndef HUNSPELL_CHROME_CLIENT
896 // load extra dictionaries 936 // load extra dictionaries
897 int Hunspell::add_dic(const char * dpath, const char * key) { 937 int Hunspell::add_dic(const char * dpath, const char * key) {
898 if (maxdic == MAXDIC || !affixpath) return 1; 938 if (maxdic == MAXDIC || !affixpath) return 1;
899 @@ -70,6 +92,7 @@ 939 @@ -70,6 +98,7 @@
900 if (pHMgr[maxdic]) maxdic++; else return 1; 940 if (pHMgr[maxdic]) maxdic++; else return 1;
901 return 0; 941 return 0;
902 } 942 }
903 +#endif 943 +#endif
904 944
905 // make a copy of src at destination while removing all leading 945 // make a copy of src at destination while removing all leading
906 // blanks and removing any trailing periods after recording 946 // blanks and removing any trailing periods after recording
907 @@ -322,6 +345,9 @@ 947 @@ -322,6 +351,9 @@
908 948
909 int Hunspell::spell(const char * word, int * info, char ** root) 949 int Hunspell::spell(const char * word, int * info, char ** root)
910 { 950 {
911 +#ifdef HUNSPELL_CHROME_CLIENT 951 +#ifdef HUNSPELL_CHROME_CLIENT
912 + if (pHMgr) pHMgr[0]->EmptyHentryCache(); 952 + if (pHMgr) pHMgr[0]->EmptyHentryCache();
913 +#endif 953 +#endif
914 struct hentry * rv=NULL; 954 struct hentry * rv=NULL;
915 // need larger vector. For example, Turkish capital letter I converted a 955 // need larger vector. For example, Turkish capital letter I converted a
916 // 2-byte UTF-8 character (dotless i) by mkallsmall. 956 // 2-byte UTF-8 character (dotless i) by mkallsmall.
917 @@ -586,6 +612,13 @@ 957 @@ -586,6 +618,13 @@
918 if (!len) 958 if (!len)
919 return NULL; 959 return NULL;
920 960
921 +#ifdef HUNSPELL_CHROME_CLIENT 961 +#ifdef HUNSPELL_CHROME_CLIENT
922 + // 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
923 + // 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.
924 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX WORDLEN)) 964 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX WORDLEN))
925 + return NULL; 965 + return NULL;
926 +#endif 966 +#endif
927 + 967 +
928 // word reversing wrapper for complex prefixes 968 // word reversing wrapper for complex prefixes
929 if (complexprefixes) { 969 if (complexprefixes) {
930 if (word != w2) { 970 if (word != w2) {
931 @@ -675,6 +708,9 @@ 971 @@ -675,6 +714,9 @@
932 972
933 int Hunspell::suggest(char*** slst, const char * word) 973 int Hunspell::suggest(char*** slst, const char * word)
934 { 974 {
935 +#ifdef HUNSPELL_CHROME_CLIENT 975 +#ifdef HUNSPELL_CHROME_CLIENT
936 + if (pHMgr) pHMgr[0]->EmptyHentryCache(); 976 + if (pHMgr) pHMgr[0]->EmptyHentryCache();
937 +#endif 977 +#endif
938 int onlycmpdsug = 0; 978 int onlycmpdsug = 0;
939 char cw[MAXWORDUTF8LEN]; 979 char cw[MAXWORDUTF8LEN];
940 char wspace[MAXWORDUTF8LEN]; 980 char wspace[MAXWORDUTF8LEN];
941 @@ -1921,13 +1957,21 @@ 981 @@ -1921,13 +1963,21 @@
942 982
943 Hunhandle *Hunspell_create(const char * affpath, const char * dpath) 983 Hunhandle *Hunspell_create(const char * affpath, const char * dpath)
944 { 984 {
945 +#ifdef HUNSPELL_CHROME_CLIENT 985 +#ifdef HUNSPELL_CHROME_CLIENT
946 + return NULL; 986 + return NULL;
947 +#else 987 +#else
948 return (Hunhandle*)(new Hunspell(affpath, dpath)); 988 return (Hunhandle*)(new Hunspell(affpath, dpath));
949 +#endif 989 +#endif
950 } 990 }
951 991
952 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath, 992 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath,
953 const char * key) 993 const char * key)
954 { 994 {
955 +#ifdef HUNSPELL_CHROME_CLIENT 995 +#ifdef HUNSPELL_CHROME_CLIENT
956 + return NULL; 996 + return NULL;
957 +#else 997 +#else
958 return (Hunhandle*)(new Hunspell(affpath, dpath, key)); 998 return (Hunhandle*)(new Hunspell(affpath, dpath, key));
959 +#endif 999 +#endif
960 } 1000 }
961 1001
962 void Hunspell_destroy(Hunhandle *pHunspell) 1002 void Hunspell_destroy(Hunhandle *pHunspell)
963 Index: src/hunspell/hunspell.hxx 1003 Index: src/hunspell/hunspell.hxx
964 =================================================================== 1004 ===================================================================
965 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.hxx,v 1005 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.hxx,v
966 retrieving revision 1.6 1006 retrieving revision 1.6
967 diff -u -r1.6 hunspell.hxx 1007 diff -u -r1.6 hunspell.hxx
968 --- 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
969 +++ src/hunspell/hunspell.hxx» 23 Mar 2012 05:56:24 -0000 1009 +++ src/hunspell/hunspell.hxx» 20 Dec 2012 23:40:03 -0000
970 @@ -5,6 +5,10 @@ 1010 @@ -5,6 +5,10 @@
971 #include "suggestmgr.hxx" 1011 #include "suggestmgr.hxx"
972 #include "langnum.hxx" 1012 #include "langnum.hxx"
973 1013
974 +#ifdef HUNSPELL_CHROME_CLIENT 1014 +#ifdef HUNSPELL_CHROME_CLIENT
975 +#include "third_party/hunspell/google/bdict_reader.h" 1015 +#include "third_party/hunspell/google/bdict_reader.h"
976 +#endif 1016 +#endif
977 + 1017 +
978 #define SPELL_XML "<?xml?>" 1018 #define SPELL_XML "<?xml?>"
979 1019
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 +#endif 1056 +#endif
1017 1057
1018 /* spell(word) - spellcheck word 1058 /* spell(word) - spellcheck word
1019 * output: 0 = bad word, not 0 = good word 1059 * output: 0 = bad word, not 0 = good word
1020 Index: src/hunspell/replist.hxx 1060 Index: src/hunspell/replist.hxx
1021 =================================================================== 1061 ===================================================================
1022 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/replist.hxx,v 1062 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/replist.hxx,v
1023 retrieving revision 1.2 1063 retrieving revision 1.2
1024 diff -u -r1.2 replist.hxx 1064 diff -u -r1.2 replist.hxx
1025 --- 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
1026 +++ src/hunspell/replist.hxx» 23 Mar 2012 05:56:24 -0000 1066 +++ src/hunspell/replist.hxx» 20 Dec 2012 23:40:03 -0000
1027 @@ -2,6 +2,12 @@ 1067 @@ -2,6 +2,12 @@
1028 #ifndef _REPLIST_HXX_ 1068 #ifndef _REPLIST_HXX_
1029 #define _REPLIST_HXX_ 1069 #define _REPLIST_HXX_
1030 1070
1031 +#ifdef HUNSPELL_CHROME_CLIENT 1071 +#ifdef HUNSPELL_CHROME_CLIENT
1032 +// Compilation issues in spellchecker.cc think near is a macro, therefore 1072 +// Compilation issues in spellchecker.cc think near is a macro, therefore
1033 +// removing it here solves that problem. 1073 +// removing it here solves that problem.
1034 +#undef near 1074 +#undef near
1035 +#endif 1075 +#endif
1036 + 1076 +
1037 #include "hunvisapi.h" 1077 #include "hunvisapi.h"
1038 1078
1039 #include "w_char.hxx" 1079 #include "w_char.hxx"
1040 Index: src/hunspell/suggestmgr.cxx 1080 Index: src/hunspell/suggestmgr.cxx
1041 =================================================================== 1081 ===================================================================
1042 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.cxx,v 1082 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.cxx,v
1043 retrieving revision 1.24 1083 retrieving revision 1.24
1044 diff -u -r1.24 suggestmgr.cxx 1084 diff -u -r1.24 suggestmgr.cxx
1045 --- 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
1046 +++ src/hunspell/suggestmgr.cxx»23 Mar 2012 05:56:24 -0000 1086 +++ src/hunspell/suggestmgr.cxx»20 Dec 2012 23:40:03 -0000
1047 @@ -12,6 +12,98 @@ 1087 @@ -12,9 +12,110 @@
1048 1088
1049 const w_char W_VLINE = { '\0', '|' }; 1089 const w_char W_VLINE = { '\0', '|' };
1050 1090
1051 +#ifdef HUNSPELL_CHROME_CLIENT 1091 +#ifdef HUNSPELL_CHROME_CLIENT
1052 +namespace { 1092 +namespace {
1053 +// A simple class which creates temporary hentry objects which are available 1093 +// A simple class which creates temporary hentry objects which are available
1054 +// only in a scope. To conceal memory operations from SuggestMgr functions, 1094 +// only in a scope. To conceal memory operations from SuggestMgr functions,
1055 +// this object automatically deletes all hentry objects created through 1095 +// this object automatically deletes all hentry objects created through
1056 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet 1096 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet
1057 +// raises a memory error. 1097 +// raises a memory error.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 + if (source->astr) { 1173 + if (source->astr) {
1134 + hash_item->astr = *source->astr; 1174 + hash_item->astr = *source->astr;
1135 + hash_item->entry.astr = &hash_item->astr; 1175 + hash_item->entry.astr = &hash_item->astr;
1136 + } 1176 + }
1137 + return &hash_item->entry; 1177 + return &hash_item->entry;
1138 +} 1178 +}
1139 + 1179 +
1140 +} // namespace 1180 +} // namespace
1141 +#endif 1181 +#endif
1142 + 1182 +
1183 +
1184 +#ifdef HUNSPELL_CHROME_CLIENT
1185 +SuggestMgr::SuggestMgr(hunspell::BDictReader* reader,
1186 + const char * tryme, int maxn,
1187 + AffixMgr * aptr)
1188 +{
1189 + bdict_reader = reader;
1190 +#else
1143 SuggestMgr::SuggestMgr(const char * tryme, int maxn, 1191 SuggestMgr::SuggestMgr(const char * tryme, int maxn,
1144 AffixMgr * aptr) 1192 AffixMgr * aptr)
1145 { 1193 {
1146 @@ -1057,6 +1149,9 @@ 1194 +#endif
1195
1196 // register affix manager and check in string of chars to
1197 // try when building candidate suggestions
1198 @@ -407,6 +508,49 @@
1199 int lenr, lenp;
1200 int wl = strlen(word);
1201 if (wl < 2 || ! pAMgr) return ns;
1202 +
1203 +#ifdef HUNSPELL_CHROME_CLIENT
1204 + const char *pattern, *pattern2;
1205 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator ();
1206 + while (iterator.GetNext(&pattern, &pattern2)) {
1207 + r = word;
1208 + lenr = strlen(pattern2);
1209 + lenp = strlen(pattern);
1210 +
1211 + // search every occurence of the pattern in the word
1212 + while ((r=strstr(r, pattern)) != NULL) {
1213 + strcpy(candidate, word);
1214 + if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break;
1215 + strcpy(candidate+(r-word), pattern2);
1216 + strcpy(candidate+(r-word)+lenr, r+lenp);
1217 + ns = testsug(wlst, candidate, wl-lenp+lenr, ns, cpdsuggest, NULL, NUL L);
1218 + if (ns == -1) return -1;
1219 + // check REP suggestions with space
1220 + char * sp = strchr(candidate, ' ');
1221 + if (sp) {
1222 + char * prev = candidate;
1223 + while (sp) {
1224 + *sp = '\0';
1225 + if (checkword(prev, strlen(prev), 0, NULL, NULL)) {
1226 + int oldns = ns;
1227 + *sp = ' ';
1228 + ns = testsug(wlst, sp + 1, strlen(sp + 1), ns, cpdsuggest, NULL , NULL);
1229 + if (ns == -1) return -1;
1230 + if (oldns < ns) {
1231 + free(wlst[ns - 1]);
1232 + wlst[ns - 1] = mystrdup(candidate);
1233 + if (!wlst[ns - 1]) return -1;
1234 + }
1235 + }
1236 + *sp = ' ';
1237 + prev = sp + 1;
1238 + sp = strchr(prev, ' ');
1239 + }
1240 + }
1241 + r++; // search for the next letter
1242 + }
1243 + }
1244 +#else
1245 int numrep = pAMgr->get_numrep();
1246 struct replentry* reptable = pAMgr->get_reptable();
1247 if (reptable==NULL) return ns;
1248 @@ -448,6 +592,7 @@
1249 r++; // search for the next letter
1250 }
1251 }
1252 +#endif
1253 return ns;
1254 }
1255
1256 @@ -1057,6 +1202,9 @@
1147 1257
1148 struct hentry* hp = NULL; 1258 struct hentry* hp = NULL;
1149 int col = -1; 1259 int col = -1;
1150 +#ifdef HUNSPELL_CHROME_CLIENT 1260 +#ifdef HUNSPELL_CHROME_CLIENT
1151 + ScopedHashEntryFactory hash_entry_factory; 1261 + ScopedHashEntryFactory hash_entry_factory;
1152 +#endif 1262 +#endif
1153 phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL; 1263 phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL;
1154 char target[MAXSWUTF8L]; 1264 char target[MAXSWUTF8L];
1155 char candidate[MAXSWUTF8L]; 1265 char candidate[MAXSWUTF8L];
1156 @@ -1115,7 +1210,11 @@ 1266 @@ -1115,7 +1263,11 @@
1157 1267
1158 if (sc > scores[lp]) { 1268 if (sc > scores[lp]) {
1159 scores[lp] = sc; 1269 scores[lp] = sc;
1160 +#ifdef HUNSPELL_CHROME_CLIENT 1270 +#ifdef HUNSPELL_CHROME_CLIENT
1161 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp); 1271 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp);
1162 +#else 1272 +#else
1163 roots[lp] = hp; 1273 roots[lp] = hp;
1164 +#endif 1274 +#endif
1165 lval = sc; 1275 lval = sc;
1166 for (j=0; j < MAX_ROOTS; j++) 1276 for (j=0; j < MAX_ROOTS; j++)
1167 if (scores[j] < lval) { 1277 if (scores[j] < lval) {
1278 Index: src/hunspell/suggestmgr.hxx
1279 ===================================================================
1280 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.hxx,v
1281 retrieving revision 1.5
1282 diff -u -r1.5 suggestmgr.hxx
1283 --- src/hunspell/suggestmgr.hxx 21 Jan 2011 22:10:24 -0000 1.5
1284 +++ src/hunspell/suggestmgr.hxx 20 Dec 2012 23:40:03 -0000
1285 @@ -52,7 +52,11 @@
1286
1287
1288 public:
1289 +#ifdef HUNSPELL_CHROME_CLIENT
1290 + SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, Affix Mgr *aptr);
1291 +#else
1292 SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr);
1293 +#endif
1294 ~SuggestMgr();
1295
1296 int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug);
1297 @@ -66,6 +70,10 @@
1298 char * suggest_morph_for_spelling_error(const char * word);
1299
1300 private:
1301 +#ifdef HUNSPELL_CHROME_CLIENT
1302 + // Not owned by us, owned by the Hunspell object.
1303 + hunspell::BDictReader* bdict_reader;
1304 +#endif
1305 int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsugg est,
1306 int * timer, clock_t * timelimit);
1307 int checkword(const char *, int, int, int *, clock_t *);
OLDNEW
« no previous file with comments | « README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698