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

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

Issue 10889002: Reset word iterators when changing the spellchecker language. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_worditerator.h ('k') | no next file » | 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 // Implements a custom word iterator used for our spellchecker. 5 // Implements a custom word iterator used for our spellchecker.
6 6
7 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" 7 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h"
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 SpellcheckWordIterator::SpellcheckWordIterator() 287 SpellcheckWordIterator::SpellcheckWordIterator()
288 : text_(NULL), 288 : text_(NULL),
289 length_(0), 289 length_(0),
290 position_(UBRK_DONE), 290 position_(UBRK_DONE),
291 attribute_(NULL), 291 attribute_(NULL),
292 iterator_(NULL) { 292 iterator_(NULL) {
293 } 293 }
294 294
295 SpellcheckWordIterator::~SpellcheckWordIterator() { 295 SpellcheckWordIterator::~SpellcheckWordIterator() {
296 Close(); 296 Reset();
297 } 297 }
298 298
299 bool SpellcheckWordIterator::Initialize( 299 bool SpellcheckWordIterator::Initialize(
300 const SpellcheckCharAttribute* attribute, 300 const SpellcheckCharAttribute* attribute,
301 bool allow_contraction) { 301 bool allow_contraction) {
302 // Create a custom ICU break iterator with empty text used in this object. (We 302 // Create a custom ICU break iterator with empty text used in this object. (We
303 // allow setting text later so we can re-use this iterator.) 303 // allow setting text later so we can re-use this iterator.)
304 DCHECK(attribute); 304 DCHECK(attribute);
305 UErrorCode open_status = U_ZERO_ERROR; 305 UErrorCode open_status = U_ZERO_ERROR;
306 UParseError parse_status; 306 UParseError parse_status;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 next = ubrk_next(iterator_); 373 next = ubrk_next(iterator_);
374 } 374 }
375 375
376 // There aren't any more words in the given text. Set the position to 376 // There aren't any more words in the given text. Set the position to
377 // UBRK_DONE to prevent from calling ubrk_next() next time when this function 377 // UBRK_DONE to prevent from calling ubrk_next() next time when this function
378 // is called. 378 // is called.
379 position_ = UBRK_DONE; 379 position_ = UBRK_DONE;
380 return false; 380 return false;
381 } 381 }
382 382
383 void SpellcheckWordIterator::Close() { 383 void SpellcheckWordIterator::Reset() {
384 if (iterator_) { 384 if (iterator_) {
385 ubrk_close(iterator_); 385 ubrk_close(iterator_);
386 iterator_ = NULL; 386 iterator_ = NULL;
387 } 387 }
388 } 388 }
389 389
390 bool SpellcheckWordIterator::Normalize(int input_start, 390 bool SpellcheckWordIterator::Normalize(int input_start,
391 int input_length, 391 int input_length,
392 string16* output_string) const { 392 string16* output_string) const {
393 // We use NFKC (Normalization Form, Compatible decomposition, followed by 393 // We use NFKC (Normalization Form, Compatible decomposition, followed by
(...skipping 10 matching lines...) Expand all
404 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) 404 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING)
405 return false; 405 return false;
406 406
407 // Copy the normalized text to the output. 407 // Copy the normalized text to the output.
408 icu::StringCharacterIterator it(output); 408 icu::StringCharacterIterator it(output);
409 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) 409 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next())
410 attribute_->OutputChar(c, output_string); 410 attribute_->OutputChar(c, output_string);
411 411
412 return !output_string->empty(); 412 return !output_string->empty();
413 } 413 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_worditerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698