| OLD | NEW |
| 1 Index: src/hunspell/affixmgr.cxx | 1 diff --git a/third_party/hunspell/src/hunspell/affixmgr.cxx b/third_party/hunspe
ll/src/hunspell/affixmgr.cxx |
| 2 =================================================================== | 2 index cc9e69b..d31944e 100644 |
| 3 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.cxx,v | 3 --- a/third_party/hunspell/src/hunspell/affixmgr.cxx |
| 4 retrieving revision 1.41 | 4 +++ b/third_party/hunspell/src/hunspell/affixmgr.cxx |
| 5 diff -u -r1.41 affixmgr.cxx | 5 @@ -87,11 +87,19 @@ |
| 6 --- src/hunspell/affixmgr.cxx» 16 Dec 2011 09:15:34 -0000» 1.41 | |
| 7 +++ src/hunspell/affixmgr.cxx» 29 May 2014 01:05:07 -0000 | |
| 8 @@ -14,8 +14,14 @@ | |
| 9 | 6 |
| 10 #include "csutil.hxx" | 7 #include "csutil.hxx" |
| 11 | 8 |
| 12 +#ifdef HUNSPELL_CHROME_CLIENT | 9 +#ifdef HUNSPELL_CHROME_CLIENT |
| 13 +AffixMgr::AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md) | 10 +AffixMgr::AffixMgr(hunspell::BDictReader* reader, |
| 14 +{ | 11 + const std::vector<HashMgr*>& ptr) |
| 12 + : alldic(ptr) |
| 13 + , pHMgr(ptr[0]) { |
| 15 + bdict_reader = reader; | 14 + bdict_reader = reader; |
| 16 +#else | 15 +#else |
| 17 AffixMgr::AffixMgr(const char * affpath, HashMgr** ptr, int * md, const char *
key) | 16 AffixMgr::AffixMgr(const char* affpath, |
| 18 { | 17 const std::vector<HashMgr*>& ptr, |
| 18 const char* key) |
| 19 : alldic(ptr) |
| 20 , pHMgr(ptr[0]) { |
| 19 +#endif | 21 +#endif |
| 22 |
| 20 // register hash manager and load affix data from aff file | 23 // register hash manager and load affix data from aff file |
| 21 pHMgr = ptr[0]; | 24 csconv = NULL; |
| 22 alldic = ptr; | 25 @@ -166,9 +174,17 @@ AffixMgr::AffixMgr(const char* affpath, |
| 23 @@ -107,9 +113,17 @@ | 26 sFlag[i] = NULL; |
| 24 sFlag[i] = NULL; | |
| 25 } | 27 } |
| 26 | 28 |
| 27 +#ifdef HUNSPELL_CHROME_CLIENT | 29 +#ifdef HUNSPELL_CHROME_CLIENT |
| 28 + // Define dummy parameters for parse_file() to avoid changing the parameters | 30 + // 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 | 31 + // of parse_file(). This may make it easier to merge the changes of the |
| 30 + // original hunspell. | 32 + // original hunspell. |
| 31 + const char* affpath = NULL; | 33 + const char* affpath = NULL; |
| 32 + const char* key = NULL; | 34 + const char* key = NULL; |
| 33 +#else | 35 +#else |
| 34 for (int j=0; j < CONTSIZE; j++) { | 36 for (int j = 0; j < CONTSIZE; j++) { |
| 35 contclasses[j] = 0; | 37 contclasses[j] = 0; |
| 36 } | 38 } |
| 37 +#endif | 39 +#endif |
| 38 | 40 |
| 39 if (parse_file(affpath, key)) { | 41 if (parse_file(affpath, key)) { |
| 40 HUNSPELL_WARNING(stderr, "Failure loading aff file %s\n",affpath); | 42 HUNSPELL_WARNING(stderr, "Failure loading aff file %s\n", affpath); |
| 41 @@ -269,6 +283,43 @@ | 43 @@ -246,7 +262,44 @@ void AffixMgr::finishFileMgr(FileMgr* afflst) { |
| 42 char * line; // io buffers | 44 |
| 43 char ft; // affix type | 45 // read in aff file and build up prefix and suffix entry objects |
| 44 | 46 int AffixMgr::parse_file(const char* affpath, const char* key) { |
| 47 + std::string line; |
| 45 +#ifdef HUNSPELL_CHROME_CLIENT | 48 +#ifdef HUNSPELL_CHROME_CLIENT |
| 46 + // open the affix file | 49 + // open the affix file |
| 47 + // We're always UTF-8 | 50 + // We're always UTF-8 |
| 48 + utf8 = 1; | 51 + utf8 = 1; |
| 49 + | 52 + |
| 50 + // A BDICT file stores PFX and SFX lines in a special section and it provides | 53 + // 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. | 54 + // a special line iterator for reading PFX and SFX lines. |
| 52 + // We create a FileMgr object from this iterator and parse PFX and SFX lines | 55 + // We create a FileMgr object from this iterator and parse PFX and SFX lines |
| 53 + // before parsing other lines. | 56 + // before parsing other lines. |
| 54 + hunspell::LineIterator affix_iterator = bdict_reader->GetAffixLineIterator(); | 57 + hunspell::LineIterator affix_iterator = bdict_reader->GetAffixLineIterator(); |
| 55 + FileMgr* iterator = new FileMgr(&affix_iterator); | 58 + FileMgr* iterator = new FileMgr(&affix_iterator); |
| 56 + if (!iterator) { | 59 + if (!iterator) { |
| 57 + HUNSPELL_WARNING(stderr, | 60 + HUNSPELL_WARNING(stderr, |
| 58 + "error: could not create a FileMgr from an affix line iterator.\n"); | 61 + "error: could not create a FileMgr from an affix line iterator.\n"); |
| 59 + return 1; | 62 + return 1; |
| 60 + } | 63 + } |
| 61 + | 64 + |
| 62 + while ((line = iterator->getline())) { | 65 + while (iterator->getline(line)) { |
| 63 + ft = ' '; | 66 + char ft = ' '; |
| 64 + if (strncmp(line,"PFX",3) == 0) ft = complexprefixes ? 'S' : 'P'; | 67 + if (line.compare(0, 3, "PFX") == 0) ft = complexprefixes ? 'S' : 'P'; |
| 65 + if (strncmp(line,"SFX",3) == 0) ft = complexprefixes ? 'P' : 'S'; | 68 + if (line.compare(0, 3, "SFX") == 0) ft = complexprefixes ? 'P' : 'S'; |
| 66 + if (ft != ' ') | 69 + if (ft != ' ') |
| 67 + parse_affix(line, ft, iterator, NULL); | 70 + parse_affix(line, ft, iterator, NULL); |
| 68 + } | 71 + } |
| 69 + delete iterator; | 72 + delete iterator; |
| 70 + | 73 |
| 71 + // Create a FileMgr object for reading lines except PFX and SFX lines. | 74 + // Create a FileMgr object for reading lines except PFX and SFX lines. |
| 72 + // We don't need to change the loop below since our FileMgr emulates the | 75 + // We don't need to change the loop below since our FileMgr emulates the |
| 73 + // original one. | 76 + // original one. |
| 74 + hunspell::LineIterator other_iterator = bdict_reader->GetOtherLineIterator(); | 77 + hunspell::LineIterator other_iterator = bdict_reader->GetOtherLineIterator(); |
| 75 + FileMgr * afflst = new FileMgr(&other_iterator); | 78 + FileMgr * afflst = new FileMgr(&other_iterator); |
| 76 + if (!afflst) { | 79 + if (!afflst) { |
| 77 + HUNSPELL_WARNING(stderr, | 80 + HUNSPELL_WARNING(stderr, |
| 78 + "error: could not create a FileMgr from an other line iterator.\n"); | 81 + "error: could not create a FileMgr from an other line iterator.\n"); |
| 79 + return 1; | 82 + return 1; |
| 80 + } | 83 + } |
| 81 +#else | 84 +#else |
| 82 // checking flag duplication | 85 // checking flag duplication |
| 83 char dupflags[CONTSIZE]; | 86 char dupflags[CONTSIZE]; |
| 84 char dupflags_ini = 1; | 87 char dupflags_ini = 1; |
| 85 @@ -282,6 +333,7 @@ | 88 @@ -261,16 +314,17 @@ int AffixMgr::parse_file(const char* affpath, const char*
key) { |
| 86 HUNSPELL_WARNING(stderr, "error: could not open affix description file %s\n
",affpath); | 89 stderr, "error: could not open affix description file %s\n", affpath); |
| 87 return 1; | 90 return 1; |
| 88 } | 91 } |
| 89 +#endif | 92 +#endif |
| 90 | 93 |
| 91 // step one is to parse the affix file building up the internal | 94 // step one is to parse the affix file building up the internal |
| 92 // affix data structures | 95 // affix data structures |
| 93 @@ -291,6 +343,7 @@ | 96 |
| 94 while ((line = afflst->getline()) != NULL) { | 97 // read in each line ignoring any that do not |
| 95 mychomp(line); | 98 // start with a known line type indicator |
| 99 - std::string line; |
| 100 while (afflst->getline(line)) { |
| 101 mychomp(line); |
| 96 | 102 |
| 97 +#ifndef HUNSPELL_CHROME_CLIENT | 103 +#ifndef HUNSPELL_CHROME_CLIENT |
| 98 /* remove byte order mark */ | 104 /* remove byte order mark */ |
| 99 if (firstline) { | 105 if (firstline) { |
| 100 firstline = 0; | 106 firstline = 0; |
| 101 @@ -299,6 +352,7 @@ | 107 @@ -280,6 +334,7 @@ int AffixMgr::parse_file(const char* affpath, const char* ke
y) { |
| 102 memmove(line, line+3, strlen(line+3)+1); | 108 line.erase(0, 3); |
| 103 } | 109 } |
| 104 } | 110 } |
| 105 +#endif | 111 +#endif |
| 106 | 112 |
| 107 /* parse in the keyboard string */ | 113 /* parse in the keyboard string */ |
| 108 if (strncmp(line,"KEY",3) == 0) { | 114 if (line.compare(0, 3, "KEY", 3) == 0) { |
| 109 @@ -545,6 +599,7 @@ | 115 @@ -532,6 +587,7 @@ int AffixMgr::parse_file(const char* affpath, const char* ke
y) { |
| 110 } | 116 } |
| 111 } | 117 } |
| 112 | 118 |
| 113 +#ifndef HUNSPELL_CHROME_CLIENT | 119 +#ifndef HUNSPELL_CHROME_CLIENT |
| 114 /* parse in the typical fault correcting table */ | 120 /* parse in the typical fault correcting table */ |
| 115 if (strncmp(line,"REP",3) == 0) { | 121 if (line.compare(0, 3, "REP", 3) == 0) { |
| 116 if (parse_reptable(line, afflst)) { | 122 if (!parse_reptable(line, afflst)) { |
| 117 @@ -552,6 +607,7 @@ | 123 @@ -539,6 +595,7 @@ int AffixMgr::parse_file(const char* affpath, const char* ke
y) { |
| 118 return 1; | 124 return 1; |
| 119 } | 125 } |
| 120 } | 126 } |
| 121 +#endif | 127 +#endif |
| 122 | 128 |
| 123 /* parse in the input conversion table */ | 129 /* parse in the input conversion table */ |
| 124 if (strncmp(line,"ICONV",5) == 0) { | 130 if (line.compare(0, 5, "ICONV", 5) == 0) { |
| 125 @@ -699,6 +755,7 @@ | 131 @@ -688,6 +745,7 @@ int AffixMgr::parse_file(const char* affpath, const char* ke
y) { |
| 126 checksharps=1; | 132 checksharps = 1; |
| 127 } | 133 } |
| 128 | 134 |
| 129 +#ifndef HUNSPELL_CHROME_CLIENT | 135 +#ifndef HUNSPELL_CHROME_CLIENT |
| 130 /* parse this affix: P - prefix, S - suffix */ | 136 /* parse this affix: P - prefix, S - suffix */ |
| 131 ft = ' '; | 137 // affix type |
| 132 if (strncmp(line,"PFX",3) == 0) ft = complexprefixes ? 'S' : 'P'; | 138 char ft = ' '; |
| 133 @@ -713,6 +770,7 @@ | 139 @@ -705,6 +763,7 @@ int AffixMgr::parse_file(const char* affpath, const char* ke
y) { |
| 134 return 1; | 140 return 1; |
| 135 } | 141 } |
| 136 } | 142 } |
| 137 +#endif | 143 +#endif |
| 138 } | 144 } |
| 139 | 145 |
| 140 finishFileMgr(afflst); | 146 finishFileMgr(afflst); |
| 141 @@ -1307,6 +1365,26 @@ | 147 @@ -1281,6 +1340,24 @@ std::string AffixMgr::prefix_check_twosfx_morph(const cha
r* word, |
| 142 const char * r; | 148 // Is word a non compound with a REP substitution (see checkcompoundrep)? |
| 143 int lenr, lenp; | 149 int AffixMgr::cpdrep_check(const char* word, int wl) { |
| 144 | 150 |
| 145 +#ifdef HUNSPELL_CHROME_CLIENT | 151 +#ifdef HUNSPELL_CHROME_CLIENT |
| 146 + const char *pattern, *pattern2; | 152 + const char *pattern, *pattern2; |
| 147 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator
(); | 153 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator
(); |
| 148 + while (iterator.GetNext(&pattern, &pattern2)) { | 154 + while (iterator.GetNext(&pattern, &pattern2)) { |
| 149 + r = word; | 155 + const char* r = word; |
| 150 + lenr = strlen(pattern2); | 156 + const size_t lenr = strlen(pattern2); |
| 151 + lenp = strlen(pattern); | 157 + const size_t lenp = strlen(pattern); |
| 152 + | 158 + |
| 153 + // search every occurence of the pattern in the word | 159 + // search every occurence of the pattern in the word |
| 154 + while ((r=strstr(r, pattern)) != NULL) { | 160 + while ((r=strstr(r, pattern)) != NULL) { |
| 155 + strcpy(candidate, word); | 161 + std::string candidate(word); |
| 156 + if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break; | 162 + candidate.replace(r-word, lenp, pattern2); |
| 157 + strcpy(candidate+(r-word), pattern2); | 163 + if (candidate_check(candidate.c_str(), candidate.size())) return 1; |
| 158 + strcpy(candidate+(r-word)+lenr, r+lenp); | |
| 159 + if (candidate_check(candidate,strlen(candidate))) return 1; | |
| 160 + r++; // search for the next letter | 164 + r++; // search for the next letter |
| 161 + } | 165 + } |
| 162 + } | 166 + } |
| 163 + | 167 + |
| 164 +#else | 168 +#else |
| 165 if ((wl < 2) || !numrep) return 0; | 169 if ((wl < 2) || reptable.empty()) |
| 170 return 0; |
| 166 | 171 |
| 167 for (int i=0; i < numrep; i++ ) { | 172 @@ -1299,6 +1376,7 @@ int AffixMgr::cpdrep_check(const char* word, int wl) { |
| 168 @@ -1323,6 +1401,7 @@ | 173 ++r; // search for the next letter |
| 169 r++; // search for the next letter | 174 } |
| 175 } |
| 176 +#endif |
| 177 |
| 178 return 0; |
| 179 } |
| 180 @@ -4489,6 +4567,7 @@ bool AffixMgr::parse_affix(const std::string& line, |
| 181 case 1: { |
| 182 np++; |
| 183 aflag = pHMgr->decode_flag(std::string(start_piece, iter).c_str()); |
| 184 +#ifndef HUNSPELL_CHROME_CLIENT // We don't check for duplicates. |
| 185 if (((at == 'S') && (dupflags[aflag] & dupSFX)) || |
| 186 ((at == 'P') && (dupflags[aflag] & dupPFX))) { |
| 187 HUNSPELL_WARNING( |
| 188 @@ -4497,6 +4576,7 @@ bool AffixMgr::parse_affix(const std::string& line, |
| 189 af->getlinenum()); |
| 190 } |
| 191 dupflags[aflag] += (char)((at == 'S') ? dupSFX : dupPFX); |
| 192 +#endif |
| 193 break; |
| 170 } | 194 } |
| 171 } | 195 // piece 3 - is cross product indicator |
| 172 +#endif | 196 diff --git a/third_party/hunspell/src/hunspell/affixmgr.hxx b/third_party/hunspe
ll/src/hunspell/affixmgr.hxx |
| 173 return 0; | 197 index c7d5a63..55acd6a 100644 |
| 174 } | 198 --- a/third_party/hunspell/src/hunspell/affixmgr.hxx |
| 175 | 199 +++ b/third_party/hunspell/src/hunspell/affixmgr.hxx |
| 176 @@ -4219,6 +4298,7 @@ | 200 @@ -92,6 +92,40 @@ |
| 177 case 1: { | |
| 178 np++; | |
| 179 aflag = pHMgr->decode_flag(piece); | |
| 180 +#ifndef HUNSPELL_CHROME_CLIENT // We don't check for duplicates. | |
| 181 if (((at == 'S') && (dupflags[aflag] & dupSFX)) || | |
| 182 ((at == 'P') && (dupflags[aflag] & dupPFX))) { | |
| 183 HUNSPELL_WARNING(stderr, "error: line %d: multiple defi
nitions of an affix flag\n", | |
| 184 @@ -4226,6 +4306,7 @@ | |
| 185 // return 1; XXX permissive mode for bad dictionaries | |
| 186 } | |
| 187 dupflags[aflag] += (char) ((at == 'S') ? dupSFX : dupPFX); | |
| 188 +#endif | |
| 189 break; | |
| 190 } | |
| 191 // piece 3 - is cross product indicator | |
| 192 Index: src/hunspell/affixmgr.hxx | |
| 193 =================================================================== | |
| 194 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/affixmgr.hxx,v | |
| 195 retrieving revision 1.15 | |
| 196 diff -u -r1.15 affixmgr.hxx | |
| 197 --- src/hunspell/affixmgr.hxx» 13 Oct 2011 13:41:54 -0000» 1.15 | |
| 198 +++ src/hunspell/affixmgr.hxx» 29 May 2014 01:05:07 -0000 | |
| 199 @@ -18,6 +18,40 @@ | |
| 200 class PfxEntry; | 201 class PfxEntry; |
| 201 class SfxEntry; | 202 class SfxEntry; |
| 202 | 203 |
| 203 +#ifdef HUNSPELL_CHROME_CLIENT | 204 +#ifdef HUNSPELL_CHROME_CLIENT |
| 204 + | 205 + |
| 205 +#include <vector> | 206 +#include <vector> |
| 206 + | 207 + |
| 207 +// This class provides an implementation of the contclasses array in AffixMgr | 208 +// 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 | 209 +// that is normally a large static array. We should almost never need more than |
| 209 +// 256 elements, so this class only allocates that much to start off with. If | 210 +// 256 elements, so this class only allocates that much to start off with. If |
| (...skipping 17 matching lines...) Expand all Loading... |
| 227 + size_t old_size = data.size(); | 228 + size_t old_size = data.size(); |
| 228 + data.resize(new_size); | 229 + data.resize(new_size); |
| 229 + memset(&data[old_size], 0, new_size - old_size); | 230 + memset(&data[old_size], 0, new_size - old_size); |
| 230 + } | 231 + } |
| 231 + | 232 + |
| 232 + std::vector<char> data; | 233 + std::vector<char> data; |
| 233 +}; | 234 +}; |
| 234 + | 235 + |
| 235 +#endif // HUNSPELL_CHROME_CLIENT | 236 +#endif // HUNSPELL_CHROME_CLIENT |
| 236 + | 237 + |
| 237 class LIBHUNSPELL_DLL_EXPORTED AffixMgr | 238 class AffixMgr { |
| 238 { | 239 PfxEntry* pStart[SETSIZE]; |
| 240 SfxEntry* sStart[SETSIZE]; |
| 241 @@ -175,11 +209,19 @@ class AffixMgr { |
| 242 int fullstrip; |
| 239 | 243 |
| 240 @@ -106,12 +140,20 @@ | 244 int havecontclass; // boolean variable |
| 241 int fullstrip; | |
| 242 | |
| 243 int havecontclass; // boolean variable | |
| 244 +#ifdef HUNSPELL_CHROME_CLIENT | 245 +#ifdef HUNSPELL_CHROME_CLIENT |
| 245 + ContClasses contclasses; | 246 + ContClasses contclasses; |
| 246 +#else | 247 +#else |
| 247 char contclasses[CONTSIZE]; // flags of possible continuing cl
asses (twofold affix) | 248 char contclasses[CONTSIZE]; // flags of possible continuing classes (twofold |
| 249 // affix) |
| 248 +#endif | 250 +#endif |
| 249 | 251 |
| 250 public: | 252 public: |
| 251 | |
| 252 +#ifdef HUNSPELL_CHROME_CLIENT | 253 +#ifdef HUNSPELL_CHROME_CLIENT |
| 253 + AffixMgr(hunspell::BDictReader* reader, HashMgr** ptr, int * md); | 254 + AffixMgr(hunspell::BDictReader* reader, const std::vector<HashMgr*>& ptr); |
| 254 +#else | 255 +#else |
| 255 AffixMgr(const char * affpath, HashMgr** ptr, int * md, | 256 AffixMgr(const char* affpath, const std::vector<HashMgr*>& ptr, const char* k
ey = 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, |
| 260 const unsigned short needflag = (unsigned short) 0, | 260 int len, |
| 261 @@ -218,6 +260,10 @@ | 261 @@ -337,6 +379,10 @@ class AffixMgr { |
| 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 bool parse_flag(const std::string& line, unsigned short* out, FileMgr* af); |
| 271 int parse_num(char * line, int * out, FileMgr * af); | 271 bool parse_num(const std::string& line, int* out, FileMgr* af); |
| 272 @@ -249,4 +295,3 @@ | 272 diff --git a/third_party/hunspell/src/hunspell/filemgr.cxx b/third_party/hunspel
l/src/hunspell/filemgr.cxx |
| 273 }; | 273 index b7c89b2..aef6dba 100644 |
| 274 | 274 --- a/third_party/hunspell/src/hunspell/filemgr.cxx |
| 275 #endif | 275 +++ b/third_party/hunspell/src/hunspell/filemgr.cxx |
| 276 - | 276 @@ -78,6 +78,32 @@ |
| 277 Index: src/hunspell/filemgr.cxx | |
| 278 =================================================================== | |
| 279 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.cxx,v | |
| 280 retrieving revision 1.5 | |
| 281 diff -u -r1.5 filemgr.cxx | |
| 282 --- src/hunspell/filemgr.cxx» 23 Jun 2011 09:21:50 -0000» 1.5 | |
| 283 +++ src/hunspell/filemgr.cxx» 29 May 2014 01:05:07 -0000 | |
| 284 @@ -7,6 +7,32 @@ | |
| 285 | |
| 286 #include "filemgr.hxx" | 277 #include "filemgr.hxx" |
| 278 #include "csutil.hxx" |
| 287 | 279 |
| 288 +#ifdef HUNSPELL_CHROME_CLIENT | 280 +#ifdef HUNSPELL_CHROME_CLIENT |
| 289 +#include "third_party/hunspell/google/bdict_reader.h" | 281 +#include "third_party/hunspell/google/bdict_reader.h" |
| 290 + | 282 + |
| 291 +FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { | 283 +FileMgr::FileMgr(hunspell::LineIterator* iterator) : iterator_(iterator) { |
| 292 +} | 284 +} |
| 293 + | 285 + |
| 294 +FileMgr::~FileMgr() { | 286 +FileMgr::~FileMgr() { |
| 295 +} | 287 +} |
| 296 + | 288 + |
| 297 +char * FileMgr::getline() { | 289 +bool FileMgr::getline(std::string& line) { |
| 298 + // Read one line from a BDICT file and store the line to our line buffer. | 290 + // Read one line from a BDICT file and return it, if we can read a line |
| 299 + // To emulate the original FileMgr::getline(), this function returns | 291 + // without errors. |
| 300 + // the pointer to our line buffer if we can read a line without errors. | |
| 301 + // Otherwise, this function returns NULL. | |
| 302 + bool result = iterator_->AdvanceAndCopy(line_, BUFSIZE - 1); | 292 + bool result = iterator_->AdvanceAndCopy(line_, BUFSIZE - 1); |
| 303 + return result ? line_ : NULL; | 293 + if (result) |
| 294 + line = line_; |
| 295 + return result; |
| 304 +} | 296 +} |
| 305 + | 297 + |
| 306 +int FileMgr::getlinenum() { | 298 +int FileMgr::getlinenum() { |
| 307 + // This function is used only for displaying a line number that causes a | 299 + // 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 | 300 + // 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 | 301 + // identifying the place where causes a parser error so much since it is a |
| 310 + // binary file. So, we just return 0. | 302 + // binary file. So, we just return 0. |
| 311 + return 0; | 303 + return 0; |
| 312 +} | 304 +} |
| 313 +#else | 305 +#else |
| 314 int FileMgr::fail(const char * err, const char * par) { | 306 int FileMgr::fail(const char* err, const char* par) { |
| 315 fprintf(stderr, err, par); | 307 fprintf(stderr, err, par); |
| 316 return -1; | 308 return -1; |
| 317 @@ -47,3 +73,4 @@ | 309 @@ -118,3 +144,4 @@ bool FileMgr::getline(std::string& dest) { |
| 318 int FileMgr::getlinenum() { | 310 int FileMgr::getlinenum() { |
| 319 return linenum; | 311 return linenum; |
| 320 } | 312 } |
| 321 +#endif | 313 +#endif |
| 322 Index: src/hunspell/filemgr.hxx | 314 diff --git a/third_party/hunspell/src/hunspell/filemgr.hxx b/third_party/hunspel
l/src/hunspell/filemgr.hxx |
| 323 =================================================================== | 315 index ca51faf..daa6d0b 100644 |
| 324 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/filemgr.hxx,v | 316 --- a/third_party/hunspell/src/hunspell/filemgr.hxx |
| 325 retrieving revision 1.3 | 317 +++ b/third_party/hunspell/src/hunspell/filemgr.hxx |
| 326 diff -u -r1.3 filemgr.hxx | 318 @@ -80,6 +80,30 @@ |
| 327 --- src/hunspell/filemgr.hxx» 15 Apr 2010 11:22:08 -0000» 1.3 | 319 #include <string> |
| 328 +++ src/hunspell/filemgr.hxx» 29 May 2014 01:05:07 -0000 | 320 #include <fstream> |
| 329 @@ -7,6 +7,30 @@ | |
| 330 #include "hunzip.hxx" | |
| 331 #include <stdio.h> | |
| 332 | 321 |
| 333 +#ifdef HUNSPELL_CHROME_CLIENT | 322 +#ifdef HUNSPELL_CHROME_CLIENT |
| 334 +namespace hunspell { | 323 +namespace hunspell { |
| 335 +class LineIterator; | 324 +class LineIterator; |
| 336 +} // namespace hunspell | 325 +} // namespace hunspell |
| 337 + | 326 + |
| 338 +// A class which encapsulates operations of reading a BDICT file. | 327 +// A class which encapsulates operations of reading a BDICT file. |
| 339 +// Chrome uses a BDICT file to compress hunspell dictionaries. A BDICT file is | 328 +// Chrome uses a BDICT file to compress hunspell dictionaries. A BDICT file is |
| 340 +// a binary file converted from a DIC file and an AFF file. (See | 329 +// a binary file converted from a DIC file and an AFF file. (See |
| 341 +// "bdict_reader.h" for its format.) | 330 +// "bdict_reader.h" for its format.) |
| 342 +// This class encapsulates the operations of reading a BDICT file and emulates | 331 +// This class encapsulates the operations of reading a BDICT file and emulates |
| 343 +// the original FileMgr operations for AffixMgr so that it can read a BDICT | 332 +// the original FileMgr operations for AffixMgr so that it can read a BDICT |
| 344 +// file without so many changes. | 333 +// file without so many changes. |
| 345 +class FileMgr { | 334 +class FileMgr { |
| 346 + public: | 335 + public: |
| 347 + FileMgr(hunspell::LineIterator* iterator); | 336 + FileMgr(hunspell::LineIterator* iterator); |
| 348 + ~FileMgr(); | 337 + ~FileMgr(); |
| 349 + char* getline(); | 338 + bool getline(std::string& line); |
| 350 + int getlinenum(); | 339 + int getlinenum(); |
| 351 + | 340 + |
| 352 + protected: | 341 + protected: |
| 353 + hunspell::LineIterator* iterator_; | 342 + hunspell::LineIterator* iterator_; |
| 354 + char line_[BUFSIZE + 50]; // input buffer | 343 + char line_[BUFSIZE + 50]; // input buffer |
| 355 +}; | 344 +}; |
| 356 +#else | 345 +#else |
| 357 class LIBHUNSPELL_DLL_EXPORTED FileMgr | 346 class FileMgr { |
| 358 { | 347 private: |
| 359 protected: | 348 FileMgr(const FileMgr&); |
| 360 @@ -23,3 +47,4 @@ | 349 @@ -99,3 +123,4 @@ class FileMgr { |
| 361 int getlinenum(); | 350 int getlinenum(); |
| 362 }; | 351 }; |
| 363 #endif | 352 #endif |
| 364 +#endif | 353 +#endif |
| 365 Index: src/hunspell/hashmgr.cxx | 354 diff --git a/third_party/hunspell/src/hunspell/hashmgr.cxx b/third_party/hunspel
l/src/hunspell/hashmgr.cxx |
| 366 =================================================================== | 355 index 072bc1a..b07c585 100644 |
| 367 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.cxx,v | 356 --- a/third_party/hunspell/src/hunspell/hashmgr.cxx |
| 368 retrieving revision 1.12 | 357 +++ b/third_party/hunspell/src/hunspell/hashmgr.cxx |
| 369 diff -u -r1.12 hashmgr.cxx | 358 @@ -84,8 +84,14 @@ |
| 370 --- src/hunspell/hashmgr.cxx» 23 Jun 2011 09:21:50 -0000» 1.12 | |
| 371 +++ src/hunspell/hashmgr.cxx» 29 May 2014 01:05:07 -0000 | |
| 372 @@ -12,8 +12,14 @@ | |
| 373 | 359 |
| 374 // build a hash table from a munched word list | 360 // build a hash table from a munched word list |
| 375 | 361 |
| 376 +#ifdef HUNSPELL_CHROME_CLIENT | 362 +#ifdef HUNSPELL_CHROME_CLIENT |
| 377 +HashMgr::HashMgr(hunspell::BDictReader* reader) | 363 +HashMgr::HashMgr(hunspell::BDictReader* reader) |
| 378 +{ | 364 + : bdict_reader(reader), |
| 379 + bdict_reader = reader; | |
| 380 +#else | 365 +#else |
| 381 HashMgr::HashMgr(const char * tpath, const char * apath, const char * key) | 366 HashMgr::HashMgr(const char* tpath, const char* apath, const char* key) |
| 382 { | 367 - : tablesize(0), |
| 368 + : |
| 383 +#endif | 369 +#endif |
| 384 tablesize = 0; | 370 + tablesize(0), |
| 385 tableptr = NULL; | 371 tableptr(NULL), |
| 386 flag_mode = FLAG_CHAR; | 372 flag_mode(FLAG_CHAR), |
| 387 @@ -31,8 +37,14 @@ | 373 complexprefixes(0), |
| 388 numaliasm = 0; | 374 @@ -99,8 +105,14 @@ HashMgr::HashMgr(const char* tpath, const char* apath, const
char* key) |
| 389 aliasm = NULL; | 375 aliasm(NULL) { |
| 390 forbiddenword = FORBIDDENWORD; // forbidden word signing flag | 376 langnum = 0; |
| 377 csconv = 0; |
| 391 +#ifdef HUNSPELL_CHROME_CLIENT | 378 +#ifdef HUNSPELL_CHROME_CLIENT |
| 392 + // No tables to load, just the AF lines. | 379 + // No tables to load, just the AF lines. |
| 393 + load_config(NULL, NULL); | 380 + load_config(NULL, NULL); |
| 394 + int ec = LoadAFLines(); | 381 + int ec = LoadAFLines(); |
| 395 +#else | 382 +#else |
| 396 load_config(apath, key); | 383 load_config(apath, key); |
| 397 int ec = load_tables(tpath, key); | 384 int ec = load_tables(tpath, key); |
| 398 +#endif | 385 +#endif |
| 399 if (ec) { | 386 if (ec) { |
| 400 /* error condition - what should we do here */ | 387 /* error condition - what should we do here */ |
| 401 HUNSPELL_WARNING(stderr, "Hash Manager Error : %d\n",ec); | 388 HUNSPELL_WARNING(stderr, "Hash Manager Error : %d\n", ec); |
| 402 @@ -91,15 +103,58 @@ | 389 @@ -156,14 +168,57 @@ HashMgr::~HashMgr() { |
| 403 if (ignorechars) free(ignorechars); | 390 #endif |
| 404 if (ignorechars_utf16) free(ignorechars_utf16); | 391 #endif |
| 405 | 392 |
| 406 +#ifdef HUNSPELL_CHROME_CLIENT | 393 +#ifdef HUNSPELL_CHROME_CLIENT |
| 407 + EmptyHentryCache(); | 394 + EmptyHentryCache(); |
| 408 + for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin(); | 395 + for (std::vector<std::string*>::iterator it = pointer_to_strings_.begin(); |
| 409 + it != pointer_to_strings_.end(); ++it) { | 396 + it != pointer_to_strings_.end(); ++it) { |
| 410 + delete *it; | 397 + delete *it; |
| 411 + } | 398 + } |
| 412 +#endif | 399 +#endif |
| 413 #ifdef MOZILLA_CLIENT | 400 #ifdef MOZILLA_CLIENT |
| 414 delete [] csconv; | 401 delete[] csconv; |
| 415 #endif | 402 #endif |
| 416 } | 403 } |
| 417 | 404 |
| 418 +#ifdef HUNSPELL_CHROME_CLIENT | 405 +#ifdef HUNSPELL_CHROME_CLIENT |
| 419 +void HashMgr::EmptyHentryCache() { | 406 +void HashMgr::EmptyHentryCache() { |
| 420 + // We need to delete each cache entry, and each additional one in the linked | 407 + // We need to delete each cache entry, and each additional one in the linked |
| 421 + // list of homonyms. | 408 + // list of homonyms. |
| 422 + for (HEntryCache::iterator i = hentry_cache.begin(); | 409 + for (HEntryCache::iterator i = hentry_cache.begin(); |
| 423 + i != hentry_cache.end(); ++i) { | 410 + i != hentry_cache.end(); ++i) { |
| 424 + hentry* cur = i->second; | 411 + hentry* cur = i->second; |
| 425 + while (cur) { | 412 + while (cur) { |
| 426 + hentry* next = cur->next_homonym; | 413 + hentry* next = cur->next_homonym; |
| 427 + DeleteHashEntry(cur); | 414 + DeleteHashEntry(cur); |
| 428 + cur = next; | 415 + cur = next; |
| 429 + } | 416 + } |
| 430 + } | 417 + } |
| 431 + hentry_cache.clear(); | 418 + hentry_cache.clear(); |
| 432 +} | 419 +} |
| 433 +#endif | 420 +#endif |
| 434 + | 421 + |
| 435 // lookup a root word in the hashtable | 422 // lookup a root word in the hashtable |
| 436 | 423 |
| 437 struct hentry * HashMgr::lookup(const char *word) const | 424 struct hentry* HashMgr::lookup(const char* word) const { |
| 438 { | |
| 439 +#ifdef HUNSPELL_CHROME_CLIENT | 425 +#ifdef HUNSPELL_CHROME_CLIENT |
| 440 + int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD]; | 426 + int affix_ids[hunspell::BDict::MAX_AFFIXES_PER_WORD]; |
| 441 + int affix_count = bdict_reader->FindWord(word, affix_ids); | 427 + int affix_count = bdict_reader->FindWord(word, affix_ids); |
| 442 + if (affix_count == 0) { // look for custom added word | 428 + if (affix_count == 0) { // look for custom added word |
| 443 + std::map<base::StringPiece, int>::const_iterator iter = | 429 + std::map<base::StringPiece, int>::const_iterator iter = |
| 444 + custom_word_to_affix_id_map_.find(word); | 430 + custom_word_to_affix_id_map_.find(word); |
| 445 + if (iter != custom_word_to_affix_id_map_.end()) { | 431 + if (iter != custom_word_to_affix_id_map_.end()) { |
| 446 + affix_count = 1; | 432 + affix_count = 1; |
| 447 + affix_ids[0] = iter->second; | 433 + affix_ids[0] = iter->second; |
| 448 + } | 434 + } |
| 449 + } | 435 + } |
| 450 + | 436 + |
| 451 + static const int kMaxWordLen = 128; | 437 + static const int kMaxWordLen = 128; |
| 452 + static char word_buf[kMaxWordLen]; | 438 + static char word_buf[kMaxWordLen]; |
| 453 + // To take account of null-termination, we use upto 127. | 439 + // To take account of null-termination, we use upto 127. |
| 454 + strncpy(word_buf, word, kMaxWordLen - 1); | 440 + strncpy(word_buf, word, kMaxWordLen - 1); |
| 455 + | 441 + |
| 456 + return AffixIDsToHentry(word_buf, affix_ids, affix_count); | 442 + return AffixIDsToHentry(word_buf, affix_ids, affix_count); |
| 457 +#else | 443 +#else |
| 458 struct hentry * dp; | 444 struct hentry* dp; |
| 459 if (tableptr) { | 445 if (tableptr) { |
| 460 dp = tableptr[hash(word)]; | 446 dp = tableptr[hash(word)]; |
| 461 @@ -109,12 +164,14 @@ | 447 @@ -175,6 +230,7 @@ struct hentry* HashMgr::lookup(const char* word) const { |
| 462 } | |
| 463 } | 448 } |
| 464 return NULL; | 449 } |
| 450 return NULL; |
| 465 +#endif | 451 +#endif |
| 466 } | 452 } |
| 467 | 453 |
| 468 // add a word to the hash table (private) | 454 // add a word to the hash table (private) |
| 469 int HashMgr::add_word(const char * word, int wbl, int wcl, unsigned short * aff
, | 455 @@ -184,6 +240,8 @@ int HashMgr::add_word(const std::string& in_word, |
| 470 int al, const char * desc, bool onlyupcase) | 456 int al, |
| 471 { | 457 const std::string* in_desc, |
| 458 bool onlyupcase) { |
| 459 +// TODO: The following 40 lines or so are actually new. Should they be included
? |
| 472 +#ifndef HUNSPELL_CHROME_CLIENT | 460 +#ifndef HUNSPELL_CHROME_CLIENT |
| 473 bool upcasehomonym = false; | 461 const std::string* word = &in_word; |
| 474 int descl = desc ? (aliasm ? sizeof(short) : strlen(desc) + 1) : 0; | 462 const std::string* desc = in_desc; |
| 475 // variable-length hash record with word and optional fields | 463 |
| 476 @@ -206,6 +263,17 @@ | 464 @@ -316,6 +374,17 @@ int HashMgr::add_word(const std::string& in_word, |
| 477 » if (hp->astr) free(hp->astr); | 465 |
| 478 » free(hp); | 466 delete desc_copy; |
| 479 } | 467 delete word_copy; |
| 480 +#else | 468 +#else |
| 481 + std::map<base::StringPiece, int>::iterator iter = | 469 + std::map<base::StringPiece, int>::iterator iter = |
| 482 + custom_word_to_affix_id_map_.find(word); | 470 + custom_word_to_affix_id_map_.find(in_word); |
| 483 + if(iter == custom_word_to_affix_id_map_.end()) { // word needs to be added | 471 + if (iter == custom_word_to_affix_id_map_.end()) { // word needs to be added |
| 484 + std::string* new_string_word = new std::string(word); | 472 + std::string* new_string_word = new std::string(in_word); |
| 485 + pointer_to_strings_.push_back(new_string_word); | 473 + pointer_to_strings_.push_back(new_string_word); |
| 486 + base::StringPiece sp(*(new_string_word)); | 474 + base::StringPiece sp(*(new_string_word)); |
| 487 + custom_word_to_affix_id_map_[sp] = 0; // no affixes for custom words | 475 + custom_word_to_affix_id_map_[sp] = 0; // no affixes for custom words |
| 488 + return 1; | 476 + return 1; |
| 489 + } | 477 + } |
| 490 +#endif | 478 +#endif |
| 491 return 0; | 479 return 0; |
| 492 } | |
| 493 | |
| 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 } | 480 } |
| 514 | 481 |
| 515 @@ -339,6 +414,44 @@ | 482 @@ -376,6 +445,12 @@ int HashMgr::get_clen_and_captype(const std::string& word,
int* captype) { |
| 483 |
| 484 // remove word (personal dictionary function for standalone applications) |
| 485 int HashMgr::remove(const std::string& word) { |
| 486 +#ifdef HUNSPELL_CHROME_CLIENT |
| 487 + std::map<base::StringPiece, int>::iterator iter = |
| 488 + custom_word_to_affix_id_map_.find(word); |
| 489 + if (iter != custom_word_to_affix_id_map_.end()) |
| 490 + custom_word_to_affix_id_map_.erase(iter); |
| 491 +#else |
| 492 struct hentry* dp = lookup(word.c_str()); |
| 493 while (dp) { |
| 494 if (dp->alen == 0 || !TESTAFF(dp->astr, forbiddenword, dp->alen)) { |
| 495 @@ -392,6 +467,7 @@ int HashMgr::remove(const std::string& word) { |
| 496 } |
| 497 dp = dp->next_homonym; |
| 498 } |
| 499 +#endif |
| 500 return 0; |
| 501 } |
| 502 |
| 503 @@ -465,6 +541,44 @@ int HashMgr::add_with_affix(const std::string& word, const
std::string& example) |
| 504 // walk the hash table entry by entry - null at end |
| 516 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp); | 505 // initialize: col=-1; hp = NULL; hp = walk_hashtable(&col, hp); |
| 517 struct hentry * HashMgr::walk_hashtable(int &col, struct hentry * hp) const | 506 struct hentry* HashMgr::walk_hashtable(int& col, struct hentry* hp) const { |
| 518 { | |
| 519 +#ifdef HUNSPELL_CHROME_CLIENT | 507 +#ifdef HUNSPELL_CHROME_CLIENT |
| 520 + // Return NULL if dictionary is not valid. | 508 + // Return NULL if dictionary is not valid. |
| 521 + if (!bdict_reader->IsValid()) | 509 + if (!bdict_reader->IsValid()) |
| 522 + return NULL; | 510 + return NULL; |
| 523 + | 511 + |
| 524 + // This function is only ever called by one place and not nested. We can | 512 + // 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 | 513 + // therefore keep static state between calls and use |col| as a "reset" flag |
| 526 + // to avoid changing the API. It is set to -1 for the first call. | 514 + // to avoid changing the API. It is set to -1 for the first call. |
| 527 + // Allocate the iterator on the heap to prevent an exit time destructor. | 515 + // Allocate the iterator on the heap to prevent an exit time destructor. |
| 528 + static hunspell::WordIterator& word_iterator = | 516 + static hunspell::WordIterator& word_iterator = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 547 + // the static struct and return it for now. | 535 + // the static struct and return it for now. |
| 548 + // No need to create linked lists for the extra affixes. | 536 + // No need to create linked lists for the extra affixes. |
| 549 + static struct { | 537 + static struct { |
| 550 + hentry entry; | 538 + hentry entry; |
| 551 + char word[kMaxWordLen]; | 539 + char word[kMaxWordLen]; |
| 552 + } hash_entry; | 540 + } hash_entry; |
| 553 + | 541 + |
| 554 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry), | 542 + return InitHashEntry(&hash_entry.entry, sizeof(hash_entry), |
| 555 + &word[0], word_len, affix_ids[0]); | 543 + &word[0], word_len, affix_ids[0]); |
| 556 +#else | 544 +#else |
| 557 if (hp && hp->next != NULL) return hp->next; | 545 if (hp && hp->next != NULL) |
| 546 return hp->next; |
| 558 for (col++; col < tablesize; col++) { | 547 for (col++; col < tablesize; col++) { |
| 559 if (tableptr[col]) return tableptr[col]; | 548 @@ -474,10 +588,12 @@ struct hentry* HashMgr::walk_hashtable(int& col, struct he
ntry* hp) const { |
| 560 @@ -346,11 +459,13 @@ | |
| 561 // null at end and reset to start | 549 // null at end and reset to start |
| 562 col = -1; | 550 col = -1; |
| 563 return NULL; | 551 return NULL; |
| 564 +#endif | 552 +#endif |
| 565 } | 553 } |
| 566 | 554 |
| 567 // load a munched word list and build a hash table on the fly | 555 // load a munched word list and build a hash table on the fly |
| 568 int HashMgr::load_tables(const char * tpath, const char * key) | 556 int HashMgr::load_tables(const char* tpath, const char* key) { |
| 569 { | |
| 570 +#ifndef HUNSPELL_CHROME_CLIENT | 557 +#ifndef HUNSPELL_CHROME_CLIENT |
| 571 int al; | 558 // open dictionary file |
| 572 char * ap; | 559 FileMgr* dict = new FileMgr(tpath, key); |
| 573 char * dp; | 560 if (dict == NULL) |
| 574 @@ -471,6 +586,7 @@ | 561 @@ -606,12 +722,16 @@ int HashMgr::load_tables(const char* tpath, const char* ke
y) { |
| 575 } | 562 } |
| 576 | 563 |
| 577 delete dict; | 564 delete dict; |
| 578 +#endif | 565 +#endif |
| 579 return 0; | 566 return 0; |
| 580 } | 567 } |
| 581 | 568 |
| 582 @@ -479,6 +595,9 @@ | 569 // the hash function is a simple load and rotate |
| 583 | 570 // algorithm borrowed |
| 584 int HashMgr::hash(const char * word) const | 571 int HashMgr::hash(const char* word) const { |
| 585 { | |
| 586 +#ifdef HUNSPELL_CHROME_CLIENT | 572 +#ifdef HUNSPELL_CHROME_CLIENT |
| 587 + return 0; | 573 + return 0; |
| 588 +#else | 574 +#else |
| 589 long hv = 0; | 575 unsigned long hv = 0; |
| 590 for (int i=0; i < 4 && *word != 0; i++) | 576 for (int i = 0; i < 4 && *word != 0; i++) |
| 591 hv = (hv << 8) | (*word++); | 577 hv = (hv << 8) | (*word++); |
| 592 @@ -487,6 +606,7 @@ | 578 @@ -620,6 +740,7 @@ int HashMgr::hash(const char* word) const { |
| 593 hv ^= (*word++); | 579 hv ^= (*word++); |
| 594 } | 580 } |
| 595 return (unsigned long) hv % tablesize; | 581 return (unsigned long)hv % tablesize; |
| 596 +#endif | 582 +#endif |
| 597 } | 583 } |
| 598 | 584 |
| 599 int HashMgr::decode_flags(unsigned short ** result, char * flags, FileMgr * af)
{ | 585 int HashMgr::decode_flags(unsigned short** result, const std::string& flags, Fi
leMgr* af) const { |
| 600 @@ -607,7 +727,12 @@ | 586 @@ -829,7 +950,12 @@ int HashMgr::load_config(const char* affpath, const char* k
ey) { |
| 601 int firstline = 1; | 587 int firstline = 1; |
| 602 | 588 |
| 603 // open the affix file | 589 // open the affix file |
| 604 +#ifdef HUNSPELL_CHROME_CLIENT | 590 +#ifdef HUNSPELL_CHROME_CLIENT |
| 605 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator(); | 591 + hunspell::LineIterator iterator = bdict_reader->GetOtherLineIterator(); |
| 606 + FileMgr * afflst = new FileMgr(&iterator); | 592 + FileMgr * afflst = new FileMgr(&iterator); |
| 607 +#else | 593 +#else |
| 608 FileMgr * afflst = new FileMgr(affpath, key); | 594 FileMgr* afflst = new FileMgr(affpath, key); |
| 609 +#endif | 595 +#endif |
| 610 if (!afflst) { | 596 if (!afflst) { |
| 611 HUNSPELL_WARNING(stderr, "Error - could not open affix description file %s\
n",affpath); | 597 HUNSPELL_WARNING( |
| 612 return 1; | 598 stderr, "Error - could not open affix description file %s\n", affpath); |
| 613 @@ -802,6 +927,121 @@ | 599 @@ -1058,6 +1184,122 @@ bool HashMgr::parse_aliasf(const std::string& line, File
Mgr* af) { |
| 614 return 0; | 600 return true; |
| 615 } | 601 } |
| 616 | 602 |
| 617 +#ifdef HUNSPELL_CHROME_CLIENT | 603 +#ifdef HUNSPELL_CHROME_CLIENT |
| 618 +int HashMgr::LoadAFLines() | 604 +int HashMgr::LoadAFLines() |
| 619 +{ | 605 +{ |
| 620 + utf8 = 1; // We always use UTF-8. | 606 + utf8 = 1; // We always use UTF-8. |
| 621 + | 607 + |
| 622 + // Read in all the AF lines which tell us the rules for each affix group ID. | 608 + // Read in all the AF lines which tell us the rules for each affix group ID. |
| 623 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator(); | 609 + hunspell::LineIterator iterator = bdict_reader->GetAfLineIterator(); |
| 624 + FileMgr afflst(&iterator); | 610 + FileMgr afflst(&iterator); |
| 625 + while (char* line = afflst.getline()) { | 611 + std::string line; |
| 612 + while (afflst.getline(line)) { |
| 626 + int rv = parse_aliasf(line, &afflst); | 613 + int rv = parse_aliasf(line, &afflst); |
| 627 + if (rv) | 614 + if (rv) |
| 628 + return rv; | 615 + return rv; |
| 629 + } | 616 + } |
| 630 + | 617 + |
| 631 + return 0; | 618 + return 0; |
| 632 +} | 619 +} |
| 633 + | 620 + |
| 634 +hentry* HashMgr::InitHashEntry(hentry* entry, | 621 +hentry* HashMgr::InitHashEntry(hentry* entry, |
| 635 + size_t item_size, | 622 + size_t item_size, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 + HEntryCache& cache = const_cast<HashMgr*>(this)->hentry_cache; | 709 + HEntryCache& cache = const_cast<HashMgr*>(this)->hentry_cache; |
| 723 + std::string std_word(word); | 710 + std::string std_word(word); |
| 724 + HEntryCache::iterator found = cache.find(std_word); | 711 + HEntryCache::iterator found = cache.find(std_word); |
| 725 + if (found != cache.end()) | 712 + if (found != cache.end()) |
| 726 + return found->second; | 713 + return found->second; |
| 727 + else | 714 + else |
| 728 + return NULL; | 715 + return NULL; |
| 729 +} | 716 +} |
| 730 +#endif | 717 +#endif |
| 731 + | 718 + |
| 732 int HashMgr::is_aliasf() { | 719 int HashMgr::is_aliasf() const { |
| 733 return (aliasf != NULL); | 720 return (aliasf != NULL); |
| 734 } | 721 } |
| 735 Index: src/hunspell/hashmgr.hxx | 722 diff --git a/third_party/hunspell/src/hunspell/hashmgr.hxx b/third_party/hunspel
l/src/hunspell/hashmgr.hxx |
| 736 =================================================================== | 723 index a158a16..9714a90 100644 |
| 737 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hashmgr.hxx,v | 724 --- a/third_party/hunspell/src/hunspell/hashmgr.hxx |
| 738 retrieving revision 1.3 | 725 +++ b/third_party/hunspell/src/hunspell/hashmgr.hxx |
| 739 diff -u -r1.3 hashmgr.hxx | 726 @@ -82,9 +82,23 @@ |
| 740 --- src/hunspell/hashmgr.hxx» 15 Apr 2010 11:22:08 -0000» 1.3 | |
| 741 +++ src/hunspell/hashmgr.hxx» 29 May 2014 01:05:07 -0000 | |
| 742 @@ -8,10 +8,25 @@ | |
| 743 #include "htypes.hxx" | |
| 744 #include "filemgr.hxx" | 727 #include "filemgr.hxx" |
| 728 #include "w_char.hxx" |
| 745 | 729 |
| 746 +#ifdef HUNSPELL_CHROME_CLIENT | 730 +#ifdef HUNSPELL_CHROME_CLIENT |
| 747 +#include <string> | |
| 748 +#include <map> | 731 +#include <map> |
| 749 + | 732 + |
| 750 +#include "base/stl_util.h" | 733 +#include "base/stl_util.h" |
| 751 +#include "base/strings/string_piece.h" | 734 +#include "base/strings/string_piece.h" |
| 752 +#include "third_party/hunspell/google/bdict_reader.h" | 735 +#include "third_party/hunspell/google/bdict_reader.h" |
| 753 +#endif | 736 +#endif |
| 754 + | 737 + |
| 755 enum flag { FLAG_CHAR, FLAG_LONG, FLAG_NUM, FLAG_UNI }; | 738 enum flag { FLAG_CHAR, FLAG_LONG, FLAG_NUM, FLAG_UNI }; |
| 756 | 739 |
| 757 class LIBHUNSPELL_DLL_EXPORTED HashMgr | 740 class HashMgr { |
| 758 { | |
| 759 +#ifdef HUNSPELL_CHROME_CLIENT | 741 +#ifdef HUNSPELL_CHROME_CLIENT |
| 760 + // Not owned by this class, owned by the Hunspell object. | 742 + // Not owned by this class, owned by the Hunspell object. |
| 761 + hunspell::BDictReader* bdict_reader; | 743 + hunspell::BDictReader* bdict_reader; |
| 762 + std::map<base::StringPiece, int> custom_word_to_affix_id_map_; | 744 + std::map<base::StringPiece, int> custom_word_to_affix_id_map_; |
| 763 + std::vector<std::string*> pointer_to_strings_; | 745 + std::vector<std::string*> pointer_to_strings_; |
| 764 +#endif | 746 +#endif |
| 765 int tablesize; | 747 int tablesize; |
| 766 struct hentry ** tableptr; | 748 struct hentry** tableptr; |
| 767 int userword; | 749 flag flag_mode; |
| 768 @@ -34,7 +49,23 @@ | 750 @@ -104,7 +118,23 @@ class HashMgr { |
| 751 char** aliasm; |
| 769 | 752 |
| 770 | 753 public: |
| 771 public: | |
| 772 +#ifdef HUNSPELL_CHROME_CLIENT | 754 +#ifdef HUNSPELL_CHROME_CLIENT |
| 773 + HashMgr(hunspell::BDictReader* reader); | 755 + HashMgr(hunspell::BDictReader* reader); |
| 774 + | 756 + |
| 775 + // Return the hentry corresponding to the given word. Returns NULL if the | 757 + // Return the hentry corresponding to the given word. Returns NULL if the |
| 776 + // word is not there in the cache. | 758 + // word is not there in the cache. |
| 777 + hentry* GetHentryFromHEntryCache(char* word); | 759 + hentry* GetHentryFromHEntryCache(char* word); |
| 778 + | 760 + |
| 779 + // Called before we do a new operation. This will empty the cache of pointers | 761 + // 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 | 762 + // 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 | 763 + // 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. | 764 + // of since Hunspell will save pointers to various ones as it works. |
| 783 + // | 765 + // |
| 784 + // This function allows that cache to be emptied and not grow infinitely. | 766 + // This function allows that cache to be emptied and not grow infinitely. |
| 785 + void EmptyHentryCache(); | 767 + void EmptyHentryCache(); |
| 786 +#else | 768 +#else |
| 787 HashMgr(const char * tpath, const char * apath, const char * key = NULL); | 769 HashMgr(const char* tpath, const char* apath, const char* key = NULL); |
| 788 +#endif | 770 +#endif |
| 789 ~HashMgr(); | 771 ~HashMgr(); |
| 790 | 772 |
| 791 struct hentry * lookup(const char *) const; | 773 struct hentry* lookup(const char*) const; |
| 792 @@ -59,6 +90,40 @@ | 774 @@ -134,6 +164,40 @@ class HashMgr { |
| 793 int al, const char * desc, bool onlyupcase); | 775 bool onlyupcase); |
| 794 int load_config(const char * affpath, const char * key); | 776 int load_config(const char* affpath, const char* key); |
| 795 int parse_aliasf(char * line, FileMgr * af); | 777 bool parse_aliasf(const std::string& line, FileMgr* af); |
| 796 + | 778 + |
| 797 +#ifdef HUNSPELL_CHROME_CLIENT | 779 +#ifdef HUNSPELL_CHROME_CLIENT |
| 798 + // Loads the AF lines from a BDICT. | 780 + // Loads the AF lines from a BDICT. |
| 799 + // A BDICT file compresses its AF lines to save memory. | 781 + // A BDICT file compresses its AF lines to save memory. |
| 800 + // This function decompresses each AF line and call parse_aliasf(). | 782 + // This function decompresses each AF line and call parse_aliasf(). |
| 801 + int LoadAFLines(); | 783 + int LoadAFLines(); |
| 802 + | 784 + |
| 803 + // Helper functions that create a new hentry struct, initialize it, and | 785 + // Helper functions that create a new hentry struct, initialize it, and |
| 804 + // delete it. | 786 + // delete it. |
| 805 + // These functions encapsulate non-trivial operations in creating and | 787 + // These functions encapsulate non-trivial operations in creating and |
| (...skipping 14 matching lines...) Expand all Loading... |
| 820 + // be a statically allocated variable that will change for the next call. The | 802 + // be a statically allocated variable that will change for the next call. The |
| 821 + // |word| buffer must be the same. | 803 + // |word| buffer must be the same. |
| 822 + hentry* AffixIDsToHentry(char* word, int* affix_ids, int affix_count) const; | 804 + hentry* AffixIDsToHentry(char* word, int* affix_ids, int affix_count) const; |
| 823 + | 805 + |
| 824 + // See EmptyHentryCache above. Note that each one is actually a linked list | 806 + // See EmptyHentryCache above. Note that each one is actually a linked list |
| 825 + // followed by the homonym pointer. | 807 + // followed by the homonym pointer. |
| 826 + typedef std::map<std::string, hentry*> HEntryCache; | 808 + typedef std::map<std::string, hentry*> HEntryCache; |
| 827 + HEntryCache hentry_cache; | 809 + HEntryCache hentry_cache; |
| 828 +#endif | 810 +#endif |
| 829 + | 811 + |
| 830 int add_hidden_capitalized_word(char * word, int wbl, int wcl, | 812 int add_hidden_capitalized_word(const std::string& word, |
| 831 unsigned short * flags, int al, char * dp, int captype); | 813 int wcl, |
| 832 int parse_aliasm(char * line, FileMgr * af); | 814 unsigned short* flags, |
| 833 Index: src/hunspell/htypes.hxx | 815 diff --git a/third_party/hunspell/src/hunspell/htypes.hxx b/third_party/hunspell
/src/hunspell/htypes.hxx |
| 834 =================================================================== | 816 index d244394..05ef6af 100644 |
| 835 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/htypes.hxx,v | 817 --- a/third_party/hunspell/src/hunspell/htypes.hxx |
| 836 retrieving revision 1.3 | 818 +++ b/third_party/hunspell/src/hunspell/htypes.hxx |
| 837 diff -u -r1.3 htypes.hxx | 819 @@ -41,6 +41,16 @@ |
| 838 --- src/hunspell/htypes.hxx» 6 Sep 2010 07:58:53 -0000» 1.3 | |
| 839 +++ src/hunspell/htypes.hxx» 29 May 2014 01:05:07 -0000 | |
| 840 @@ -1,6 +1,16 @@ | |
| 841 #ifndef _HTYPES_HXX_ | 820 #ifndef _HTYPES_HXX_ |
| 842 #define _HTYPES_HXX_ | 821 #define _HTYPES_HXX_ |
| 843 | 822 |
| 844 +#ifdef HUNSPELL_CHROME_CLIENT | 823 +#ifdef HUNSPELL_CHROME_CLIENT |
| 845 +// This is a workaround for preventing errors in parsing Turkish BDICs, which | 824 +// This is a workaround for preventing errors in parsing Turkish BDICs, which |
| 846 +// contain very long AF lines (~ 12,000 chars). | 825 +// contain very long AF lines (~ 12,000 chars). |
| 847 +// TODO(hbono) change the HashMgr::parse_aliasf() function to be able to parse | 826 +// TODO(hbono) change the HashMgr::parse_aliasf() function to be able to parse |
| 848 +// longer lines than MAXDELEN. | 827 +// longer lines than MAXDELEN. |
| 849 +#define MAXDELEN (8192 * 2) | 828 +#define MAXDELEN (8192 * 2) |
| 850 +#else | 829 +#else |
| 851 +#define MAXDELEN 8192 | 830 +#define MAXDELEN 8192 |
| 852 +#endif // HUNSPELL_CHROME_CLIENT | 831 +#endif // HUNSPELL_CHROME_CLIENT |
| 853 + | 832 + |
| 854 #define ROTATE_LEN 5 | 833 #define ROTATE_LEN 5 |
| 855 | 834 |
| 856 #define ROTATE(v,q) \ | 835 #define ROTATE(v, q) \ |
| 857 Index: src/hunspell/hunspell.cxx | 836 diff --git a/third_party/hunspell/src/hunspell/hunspell.cxx b/third_party/hunspe
ll/src/hunspell/hunspell.cxx |
| 858 =================================================================== | 837 index 114570f..1110ee0 100644 |
| 859 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.cxx,v | 838 --- a/third_party/hunspell/src/hunspell/hunspell.cxx |
| 860 retrieving revision 1.29 | 839 +++ b/third_party/hunspell/src/hunspell/hunspell.cxx |
| 861 diff -u -r1.29 hunspell.cxx | 840 @@ -79,6 +79,9 @@ |
| 862 --- src/hunspell/hunspell.cxx» 23 Jun 2011 09:21:50 -0000» 1.29 | |
| 863 +++ src/hunspell/hunspell.cxx» 29 May 2014 01:05:07 -0000 | |
| 864 @@ -7,20 +7,37 @@ | |
| 865 | |
| 866 #include "hunspell.hxx" | 841 #include "hunspell.hxx" |
| 842 #include "suggestmgr.hxx" |
| 867 #include "hunspell.h" | 843 #include "hunspell.h" |
| 868 +#ifndef HUNSPELL_CHROME_CLIENT | 844 +#ifndef HUNSPELL_CHROME_CLIENT |
| 869 #ifndef MOZILLA_CLIENT | 845 +# include "config.h" |
| 870 # include "config.h" | |
| 871 #endif | |
| 872 +#endif | 846 +#endif |
| 873 #include "csutil.hxx" | 847 #include "csutil.hxx" |
| 874 | 848 |
| 849 #include <limits> |
| 850 @@ -89,9 +92,15 @@ |
| 851 class HunspellImpl |
| 852 { |
| 853 public: |
| 854 +#ifdef HUNSPELL_CHROME_CLIENT |
| 855 + HunspellImpl(const unsigned char* bdict_data, size_t bdict_length); |
| 856 +#else |
| 857 HunspellImpl(const char* affpath, const char* dpath, const char* key); |
| 858 +#endif |
| 859 ~HunspellImpl(); |
| 860 +#ifndef HUNSPELL_CHROME_CLIENT |
| 861 int add_dic(const char* dpath, const char* key); |
| 862 +#endif |
| 863 std::vector<std::string> suffix_suggest(const std::string& root_word); |
| 864 std::vector<std::string> generate(const std::string& word, const std::vector<
std::string>& pl); |
| 865 std::vector<std::string> generate(const std::string& word, const std::string&
pattern); |
| 866 @@ -115,7 +124,9 @@ private: |
| 867 AffixMgr* pAMgr; |
| 868 std::vector<HashMgr*> m_HMgrs; |
| 869 SuggestMgr* pSMgr; |
| 870 +#ifndef HUNSPELL_CHROME_CLIENT // We are using BDict instead. |
| 871 char* affixpath; |
| 872 +#endif |
| 873 std::string encoding; |
| 874 struct cs_info* csconv; |
| 875 int langnum; |
| 876 @@ -123,6 +134,11 @@ private: |
| 877 int complexprefixes; |
| 878 std::vector<std::string> wordbreak; |
| 879 |
| 880 +#ifdef HUNSPELL_CHROME_CLIENT |
| 881 + // Not owned by us, owned by the Hunspell object. |
| 882 + hunspell::BDictReader* bdict_reader; |
| 883 +#endif |
| 884 + |
| 885 private: |
| 886 void cleanword(std::string& dest, const std::string&, int* pcaptype, int* pab
brev); |
| 887 size_t cleanword2(std::string& dest, |
| 888 @@ -152,22 +168,43 @@ private: |
| 889 HunspellImpl& operator=(const HunspellImpl&); |
| 890 }; |
| 891 |
| 875 +#ifdef HUNSPELL_CHROME_CLIENT | 892 +#ifdef HUNSPELL_CHROME_CLIENT |
| 876 +Hunspell::Hunspell(const unsigned char* bdict_data, size_t bdict_length) | 893 +Hunspell::Hunspell(const unsigned char* bdict_data, size_t bdict_length) |
| 894 + : m_Impl(new HunspellImpl(bdict_data, bdict_length)) { |
| 877 +#else | 895 +#else |
| 878 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key) | 896 Hunspell::Hunspell(const char* affpath, const char* dpath, const char* key) |
| 897 : m_Impl(new HunspellImpl(affpath, dpath, key)) { |
| 879 +#endif | 898 +#endif |
| 880 { | 899 } |
| 881 encoding = NULL; | |
| 882 csconv = NULL; | |
| 883 utf8 = 0; | |
| 884 complexprefixes = 0; | |
| 885 +#ifndef HUNSPELL_CHROME_CLIENT | |
| 886 affixpath = mystrdup(affpath); | |
| 887 +#endif | |
| 888 maxdic = 0; | |
| 889 | 900 |
| 890 +#ifdef HUNSPELL_CHROME_CLIENT | 901 +#ifdef HUNSPELL_CHROME_CLIENT |
| 891 + bdict_reader = new hunspell::BDictReader; | 902 +HunspellImpl::HunspellImpl(const unsigned char* bdict_data, size_t bdict_length
) { |
| 892 + bdict_reader->Init(bdict_data, bdict_length); | 903 +#else |
| 904 HunspellImpl::HunspellImpl(const char* affpath, const char* dpath, const char*
key) { |
| 905 +#endif |
| 906 csconv = NULL; |
| 907 utf8 = 0; |
| 908 complexprefixes = 0; |
| 909 +#ifndef HUNSPELL_CHROME_CLIENT |
| 910 affixpath = mystrdup(affpath); |
| 911 +#endif |
| 893 + | 912 + |
| 894 + pHMgr[0] = new HashMgr(bdict_reader); | 913 +#ifdef HUNSPELL_CHROME_CLIENT |
| 895 + if (pHMgr[0]) maxdic = 1; | 914 + bdict_reader = new hunspell::BDictReader; |
| 915 + bdict_reader->Init(bdict_data, bdict_length); |
| 916 |
| 917 /* first set up the hash manager */ |
| 918 + m_HMgrs.push_back(new HashMgr(bdict_reader)); |
| 896 + | 919 + |
| 897 + pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic); | 920 + pAMgr = new AffixMgr(bdict_reader, m_HMgrs); // TODO: 'key' ? |
| 898 +#else | 921 +#else |
| 899 /* first set up the hash manager */ | 922 + /* first set up the hash manager */ |
| 900 pHMgr[0] = new HashMgr(dpath, affpath, key); | 923 m_HMgrs.push_back(new HashMgr(dpath, affpath, key)); |
| 901 if (pHMgr[0]) maxdic = 1; | 924 |
| 902 @@ -28,6 +45,7 @@ | 925 /* next set up the affix manager */ |
| 903 /* next set up the affix manager */ | 926 /* it needs access to the hash manager lookup methods */ |
| 904 /* it needs access to the hash manager lookup methods */ | 927 pAMgr = new AffixMgr(affpath, m_HMgrs, key); |
| 905 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key); | |
| 906 +#endif | 928 +#endif |
| 907 | 929 |
| 908 /* get the preferred try string and the dictionary */ | 930 /* get the preferred try string and the dictionary */ |
| 909 /* encoding from the Affix Manager for that dictionary */ | 931 /* encoding from the Affix Manager for that dictionary */ |
| 910 @@ -41,7 +59,11 @@ | 932 @@ -181,7 +218,11 @@ HunspellImpl::HunspellImpl(const char* affpath, const char*
dpath, const char* k |
| 911 wordbreak = pAMgr->get_breaktable(); | 933 wordbreak = pAMgr->get_breaktable(); |
| 912 | 934 |
| 913 /* and finally set up the suggestion manager */ | 935 /* and finally set up the suggestion manager */ |
| 914 +#ifdef HUNSPELL_CHROME_CLIENT | 936 +#ifdef HUNSPELL_CHROME_CLIENT |
| 915 + pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr); | 937 + pSMgr = new SuggestMgr(bdict_reader, try_string, MAXSUGGESTION, pAMgr); |
| 916 +#else | 938 +#else |
| 917 pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr); | 939 pSMgr = new SuggestMgr(try_string, MAXSUGGESTION, pAMgr); |
| 918 +#endif | 940 +#endif |
| 919 if (try_string) free(try_string); | 941 if (try_string) |
| 942 free(try_string); |
| 920 } | 943 } |
| 921 | 944 @@ -201,11 +242,17 @@ HunspellImpl::~HunspellImpl() { |
| 922 @@ -59,10 +81,16 @@ | 945 delete[] csconv; |
| 923 csconv= NULL; | 946 #endif |
| 924 if (encoding) free(encoding); | 947 csconv = NULL; |
| 925 encoding = NULL; | |
| 926 +#ifdef HUNSPELL_CHROME_CLIENT | 948 +#ifdef HUNSPELL_CHROME_CLIENT |
| 927 + if (bdict_reader) delete bdict_reader; | 949 + if (bdict_reader) delete bdict_reader; |
| 928 + bdict_reader = NULL; | 950 + bdict_reader = NULL; |
| 929 +#else | 951 +#else |
| 930 if (affixpath) free(affixpath); | 952 if (affixpath) |
| 931 affixpath = NULL; | 953 free(affixpath); |
| 954 affixpath = NULL; |
| 932 +#endif | 955 +#endif |
| 933 } | 956 } |
| 934 | 957 |
| 935 +#ifndef HUNSPELL_CHROME_CLIENT | 958 +#ifndef HUNSPELL_CHROME_CLIENT |
| 936 // load extra dictionaries | 959 // load extra dictionaries |
| 937 int Hunspell::add_dic(const char * dpath, const char * key) { | 960 int Hunspell::add_dic(const char* dpath, const char* key) { |
| 938 if (maxdic == MAXDIC || !affixpath) return 1; | 961 return m_Impl->add_dic(dpath, key); |
| 939 @@ -70,6 +98,7 @@ | 962 @@ -218,6 +265,7 @@ int HunspellImpl::add_dic(const char* dpath, const char* key
) { |
| 940 if (pHMgr[maxdic]) maxdic++; else return 1; | 963 m_HMgrs.push_back(new HashMgr(dpath, affixpath, key)); |
| 941 return 0; | 964 return 0; |
| 942 } | 965 } |
| 943 +#endif | 966 +#endif |
| 944 | 967 |
| 945 // make a copy of src at destination while removing all leading | 968 // make a copy of src at destination while removing all leading |
| 946 // blanks and removing any trailing periods after recording | 969 // blanks and removing any trailing periods after recording |
| 947 @@ -322,6 +351,9 @@ | 970 @@ -411,6 +459,9 @@ bool Hunspell::spell(const std::string& word, int* info, std
::string* root) { |
| 971 } |
| 948 | 972 |
| 949 int Hunspell::spell(const char * word, int * info, char ** root) | 973 bool HunspellImpl::spell(const std::string& word, int* info, std::string* root)
{ |
| 950 { | |
| 951 +#ifdef HUNSPELL_CHROME_CLIENT | 974 +#ifdef HUNSPELL_CHROME_CLIENT |
| 952 + if (pHMgr[0]) pHMgr[0]->EmptyHentryCache(); | 975 + if (m_HMgrs[0]) m_HMgrs[0]->EmptyHentryCache(); |
| 953 +#endif | 976 +#endif |
| 954 struct hentry * rv=NULL; | 977 struct hentry* rv = NULL; |
| 955 // need larger vector. For example, Turkish capital letter I converted a | 978 |
| 956 // 2-byte UTF-8 character (dotless i) by mkallsmall. | 979 int info2 = 0; |
| 957 @@ -586,6 +618,13 @@ | 980 @@ -717,6 +768,13 @@ struct hentry* HunspellImpl::checkword(const std::string& w
, int* info, std::str |
| 958 if (!len) | 981 if (!len) |
| 959 return NULL; | 982 return NULL; |
| 960 | 983 |
| 961 +#ifdef HUNSPELL_CHROME_CLIENT | 984 +#ifdef HUNSPELL_CHROME_CLIENT |
| 962 + // We need to check if the word length is valid to make coverity (Event | 985 + // 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. | 986 + // fixed_size_dest: Possible overrun of N byte fixed size buffer) happy. |
| 964 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX
WORDLEN)) | 987 + if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAX
WORDLEN)) |
| 965 + return NULL; | 988 + return NULL; |
| 966 +#endif | 989 +#endif |
| 967 + | 990 + |
| 968 // word reversing wrapper for complex prefixes | 991 // word reversing wrapper for complex prefixes |
| 969 if (complexprefixes) { | 992 if (complexprefixes) { |
| 970 if (word != w2) { | 993 if (!usebuffer) { |
| 971 @@ -675,6 +714,9 @@ | 994 @@ -829,6 +887,9 @@ std::vector<std::string> Hunspell::suggest(const std::string
& word) { |
| 995 } |
| 972 | 996 |
| 973 int Hunspell::suggest(char*** slst, const char * word) | 997 std::vector<std::string> HunspellImpl::suggest(const std::string& word) { |
| 974 { | |
| 975 +#ifdef HUNSPELL_CHROME_CLIENT | 998 +#ifdef HUNSPELL_CHROME_CLIENT |
| 976 + if (pHMgr[0]) pHMgr[0]->EmptyHentryCache(); | 999 + if (m_HMgrs[0]) m_HMgrs[0]->EmptyHentryCache(); |
| 977 +#endif | 1000 +#endif |
| 1001 std::vector<std::string> slst; |
| 1002 |
| 978 int onlycmpdsug = 0; | 1003 int onlycmpdsug = 0; |
| 979 char cw[MAXWORDUTF8LEN]; | 1004 @@ -992,9 +1053,9 @@ std::vector<std::string> HunspellImpl::suggest(const std::s
tring& word) { |
| 980 char wspace[MAXWORDUTF8LEN]; | 1005 w.append(slst[j].substr(pos + 1)); |
| 981 @@ -1921,13 +1963,21 @@ | 1006 (void)spell(w, &info, NULL); |
| 1007 if ((info & SPELL_COMPOUND) && (info & SPELL_FORBIDDEN)) { |
| 1008 - slst[pos] = ' '; |
| 1009 + slst[j][pos] = ' '; |
| 1010 } else |
| 1011 - slst[pos] = '-'; |
| 1012 + slst[j][pos] = '-'; |
| 1013 } |
| 1014 } |
| 1015 } |
| 1016 @@ -1845,22 +1906,32 @@ int Hunspell::generate(char*** slst, const char* word, c
onst char* pattern) { |
| 1017 } |
| 982 | 1018 |
| 983 Hunhandle *Hunspell_create(const char * affpath, const char * dpath) | 1019 Hunhandle* Hunspell_create(const char* affpath, const char* dpath) { |
| 984 { | |
| 985 +#ifdef HUNSPELL_CHROME_CLIENT | 1020 +#ifdef HUNSPELL_CHROME_CLIENT |
| 986 + return NULL; | 1021 + return NULL; |
| 987 +#else | 1022 +#else |
| 988 return (Hunhandle*)(new Hunspell(affpath, dpath)); | 1023 return (Hunhandle*)(new Hunspell(affpath, dpath)); |
| 989 +#endif | 1024 +#endif |
| 990 } | 1025 } |
| 991 | 1026 |
| 992 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath, | 1027 Hunhandle* Hunspell_create_key(const char* affpath, |
| 993 const char * key) | 1028 const char* dpath, |
| 994 { | 1029 const char* key) { |
| 995 +#ifdef HUNSPELL_CHROME_CLIENT | 1030 +#ifdef HUNSPELL_CHROME_CLIENT |
| 996 + return NULL; | 1031 + return NULL; |
| 997 +#else | 1032 +#else |
| 998 return (Hunhandle*)(new Hunspell(affpath, dpath, key)); | 1033 return reinterpret_cast<Hunhandle*>(new Hunspell(affpath, dpath, key)); |
| 999 +#endif | 1034 +#endif |
| 1000 } | 1035 } |
| 1001 | 1036 |
| 1002 void Hunspell_destroy(Hunhandle *pHunspell) | 1037 void Hunspell_destroy(Hunhandle* pHunspell) { |
| 1003 Index: src/hunspell/hunspell.hxx | 1038 delete reinterpret_cast<Hunspell*>(pHunspell); |
| 1004 =================================================================== | 1039 } |
| 1005 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/hunspell.hxx,v | 1040 |
| 1006 retrieving revision 1.6 | 1041 +#ifndef HUNSPELL_CHROME_CLIENT |
| 1007 diff -u -r1.6 hunspell.hxx | 1042 int Hunspell_add_dic(Hunhandle* pHunspell, const char* dpath) { |
| 1008 --- src/hunspell/hunspell.hxx» 21 Jan 2011 17:30:41 -0000» 1.6 | 1043 return reinterpret_cast<Hunspell*>(pHunspell)->add_dic(dpath); |
| 1009 +++ src/hunspell/hunspell.hxx» 29 May 2014 01:05:07 -0000 | 1044 } |
| 1010 @@ -5,6 +5,10 @@ | 1045 +#endif |
| 1011 #include "suggestmgr.hxx" | 1046 |
| 1012 #include "langnum.hxx" | 1047 int Hunspell_spell(Hunhandle* pHunspell, const char* word) { |
| 1048 return reinterpret_cast<Hunspell*>(pHunspell)->spell(std::string(word)); |
| 1049 diff --git a/third_party/hunspell/src/hunspell/hunspell.hxx b/third_party/hunspe
ll/src/hunspell/hunspell.hxx |
| 1050 index db25bae..251d58e 100644 |
| 1051 --- a/third_party/hunspell/src/hunspell/hunspell.hxx |
| 1052 +++ b/third_party/hunspell/src/hunspell/hunspell.hxx |
| 1053 @@ -78,6 +78,10 @@ |
| 1054 #include <string> |
| 1055 #include <vector> |
| 1013 | 1056 |
| 1014 +#ifdef HUNSPELL_CHROME_CLIENT | 1057 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1015 +#include "third_party/hunspell/google/bdict_reader.h" | 1058 +#include "third_party/hunspell/google/bdict_reader.h" |
| 1016 +#endif | 1059 +#endif |
| 1017 + | 1060 + |
| 1018 #define SPELL_XML "<?xml?>" | 1061 #define SPELL_XML "<?xml?>" |
| 1019 | 1062 |
| 1020 #define MAXDIC 20 | 1063 #define MAXSUGGESTION 15 |
| 1021 @@ -23,7 +27,9 @@ | 1064 @@ -111,11 +115,17 @@ class LIBHUNSPELL_DLL_EXPORTED Hunspell { |
| 1022 HashMgr* pHMgr[MAXDIC]; | 1065 * long path names (without the long path prefix Hunspell will use fopen() |
| 1023 int maxdic; | 1066 * with system-dependent character encoding instead of _wfopen()). |
| 1024 SuggestMgr* pSMgr; | |
| 1025 +#ifndef HUNSPELL_CHROME_CLIENT // We are using BDict instead. | |
| 1026 char * affixpath; | |
| 1027 +#endif | |
| 1028 char * encoding; | |
| 1029 struct cs_info * csconv; | |
| 1030 int langnum; | |
| 1031 @@ -31,17 +37,28 @@ | |
| 1032 int complexprefixes; | |
| 1033 char** wordbreak; | |
| 1034 | |
| 1035 +#ifdef HUNSPELL_CHROME_CLIENT | |
| 1036 + // Not owned by us, owned by the Hunspell object. | |
| 1037 + hunspell::BDictReader* bdict_reader; | |
| 1038 +#endif | |
| 1039 + | |
| 1040 public: | |
| 1041 | |
| 1042 /* Hunspell(aff, dic) - constructor of Hunspell class | |
| 1043 * input: path of affix file and dictionary file | |
| 1044 */ | 1067 */ |
| 1045 | |
| 1046 +#ifdef HUNSPELL_CHROME_CLIENT | 1068 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1047 + Hunspell(const unsigned char* bdict_data, size_t bdict_length); | 1069 + Hunspell(const unsigned char* bdict_data, size_t bdict_length); |
| 1048 +#else | 1070 +#else |
| 1049 Hunspell(const char * affpath, const char * dpath, const char * key = NULL); | 1071 Hunspell(const char* affpath, const char* dpath, const char* key = NULL); |
| 1050 +#endif | 1072 +#endif |
| 1051 ~Hunspell(); | 1073 ~Hunspell(); |
| 1052 | 1074 |
| 1053 +#ifndef HUNSPELL_CHROME_CLIENT | 1075 +#ifndef HUNSPELL_CHROME_CLIENT |
| 1054 /* load extra dictionaries (only dic files) */ | 1076 /* load extra dictionaries (only dic files) */ |
| 1055 int add_dic(const char * dpath, const char * key = NULL); | 1077 int add_dic(const char* dpath, const char* key = NULL); |
| 1056 +#endif | 1078 +#endif |
| 1057 | 1079 |
| 1058 /* spell(word) - spellcheck word | 1080 /* spell(word) - spellcheck word |
| 1059 * output: 0 = bad word, not 0 = good word | 1081 * output: false = bad word, true = good word |
| 1060 Index: src/hunspell/replist.hxx | 1082 diff --git a/third_party/hunspell/src/hunspell/replist.cxx b/third_party/hunspel
l/src/hunspell/replist.cxx |
| 1061 =================================================================== | 1083 index 8404947..3128420 100644 |
| 1062 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/replist.hxx,v | 1084 --- a/third_party/hunspell/src/hunspell/replist.cxx |
| 1063 retrieving revision 1.2 | 1085 +++ b/third_party/hunspell/src/hunspell/replist.cxx |
| 1064 diff -u -r1.2 replist.hxx | 1086 @@ -167,6 +167,7 @@ int RepList::add(const std::string& in_pat1, const std::stri
ng& pat2) { |
| 1065 --- src/hunspell/replist.hxx» 15 Apr 2010 11:22:09 -0000» 1.2 | 1087 mystrrep(r->outstrings[type], "_", " "); |
| 1066 +++ src/hunspell/replist.hxx» 29 May 2014 01:05:07 -0000 | 1088 dat[pos++] = r; |
| 1067 @@ -2,6 +2,12 @@ | 1089 // sort to the right place in the list |
| 1090 +#if 0 |
| 1091 int i; |
| 1092 for (i = pos - 1; i > 0; i--) { |
| 1093 int c = strncmp(r->pattern.c_str(), dat[i-1]->pattern.c_str(), dat[i-1]->pa
ttern.size()); |
| 1094 @@ -184,6 +185,15 @@ int RepList::add(const std::string& in_pat1, const std::str
ing& pat2) { |
| 1095 } |
| 1096 memmove(dat + i + 1, dat + i, (pos - i - 1) * sizeof(replentry *)); |
| 1097 dat[i] = r; |
| 1098 +#else |
| 1099 + for (int i = pos - 1; i > 0; i--) { |
| 1100 + r = dat[i]; |
| 1101 + if (r->pattern < dat[i - 1]->pattern) { |
| 1102 + dat[i] = dat[i - 1]; |
| 1103 + dat[i - 1] = r; |
| 1104 + } else break; |
| 1105 + } |
| 1106 +#endif |
| 1107 return 0; |
| 1108 } |
| 1109 |
| 1110 diff --git a/third_party/hunspell/src/hunspell/replist.hxx b/third_party/hunspel
l/src/hunspell/replist.hxx |
| 1111 index ccf29b5c..176ccec 100644 |
| 1112 --- a/third_party/hunspell/src/hunspell/replist.hxx |
| 1113 +++ b/third_party/hunspell/src/hunspell/replist.hxx |
| 1114 @@ -75,6 +75,12 @@ |
| 1068 #ifndef _REPLIST_HXX_ | 1115 #ifndef _REPLIST_HXX_ |
| 1069 #define _REPLIST_HXX_ | 1116 #define _REPLIST_HXX_ |
| 1070 | 1117 |
| 1071 +#ifdef HUNSPELL_CHROME_CLIENT | 1118 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1072 +// Compilation issues in spellchecker.cc think near is a macro, therefore | 1119 +// Compilation issues in spellchecker.cc think near is a macro, therefore |
| 1073 +// removing it here solves that problem. | 1120 +// removing it here solves that problem. |
| 1074 +#undef near | 1121 +#undef near |
| 1075 +#endif | 1122 +#endif |
| 1076 + | 1123 + |
| 1077 #include "hunvisapi.h" | 1124 #include "w_char.hxx" |
| 1078 | 1125 |
| 1079 #include "w_char.hxx" | 1126 #include <string> |
| 1080 Index: src/hunspell/suggestmgr.cxx | 1127 diff --git a/third_party/hunspell/src/hunspell/suggestmgr.cxx b/third_party/huns
pell/src/hunspell/suggestmgr.cxx |
| 1081 =================================================================== | 1128 index 7a9dafa..55f99b6 100644 |
| 1082 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.cxx,v | 1129 --- a/third_party/hunspell/src/hunspell/suggestmgr.cxx |
| 1083 retrieving revision 1.24 | 1130 +++ b/third_party/hunspell/src/hunspell/suggestmgr.cxx |
| 1084 diff -u -r1.24 suggestmgr.cxx | 1131 @@ -82,7 +82,112 @@ |
| 1085 --- src/hunspell/suggestmgr.cxx»14 Feb 2011 21:47:24 -0000» 1.24 | |
| 1086 +++ src/hunspell/suggestmgr.cxx»29 May 2014 01:05:07 -0000 | |
| 1087 @@ -12,9 +12,114 @@ | |
| 1088 | 1132 |
| 1089 const w_char W_VLINE = { '\0', '|' }; | 1133 const w_char W_VLINE = {'\0', '|'}; |
| 1090 | 1134 |
| 1091 +#ifdef HUNSPELL_CHROME_CLIENT | 1135 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1092 +namespace { | 1136 +namespace { |
| 1093 +// A simple class which creates temporary hentry objects which are available | 1137 +// A simple class which creates temporary hentry objects which are available |
| 1094 +// only in a scope. To conceal memory operations from SuggestMgr functions, | 1138 +// only in a scope. To conceal memory operations from SuggestMgr functions, |
| 1095 +// this object automatically deletes all hentry objects created through | 1139 +// this object automatically deletes all hentry objects created through |
| 1096 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet | 1140 +// CreateScopedHashEntry() calls in its destructor. So, the following snippet |
| 1097 +// raises a memory error. | 1141 +// raises a memory error. |
| 1098 +// | 1142 +// |
| 1099 +// hentry* bad_copy = NULL; | 1143 +// hentry* bad_copy = NULL; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 +#endif | 1229 +#endif |
| 1186 + | 1230 + |
| 1187 + | 1231 + |
| 1188 +#ifdef HUNSPELL_CHROME_CLIENT | 1232 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1189 +SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, | 1233 +SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, |
| 1190 + const char * tryme, int maxn, | 1234 + const char * tryme, int maxn, |
| 1191 + AffixMgr * aptr) | 1235 + AffixMgr * aptr) |
| 1192 +{ | 1236 +{ |
| 1193 + bdict_reader = reader; | 1237 + bdict_reader = reader; |
| 1194 +#else | 1238 +#else |
| 1195 SuggestMgr::SuggestMgr(const char * tryme, int maxn, | 1239 SuggestMgr::SuggestMgr(const char* tryme, unsigned int maxn, AffixMgr* aptr) { |
| 1196 AffixMgr * aptr) | |
| 1197 { | |
| 1198 +#endif | 1240 +#endif |
| 1199 | 1241 // register affix manager and check in string of chars to |
| 1200 // register affix manager and check in string of chars to | |
| 1201 // try when building candidate suggestions | 1242 // try when building candidate suggestions |
| 1202 @@ -407,6 +512,49 @@ | 1243 pAMgr = aptr; |
| 1203 int lenr, lenp; | 1244 @@ -409,6 +514,21 @@ int SuggestMgr::replchars(std::vector<std::string>& wlst, |
| 1204 int wl = strlen(word); | 1245 int wl = strlen(word); |
| 1205 if (wl < 2 || ! pAMgr) return ns; | 1246 if (wl < 2 || !pAMgr) |
| 1206 + | 1247 return wlst.size(); |
| 1248 + |
| 1249 +// TODO: wrong, 'ns' doesn't exist any more |
| 1207 +#ifdef HUNSPELL_CHROME_CLIENT | 1250 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1208 + const char *pattern, *pattern2; | 1251 + const char *pattern, *pattern2; |
| 1209 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator
(); | 1252 + hunspell::ReplacementIterator iterator = bdict_reader->GetReplacementIterator
(); |
| 1210 + while (iterator.GetNext(&pattern, &pattern2)) { | 1253 + while (iterator.GetNext(&pattern, &pattern2)) { |
| 1211 + r = word; | 1254 + const char* r = word; |
| 1212 + lenr = strlen(pattern2); | 1255 + size_t lenr = strlen(pattern2); |
| 1213 + lenp = strlen(pattern); | 1256 + size_t lenp = strlen(pattern); |
| 1214 + | 1257 + |
| 1215 + // search every occurence of the pattern in the word | 1258 + // search every occurence of the pattern in the word |
| 1216 + while ((r=strstr(r, pattern)) != NULL) { | 1259 + while ((r=strstr(r, pattern)) != NULL) { |
| 1217 + strcpy(candidate, word); | 1260 + candidate = word; |
| 1218 + if (r-word + lenr + strlen(r+lenp) >= MAXLNLEN) break; | 1261 + candidate.replace(r-word, lenp, pattern2); |
| 1219 + strcpy(candidate+(r-word), pattern2); | |
| 1220 + strcpy(candidate+(r-word)+lenr, r+lenp); | |
| 1221 + ns = testsug(wlst, candidate, wl-lenp+lenr, ns, cpdsuggest, NULL, NUL
L); | |
| 1222 + if (ns == -1) return -1; | |
| 1223 + // check REP suggestions with space | |
| 1224 + char * sp = strchr(candidate, ' '); | |
| 1225 + if (sp) { | |
| 1226 + char * prev = candidate; | |
| 1227 + while (sp) { | |
| 1228 + *sp = '\0'; | |
| 1229 + if (checkword(prev, strlen(prev), 0, NULL, NULL)) { | |
| 1230 + int oldns = ns; | |
| 1231 + *sp = ' '; | |
| 1232 + ns = testsug(wlst, sp + 1, strlen(sp + 1), ns, cpdsuggest, NULL
, NULL); | |
| 1233 + if (ns == -1) return -1; | |
| 1234 + if (oldns < ns) { | |
| 1235 + free(wlst[ns - 1]); | |
| 1236 + wlst[ns - 1] = mystrdup(candidate); | |
| 1237 + if (!wlst[ns - 1]) return -1; | |
| 1238 + } | |
| 1239 + } | |
| 1240 + *sp = ' '; | |
| 1241 + prev = sp + 1; | |
| 1242 + sp = strchr(prev, ' '); | |
| 1243 + } | |
| 1244 + } | |
| 1245 + r++; // search for the next letter | |
| 1246 + } | |
| 1247 + } | |
| 1248 +#else | 1262 +#else |
| 1249 int numrep = pAMgr->get_numrep(); | 1263 const std::vector<replentry>& reptable = pAMgr->get_reptable(); |
| 1250 struct replentry* reptable = pAMgr->get_reptable(); | 1264 for (size_t i = 0; i < reptable.size(); ++i) { |
| 1251 if (reptable==NULL) return ns; | 1265 const char* r = word; |
| 1252 @@ -448,6 +596,7 @@ | 1266 @@ -428,6 +548,7 @@ int SuggestMgr::replchars(std::vector<std::string>& wlst, |
| 1253 r++; // search for the next letter | 1267 candidate.resize(r - word); |
| 1254 } | 1268 candidate.append(reptable[i].outstrings[type]); |
| 1255 } | 1269 candidate.append(r + reptable[i].pattern.size()); |
| 1256 +#endif | 1270 +#endif |
| 1257 return ns; | 1271 testsug(wlst, candidate, cpdsuggest, NULL, NULL); |
| 1258 } | 1272 // check REP suggestions with space |
| 1259 | 1273 size_t sp = candidate.find(' '); |
| 1260 @@ -678,7 +827,9 @@ | 1274 @@ -1047,6 +1168,9 @@ void SuggestMgr::ngsuggest(std::vector<std::string>& wlst, |
| 1261 // error is missing a letter it needs | |
| 1262 int SuggestMgr::forgotchar(char ** wlst, const char * word, int ns, int cpdsugg
est) | |
| 1263 { | |
| 1264 - char candidate[MAXSWUTF8L]; | |
| 1265 + // TODO(rouslan): Remove the interim change below when this patch lands: | |
| 1266 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639
5 | |
| 1267 + char candidate[MAXSWUTF8L + 4]; | |
| 1268 char * p; | |
| 1269 clock_t timelimit = clock(); | |
| 1270 int timer = MINTIMER; | |
| 1271 @@ -700,8 +851,10 @@ | |
| 1272 // error is missing a letter it needs | |
| 1273 int SuggestMgr::forgotchar_utf(char ** wlst, const w_char * word, int wl, int n
s, int cpdsuggest) | |
| 1274 { | |
| 1275 - w_char candidate_utf[MAXSWL]; | |
| 1276 - char candidate[MAXSWUTF8L]; | |
| 1277 + // TODO(rouslan): Remove the interim change below when this patch lands: | |
| 1278 + // http://sf.net/tracker/?func=detail&aid=3595024&group_id=143754&atid=75639
5 | |
| 1279 + w_char candidate_utf[MAXSWL + 1]; | |
| 1280 + char candidate[MAXSWUTF8L + 4]; | |
| 1281 w_char * p; | |
| 1282 clock_t timelimit = clock(); | |
| 1283 int timer = MINTIMER; | |
| 1284 @@ -1057,6 +1210,9 @@ | |
| 1285 | 1275 |
| 1286 struct hentry* hp = NULL; | 1276 struct hentry* hp = NULL; |
| 1287 int col = -1; | 1277 int col = -1; |
| 1288 +#ifdef HUNSPELL_CHROME_CLIENT | 1278 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1289 + ScopedHashEntryFactory hash_entry_factory; | 1279 + ScopedHashEntryFactory hash_entry_factory; |
| 1290 +#endif | 1280 +#endif |
| 1291 phonetable * ph = (pAMgr) ? pAMgr->get_phonetable() : NULL; | 1281 phonetable* ph = (pAMgr) ? pAMgr->get_phonetable() : NULL; |
| 1292 char target[MAXSWUTF8L]; | 1282 std::string target; |
| 1293 char candidate[MAXSWUTF8L]; | 1283 std::string candidate; |
| 1294 @@ -1115,7 +1271,11 @@ | 1284 @@ -1109,7 +1233,11 @@ void SuggestMgr::ngsuggest(std::vector<std::string>& wlst
, |
| 1295 | 1285 |
| 1296 if (sc > scores[lp]) { | 1286 if (sc > scores[lp]) { |
| 1297 scores[lp] = sc; | 1287 scores[lp] = sc; |
| 1298 +#ifdef HUNSPELL_CHROME_CLIENT | 1288 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1299 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp); | 1289 + roots[lp] = hash_entry_factory.CreateScopedHashEntry(lp, hp); |
| 1300 +#else | 1290 +#else |
| 1301 roots[lp] = hp; | 1291 roots[lp] = hp; |
| 1302 +#endif | 1292 +#endif |
| 1303 lval = sc; | 1293 lval = sc; |
| 1304 for (j=0; j < MAX_ROOTS; j++) | 1294 for (int j = 0; j < MAX_ROOTS; j++) |
| 1305 if (scores[j] < lval) { | 1295 if (scores[j] < lval) { |
| 1306 @@ -1948,16 +2108,14 @@ | 1296 @@ -1137,6 +1265,7 @@ void SuggestMgr::ngsuggest(std::vector<std::string>& wlst, |
| 1297 int thresh = 0; |
| 1298 for (int sp = 1; sp < 4; sp++) { |
| 1299 if (utf8) { |
| 1300 + u8_u16(u8, word); |
| 1301 for (int k = sp; k < n; k += 4) { |
| 1302 u8[k].l = '*'; |
| 1303 u8[k].h = 0; |
| 1304 @@ -1968,8 +2097,8 @@ void SuggestMgr::lcs(const char* s, |
| 1307 m = strlen(s); | 1305 m = strlen(s); |
| 1308 n = strlen(s2); | 1306 n = strlen(s2); |
| 1309 } | 1307 } |
| 1310 - c = (char *) malloc((m + 1) * (n + 1)); | 1308 - c = (char*)malloc((m + 1) * (n + 1)); |
| 1311 - b = (char *) malloc((m + 1) * (n + 1)); | 1309 - b = (char*)malloc((m + 1) * (n + 1)); |
| 1312 + c = (char *) calloc(m + 1, n + 1); | 1310 + c = (char *) calloc(m + 1, n + 1); |
| 1313 + b = (char *) calloc(m + 1, n + 1); | 1311 + b = (char *) calloc(m + 1, n + 1); |
| 1314 if (!c || !b) { | 1312 if (!c || !b) { |
| 1315 if (c) free(c); | 1313 if (c) |
| 1316 if (b) free(b); | 1314 free(c); |
| 1315 @@ -1978,10 +2107,6 @@ void SuggestMgr::lcs(const char* s, |
| 1317 *result = NULL; | 1316 *result = NULL; |
| 1318 return; | 1317 return; |
| 1319 } | 1318 } |
| 1320 - for (i = 1; i <= m; i++) c[i*(n+1)] = 0; | 1319 - for (i = 1; i <= m; i++) |
| 1321 - for (j = 0; j <= n; j++) c[j] = 0; | 1320 - c[i * (n + 1)] = 0; |
| 1321 - for (j = 0; j <= n; j++) |
| 1322 - c[j] = 0; |
| 1322 for (i = 1; i <= m; i++) { | 1323 for (i = 1; i <= m; i++) { |
| 1323 for (j = 1; j <= n; j++) { | 1324 for (j = 1; j <= n; j++) { |
| 1324 if ( ((utf8) && (*((short *) su+i-1) == *((short *)su2+j-1))) | 1325 if (((utf8) && (su[i - 1] == su2[j - 1])) || |
| 1325 Index: src/hunspell/suggestmgr.hxx | 1326 diff --git a/third_party/hunspell/src/hunspell/suggestmgr.hxx b/third_party/huns
pell/src/hunspell/suggestmgr.hxx |
| 1326 =================================================================== | 1327 index ee0322c..f940431 100644 |
| 1327 RCS file: /cvsroot/hunspell/hunspell/src/hunspell/suggestmgr.hxx,v | 1328 --- a/third_party/hunspell/src/hunspell/suggestmgr.hxx |
| 1328 retrieving revision 1.5 | 1329 +++ b/third_party/hunspell/src/hunspell/suggestmgr.hxx |
| 1329 diff -u -r1.5 suggestmgr.hxx | 1330 @@ -124,7 +124,11 @@ class SuggestMgr { |
| 1330 --- src/hunspell/suggestmgr.hxx»21 Jan 2011 22:10:24 -0000» 1.5 | 1331 int complexprefixes; |
| 1331 +++ src/hunspell/suggestmgr.hxx»29 May 2014 01:05:07 -0000 | |
| 1332 @@ -52,7 +52,11 @@ | |
| 1333 | 1332 |
| 1334 | 1333 public: |
| 1335 public: | |
| 1336 +#ifdef HUNSPELL_CHROME_CLIENT | 1334 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1337 + SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, Affix
Mgr *aptr); | 1335 + SuggestMgr(hunspell::BDictReader* reader, const char * tryme, int maxn, Affix
Mgr *aptr); |
| 1338 +#else | 1336 +#else |
| 1339 SuggestMgr(const char * tryme, int maxn, AffixMgr *aptr); | 1337 SuggestMgr(const char* tryme, unsigned int maxn, AffixMgr* aptr); |
| 1340 +#endif | 1338 +#endif |
| 1341 ~SuggestMgr(); | 1339 ~SuggestMgr(); |
| 1342 | 1340 |
| 1343 int suggest(char*** slst, const char * word, int nsug, int * onlycmpdsug); | 1341 void suggest(std::vector<std::string>& slst, const char* word, int* onlycmpds
ug); |
| 1344 @@ -66,6 +70,10 @@ | 1342 @@ -134,6 +138,10 @@ class SuggestMgr { |
| 1345 char * suggest_morph_for_spelling_error(const char * word); | 1343 std::string suggest_gen(const std::vector<std::string>& pl, const std::string
& pattern); |
| 1346 | 1344 |
| 1347 private: | 1345 private: |
| 1348 +#ifdef HUNSPELL_CHROME_CLIENT | 1346 +#ifdef HUNSPELL_CHROME_CLIENT |
| 1349 + // Not owned by us, owned by the Hunspell object. | 1347 + // Not owned by us, owned by the Hunspell object. |
| 1350 + hunspell::BDictReader* bdict_reader; | 1348 + hunspell::BDictReader* bdict_reader; |
| 1351 +#endif | 1349 +#endif |
| 1352 int testsug(char** wlst, const char * candidate, int wl, int ns, int cpdsugg
est, | 1350 void testsug(std::vector<std::string>& wlst, |
| 1353 int * timer, clock_t * timelimit); | 1351 const std::string& candidate, |
| 1354 int checkword(const char *, int, int, int *, clock_t *); | 1352 int cpdsuggest, |
| 1355 diff --git a/third_party/hunspell/src/hunspell/csutil.cxx b/third_party/hunspell
/src/hunspell/csutil.cxx | |
| 1356 index 2be9027..0f2267f 100644 | |
| 1357 --- a/third_party/hunspell/src/hunspell/csutil.cxx | |
| 1358 +++ b/third_party/hunspell/src/hunspell/csutil.cxx | |
| 1359 @@ -96,10 +96,10 @@ char * u16_u8(char * dest, int size, const w_char * src, int
srclen) { | |
| 1360 | |
| 1361 /* only UTF-16 (BMP) implementation */ | |
| 1362 int u8_u16(w_char * dest, int size, const char * src) { | |
| 1363 - const signed char * u8 = (const signed char *)src; | |
| 1364 + const unsigned char * u8 = (const unsigned char*)src; | |
| 1365 w_char * u2 = dest; | |
| 1366 w_char * u2_max = u2 + size; | |
| 1367 - | |
| 1368 + | |
| 1369 while ((u2 < u2_max) && *u8) { | |
| 1370 switch ((*u8) & 0xf0) { | |
| 1371 case 0x00: | |
| 1372 @@ -118,7 +118,7 @@ int u8_u16(w_char * dest, int size, const char * src) { | |
| 1373 case 0x90: | |
| 1374 case 0xa0: | |
| 1375 case 0xb0: { | |
| 1376 - HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Unexpected continua
tion bytes in %ld. character position\n%s\n", static_cast<long>(u8 - (signed cha
r *)src), src); | |
| 1377 + HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Unexpected continua
tion bytes in %ld. character position\n%s\n", static_cast<long>(u8 - (const unsi
gned char*)src), src); | |
| 1378 u2->h = 0xff; | |
| 1379 u2->l = 0xfd; | |
| 1380 break; | |
| 1381 @@ -130,7 +130,7 @@ int u8_u16(w_char * dest, int size, const char * src) { | |
| 1382 u2->l = (*u8 << 6) + (*(u8+1) & 0x3f); | |
| 1383 u8++; | |
| 1384 } else { | |
| 1385 - HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing continu
ation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (signed ch
ar *)src), src); | |
| 1386 + HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing continu
ation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (const uns
igned char*)src), src); | |
| 1387 u2->h = 0xff; | |
| 1388 u2->l = 0xfd; | |
| 1389 } | |
| 1390 @@ -144,12 +144,12 @@ int u8_u16(w_char * dest, int size, const char * src) { | |
| 1391 u2->l = (*u8 << 6) + (*(u8+1) & 0x3f); | |
| 1392 u8++; | |
| 1393 } else { | |
| 1394 - HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing con
tinuation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (signe
d char *)src), src); | |
| 1395 + HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing con
tinuation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (const
unsigned char*)src), src); | |
| 1396 u2->h = 0xff; | |
| 1397 u2->l = 0xfd; | |
| 1398 } | |
| 1399 } else { | |
| 1400 - HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing continu
ation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (signed ch
ar *)src), src); | |
| 1401 + HUNSPELL_WARNING(stderr, "UTF-8 encoding error. Missing continu
ation byte in %ld. character position:\n%s\n", static_cast<long>(u8 - (const uns
igned char*)src), src); | |
| 1402 u2->h = 0xff; | |
| 1403 u2->l = 0xfd; | |
| 1404 } | |
| OLD | NEW |