OLD | NEW |
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 "chrome/renderer/spellchecker/hunspell_engine.h" | 5 #include "chrome/renderer/spellchecker/hunspell_engine.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 hunspell_.reset( | 67 hunspell_.reset( |
68 new Hunspell(bdict_file_->data(), bdict_file_->length())); | 68 new Hunspell(bdict_file_->data(), bdict_file_->length())); |
69 | 69 |
70 DHISTOGRAM_TIMES("Spellcheck.InitTime", | 70 DHISTOGRAM_TIMES("Spellcheck.InitTime", |
71 base::Histogram::DebugNow() - debug_start_time); | 71 base::Histogram::DebugNow() - debug_start_time); |
72 } else { | 72 } else { |
73 NOTREACHED() << "Could not mmap spellchecker dictionary."; | 73 NOTREACHED() << "Could not mmap spellchecker dictionary."; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 bool HunspellEngine::CheckSpelling(const string16& word_to_check, int tag) { | 77 bool HunspellEngine::CheckSpelling(const base::string16& word_to_check, |
| 78 int tag) { |
78 // Assume all words that cannot be checked are valid. Since Chrome can't | 79 // Assume all words that cannot be checked are valid. Since Chrome can't |
79 // offer suggestions on them, either, there's no point in flagging them to | 80 // offer suggestions on them, either, there's no point in flagging them to |
80 // the user. | 81 // the user. |
81 bool word_correct = true; | 82 bool word_correct = true; |
82 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); | 83 std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); |
83 | 84 |
84 // Limit the size of checked words. | 85 // Limit the size of checked words. |
85 if (word_to_check_utf8.length() <= kMaxCheckedLen) { | 86 if (word_to_check_utf8.length() <= kMaxCheckedLen) { |
86 // If |hunspell_| is NULL here, an error has occurred, but it's better | 87 // If |hunspell_| is NULL here, an error has occurred, but it's better |
87 // to check rather than crash. | 88 // to check rather than crash. |
88 if (hunspell_.get()) { | 89 if (hunspell_.get()) { |
89 // |hunspell_->spell| returns 0 if the word is misspelled. | 90 // |hunspell_->spell| returns 0 if the word is misspelled. |
90 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); | 91 word_correct = (hunspell_->spell(word_to_check_utf8.c_str()) != 0); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 return word_correct; | 95 return word_correct; |
95 } | 96 } |
96 | 97 |
97 void HunspellEngine::FillSuggestionList( | 98 void HunspellEngine::FillSuggestionList( |
98 const string16& wrong_word, | 99 const base::string16& wrong_word, |
99 std::vector<string16>* optional_suggestions) { | 100 std::vector<base::string16>* optional_suggestions) { |
100 std::string wrong_word_utf8(UTF16ToUTF8(wrong_word)); | 101 std::string wrong_word_utf8(UTF16ToUTF8(wrong_word)); |
101 if (wrong_word_utf8.length() > kMaxSuggestLen) | 102 if (wrong_word_utf8.length() > kMaxSuggestLen) |
102 return; | 103 return; |
103 | 104 |
104 // If |hunspell_| is NULL here, an error has occurred, but it's better | 105 // If |hunspell_| is NULL here, an error has occurred, but it's better |
105 // to check rather than crash. | 106 // to check rather than crash. |
106 // TODO(groby): Technically, it's not. We should track down the issue. | 107 // TODO(groby): Technically, it's not. We should track down the issue. |
107 if (!hunspell_.get()) | 108 if (!hunspell_.get()) |
108 return; | 109 return; |
109 | 110 |
(...skipping 23 matching lines...) Expand all Loading... |
133 // Don't initialize if hunspell is disabled. | 134 // Don't initialize if hunspell is disabled. |
134 if (file_ != base::kInvalidPlatformFileValue) | 135 if (file_ != base::kInvalidPlatformFileValue) |
135 InitializeHunspell(); | 136 InitializeHunspell(); |
136 | 137 |
137 return !initialized_; | 138 return !initialized_; |
138 } | 139 } |
139 | 140 |
140 bool HunspellEngine::IsEnabled() { | 141 bool HunspellEngine::IsEnabled() { |
141 return file_ != base::kInvalidPlatformFileValue; | 142 return file_ != base::kInvalidPlatformFileValue; |
142 } | 143 } |
OLD | NEW |