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 // 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 373 } |
374 | 374 |
375 // Find a word that can be checked for spelling. Our rule sets filter out | 375 // Find a word that can be checked for spelling. Our rule sets filter out |
376 // invalid words (e.g. numbers and characters not supported by the | 376 // invalid words (e.g. numbers and characters not supported by the |
377 // spellchecker language) so this ubrk_getRuleStatus() call returns | 377 // spellchecker language) so this ubrk_getRuleStatus() call returns |
378 // UBRK_WORD_NONE when this iterator finds an invalid word. So, we skip such | 378 // UBRK_WORD_NONE when this iterator finds an invalid word. So, we skip such |
379 // words until we can find a valid word or reach the end of the input string. | 379 // words until we can find a valid word or reach the end of the input string. |
380 while (iterator_->Advance()) { | 380 while (iterator_->Advance()) { |
381 const size_t start = iterator_->prev(); | 381 const size_t start = iterator_->prev(); |
382 const size_t length = iterator_->pos() - start; | 382 const size_t length = iterator_->pos() - start; |
383 if (iterator_->IsWord()) { | 383 if (iterator_->IsWordBreak() == base::i18n::BreakIterator::IS_WORD_BREAK) { |
384 if (Normalize(start, length, word_string)) { | 384 if (Normalize(start, length, word_string)) { |
385 *word_start = start; | 385 *word_start = start; |
386 *word_length = length; | 386 *word_length = length; |
387 return true; | 387 return true; |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 // There aren't any more words in the given text. | 392 // There aren't any more words in the given text. |
393 return false; | 393 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
414 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) | 414 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) |
415 return false; | 415 return false; |
416 | 416 |
417 // Copy the normalized text to the output. | 417 // Copy the normalized text to the output. |
418 icu::StringCharacterIterator it(output); | 418 icu::StringCharacterIterator it(output); |
419 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) | 419 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) |
420 attribute_->OutputChar(c, output_string); | 420 attribute_->OutputChar(c, output_string); |
421 | 421 |
422 return !output_string->empty(); | 422 return !output_string->empty(); |
423 } | 423 } |
OLD | NEW |