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

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_language.cc

Issue 1269343005: Updates SpellcheckWordIterator::GetNextWord to return an enum. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@break-iter
Patch Set: Updates comments and preserves functionality in tests. Created 5 years, 4 months 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
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 "chrome/renderer/spellchecker/spellcheck_language.h" 5 #include "chrome/renderer/spellchecker/spellcheck_language.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" 8 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h"
9 #include "chrome/renderer/spellchecker/spelling_engine.h" 9 #include "chrome/renderer/spellchecker/spelling_engine.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 int word_length; 60 int word_length;
61 if (!text_iterator_.IsInitialized() && 61 if (!text_iterator_.IsInitialized() &&
62 !text_iterator_.Initialize(&character_attributes_, true)) { 62 !text_iterator_.Initialize(&character_attributes_, true)) {
63 // We failed to initialize text_iterator_, return as spelled correctly. 63 // We failed to initialize text_iterator_, return as spelled correctly.
64 VLOG(1) << "Failed to initialize SpellcheckWordIterator"; 64 VLOG(1) << "Failed to initialize SpellcheckWordIterator";
65 return true; 65 return true;
66 } 66 }
67 67
68 text_iterator_.SetText(in_word, in_word_len); 68 text_iterator_.SetText(in_word, in_word_len);
69 DCHECK(platform_spelling_engine_.get()); 69 DCHECK(platform_spelling_engine_.get());
70 while (text_iterator_.GetNextWord(&word, &word_start, &word_length)) { 70 SpellcheckWordIterator::WordIteratorStatus status =
71 text_iterator_.GetNextWord(&word, &word_start, &word_length);
72 while (status != SpellcheckWordIterator::IS_END_OF_TEXT) {
please use gerrit instead 2015/08/11 22:54:10 Is this loop easier to understand? Should be less
Julius 2015/08/12 20:25:59 Done.
73 // Found a character that is not able to be spellchecked so skip it.
74 if (status == SpellcheckWordIterator::IS_SKIPPABLE_CHAR) {
75 status = text_iterator_.GetNextWord(&word, &word_start, &word_length);
76 continue;
77 }
78
71 // Found a word (or a contraction) that the spellchecker can check the 79 // Found a word (or a contraction) that the spellchecker can check the
72 // spelling of. 80 // spelling of.
73 if (platform_spelling_engine_->CheckSpelling(word, tag)) 81 if (platform_spelling_engine_->CheckSpelling(word, tag)) {
82 status = text_iterator_.GetNextWord(&word, &word_start, &word_length);
74 continue; 83 continue;
84 }
75 85
76 // If the given word is a concatenated word of two or more valid words 86 // If the given word is a concatenated word of two or more valid words
77 // (e.g. "hello:hello"), we should treat it as a valid word. 87 // (e.g. "hello:hello"), we should treat it as a valid word.
78 if (IsValidContraction(word, tag)) 88 if (IsValidContraction(word, tag)) {
89 status = text_iterator_.GetNextWord(&word, &word_start, &word_length);
79 continue; 90 continue;
91 }
80 92
81 *misspelling_start = word_start; 93 *misspelling_start = word_start;
82 *misspelling_len = word_length; 94 *misspelling_len = word_length;
83 95
84 // Get the list of suggested words. 96 // Get the list of suggested words.
85 if (optional_suggestions) { 97 if (optional_suggestions) {
86 platform_spelling_engine_->FillSuggestionList(word, 98 platform_spelling_engine_->FillSuggestionList(word,
87 optional_suggestions); 99 optional_suggestions);
88 } 100 }
89 return false; 101 return false;
(...skipping 15 matching lines...) Expand all
105 return true; 117 return true;
106 } 118 }
107 119
108 contraction_iterator_.SetText(contraction.c_str(), contraction.length()); 120 contraction_iterator_.SetText(contraction.c_str(), contraction.length());
109 121
110 base::string16 word; 122 base::string16 word;
111 int word_start; 123 int word_start;
112 int word_length; 124 int word_length;
113 125
114 DCHECK(platform_spelling_engine_.get()); 126 DCHECK(platform_spelling_engine_.get());
115 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) { 127 SpellcheckWordIterator::WordIteratorStatus status =
128 contraction_iterator_.GetNextWord(&word, &word_start, &word_length);
129 while (status != SpellcheckWordIterator::IS_END_OF_TEXT) {
please use gerrit instead 2015/08/11 22:54:10 for loop again.
Julius 2015/08/12 20:25:59 Done.
116 if (!platform_spelling_engine_->CheckSpelling(word, tag)) 130 if (!platform_spelling_engine_->CheckSpelling(word, tag))
117 return false; 131 return false;
132 status =
133 contraction_iterator_.GetNextWord(&word, &word_start, &word_length);
118 } 134 }
119 return true; 135 return true;
120 } 136 }
121 137
122 bool SpellcheckLanguage::IsEnabled() { 138 bool SpellcheckLanguage::IsEnabled() {
123 DCHECK(platform_spelling_engine_.get()); 139 DCHECK(platform_spelling_engine_.get());
124 return platform_spelling_engine_->IsEnabled(); 140 return platform_spelling_engine_->IsEnabled();
125 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698