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

Side by Side Diff: components/spellcheck/renderer/hunspell_engine.cc

Issue 2544793003: [spellcheck] Updated Hunspell to 1.5.4 (Closed)
Patch Set: Updated patch with encoding change Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/spellcheck/renderer/spellcheck_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/spellcheck/renderer/hunspell_engine.h" 5 #include "components/spellcheck/renderer/hunspell_engine.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <utility> 10 #include <utility>
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // the user. 79 // the user.
80 bool word_correct = true; 80 bool word_correct = true;
81 std::string word_to_check_utf8(base::UTF16ToUTF8(word_to_check)); 81 std::string word_to_check_utf8(base::UTF16ToUTF8(word_to_check));
82 82
83 // Limit the size of checked words. 83 // Limit the size of checked words.
84 if (word_to_check_utf8.length() <= kMaxCheckedLen) { 84 if (word_to_check_utf8.length() <= kMaxCheckedLen) {
85 // If |hunspell_| is NULL here, an error has occurred, but it's better 85 // If |hunspell_| is NULL here, an error has occurred, but it's better
86 // to check rather than crash. 86 // to check rather than crash.
87 if (hunspell_.get()) { 87 if (hunspell_.get()) {
88 // |hunspell_->spell| returns 0 if the word is misspelled. 88 // |hunspell_->spell| returns 0 if the word is misspelled.
89 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); 89 word_correct = (hunspell_->spell(word_to_check_utf8) != 0);
90 } 90 }
91 } 91 }
92 92
93 return word_correct; 93 return word_correct;
94 } 94 }
95 95
96 void HunspellEngine::FillSuggestionList( 96 void HunspellEngine::FillSuggestionList(
97 const base::string16& wrong_word, 97 const base::string16& wrong_word,
98 std::vector<base::string16>* optional_suggestions) { 98 std::vector<base::string16>* optional_suggestions) {
99 std::string wrong_word_utf8(base::UTF16ToUTF8(wrong_word)); 99 std::string wrong_word_utf8(base::UTF16ToUTF8(wrong_word));
100 if (wrong_word_utf8.length() > kMaxSuggestLen) 100 if (wrong_word_utf8.length() > kMaxSuggestLen)
101 return; 101 return;
102 102
103 // If |hunspell_| is NULL here, an error has occurred, but it's better 103 // If |hunspell_| is NULL here, an error has occurred, but it's better
104 // to check rather than crash. 104 // to check rather than crash.
105 // TODO(groby): Technically, it's not. We should track down the issue. 105 // TODO(groby): Technically, it's not. We should track down the issue.
106 if (!hunspell_.get()) 106 if (!hunspell_.get())
107 return; 107 return;
108 108
109 char** suggestions = NULL; 109 std::vector<std::string> suggestions =
110 int number_of_suggestions = 110 hunspell_->suggest(wrong_word_utf8);
111 hunspell_->suggest(&suggestions, wrong_word_utf8.c_str());
112 111
113 // Populate the vector of WideStrings. 112 // Populate the vector of WideStrings.
114 for (int i = 0; i < number_of_suggestions; ++i) { 113 for (size_t i = 0; i < suggestions.size(); ++i) {
115 if (i < spellcheck::kMaxSuggestions) 114 if (i < spellcheck::kMaxSuggestions)
116 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i])); 115 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i]));
117 free(suggestions[i]);
118 } 116 }
119 if (suggestions != NULL)
120 free(suggestions);
121 } 117 }
122 118
123 bool HunspellEngine::InitializeIfNeeded() { 119 bool HunspellEngine::InitializeIfNeeded() {
124 if (!initialized_ && !dictionary_requested_) { 120 if (!initialized_ && !dictionary_requested_) {
125 // RenderThread will not exist in test. 121 // RenderThread will not exist in test.
126 if (RenderThread::Get()) 122 if (RenderThread::Get())
127 RenderThread::Get()->Send(new SpellCheckHostMsg_RequestDictionary); 123 RenderThread::Get()->Send(new SpellCheckHostMsg_RequestDictionary);
128 dictionary_requested_ = true; 124 dictionary_requested_ = true;
129 return true; 125 return true;
130 } 126 }
131 127
132 // Don't initialize if hunspell is disabled. 128 // Don't initialize if hunspell is disabled.
133 if (file_.IsValid()) 129 if (file_.IsValid())
134 InitializeHunspell(); 130 InitializeHunspell();
135 131
136 return !initialized_; 132 return !initialized_;
137 } 133 }
138 134
139 bool HunspellEngine::IsEnabled() { 135 bool HunspellEngine::IsEnabled() {
140 return hunspell_enabled_; 136 return hunspell_enabled_;
141 } 137 }
OLDNEW
« no previous file with comments | « no previous file | components/spellcheck/renderer/spellcheck_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698