| OLD | NEW |
| 1 #include "license.hunspell" | 1 #include "license.hunspell" |
| 2 #include "license.myspell" | 2 #include "license.myspell" |
| 3 | 3 |
| 4 #include <stdlib.h> | 4 #include <stdlib.h> |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include "suggestmgr.hxx" | 9 #include "suggestmgr.hxx" |
| 10 #include "htypes.hxx" | 10 #include "htypes.hxx" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 hentry* CreateScopedHashEntry(int index, const hentry* source); | 47 hentry* CreateScopedHashEntry(int index, const hentry* source); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // A struct which encapsulates the new hentry struct introduced in hunspell | 50 // A struct which encapsulates the new hentry struct introduced in hunspell |
| 51 // 1.2.8. For a pointer to an hentry struct 'h', hunspell 1.2.8 stores a word | 51 // 1.2.8. For a pointer to an hentry struct 'h', hunspell 1.2.8 stores a word |
| 52 // (including a NUL character) into 'h->word[0]',...,'h->word[h->blen]' even | 52 // (including a NUL character) into 'h->word[0]',...,'h->word[h->blen]' even |
| 53 // though arraysize(h->word[]) is 1. Also, it changed 'astr' to a pointer so | 53 // though arraysize(h->word[]) is 1. Also, it changed 'astr' to a pointer so |
| 54 // it can store affix flags into 'h->astr[0]',...,'h->astr[alen-1]'. To handle | 54 // it can store affix flags into 'h->astr[0]',...,'h->astr[alen-1]'. To handle |
| 55 // this new hentry struct, we define a struct which combines three values: an | 55 // this new hentry struct, we define a struct which combines three values: an |
| 56 // hentry struct 'hentry'; a char array 'word[kMaxWordLen]', and; an unsigned | 56 // hentry struct 'hentry'; a char array 'word[kMaxWordLen]', and; an unsigned |
| 57 // short value 'astr' so a hentry struct 'h' returned from | 57 // short array 'astr' so a hentry struct 'h' returned from |
| 58 // CreateScopedHashEntry() satisfies the following equations: | 58 // CreateScopedHashEntry() satisfies the following equations: |
| 59 // hentry* h = factory.CreateScopedHashEntry(0, source); | 59 // hentry* h = factory.CreateScopedHashEntry(0, source); |
| 60 // h->word[0] == ((HashEntryItem*)h)->entry.word[0]. | 60 // h->word[0] == ((HashEntryItem*)h)->entry.word[0]. |
| 61 // h->word[1] == ((HashEntryItem*)h)->word[0]. | 61 // h->word[1] == ((HashEntryItem*)h)->word[0]. |
| 62 // ... | 62 // ... |
| 63 // h->word[h->blen] == ((HashEntryItem*)h)->word[h->blen-1]. | 63 // h->word[h->blen] == ((HashEntryItem*)h)->word[h->blen-1]. |
| 64 // h->astr[0] == ((HashEntryItem*)h)->astr. | 64 // h->astr[0] == ((HashEntryItem*)h)->astr[0]. |
| 65 // Our BDICT does not use affix flags longer than one for now since they are | 65 // h->astr[1] == ((HashEntryItem*)h)->astr[1]. |
| 66 // discarded by convert_dict, i.e. 'h->astr' is always <= 1. Therefore, this | 66 // ... |
| 67 // struct does not use an array for 'astr'. | 67 // h->astr[h->alen-1] == ((HashEntryItem*)h)->astr[h->alen-1]. |
| 68 enum { | 68 enum { |
| 69 kMaxWordLen = 128, | 69 kMaxWordLen = 128, |
| 70 kMaxAffixLen = 8, |
| 70 }; | 71 }; |
| 71 struct HashEntryItem { | 72 struct HashEntryItem { |
| 72 hentry entry; | 73 hentry entry; |
| 73 char word[kMaxWordLen]; | 74 char word[kMaxWordLen]; |
| 74 unsigned short astr; | 75 unsigned short astr[kMaxAffixLen]; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 HashEntryItem hash_items_[MAX_ROOTS]; | 78 HashEntryItem hash_items_[MAX_ROOTS]; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 ScopedHashEntryFactory::ScopedHashEntryFactory() { | 81 ScopedHashEntryFactory::ScopedHashEntryFactory() { |
| 81 memset(&hash_items_[0], 0, sizeof(hash_items_)); | 82 memset(&hash_items_[0], 0, sizeof(hash_items_)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 ScopedHashEntryFactory::~ScopedHashEntryFactory() { | 85 ScopedHashEntryFactory::~ScopedHashEntryFactory() { |
| 85 } | 86 } |
| 86 | 87 |
| 87 hentry* ScopedHashEntryFactory::CreateScopedHashEntry(int index, | 88 hentry* ScopedHashEntryFactory::CreateScopedHashEntry(int index, |
| 88 const hentry* source) { | 89 const hentry* source) { |
| 89 if (index >= MAX_ROOTS || source->blen >= kMaxWordLen || source->alen > 1) | 90 if (index >= MAX_ROOTS || source->blen >= kMaxWordLen) |
| 90 return NULL; | 91 return NULL; |
| 91 | 92 |
| 92 // Retrieve a HashEntryItem struct from our spool, initialize it, and | 93 // Retrieve a HashEntryItem struct from our spool, initialize it, and |
| 93 // returns the address of its 'hentry' member. | 94 // returns the address of its 'hentry' member. |
| 94 size_t source_size = sizeof(hentry) + source->blen + 1; | 95 size_t source_size = sizeof(hentry) + source->blen + 1; |
| 95 HashEntryItem* hash_item = &hash_items_[index]; | 96 HashEntryItem* hash_item = &hash_items_[index]; |
| 96 memcpy(&hash_item->entry, source, source_size); | 97 memcpy(&hash_item->entry, source, source_size); |
| 97 if (source->astr) { | 98 if (source->astr) { |
| 98 hash_item->astr = *source->astr; | 99 hash_item->entry.alen = source->alen; |
| 99 hash_item->entry.astr = &hash_item->astr; | 100 if (hash_item->entry.alen > kMaxAffixLen) |
| 101 hash_item->entry.alen = kMaxAffixLen; |
| 102 memcpy(hash_item->astr, source->astr, hash_item->entry.alen * sizeof(hash_it
em->astr[0])); |
| 103 hash_item->entry.astr = &hash_item->astr[0]; |
| 100 } | 104 } |
| 101 return &hash_item->entry; | 105 return &hash_item->entry; |
| 102 } | 106 } |
| 103 | 107 |
| 104 } // namespace | 108 } // namespace |
| 105 #endif | 109 #endif |
| 106 | 110 |
| 107 | 111 |
| 108 #ifdef HUNSPELL_CHROME_CLIENT | 112 #ifdef HUNSPELL_CHROME_CLIENT |
| 109 SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, | 113 SuggestMgr::SuggestMgr(hunspell::BDictReader* reader, |
| (...skipping 2041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 len++; | 2155 len++; |
| 2152 i--; | 2156 i--; |
| 2153 j--; | 2157 j--; |
| 2154 } else if (result[i*(n+1) + j] == LCS_UP) { | 2158 } else if (result[i*(n+1) + j] == LCS_UP) { |
| 2155 i--; | 2159 i--; |
| 2156 } else j--; | 2160 } else j--; |
| 2157 } | 2161 } |
| 2158 free(result); | 2162 free(result); |
| 2159 return len; | 2163 return len; |
| 2160 } | 2164 } |
| OLD | NEW |