| 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> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/i18n/break_iterator.h" | 13 #include "base/i18n/break_iterator.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/renderer/spellchecker/spellcheck.h" | 18 #include "chrome/renderer/spellchecker/spellcheck.h" |
| 18 #include "third_party/icu/source/common/unicode/normlzr.h" | 19 #include "third_party/icu/source/common/unicode/normlzr.h" |
| 19 #include "third_party/icu/source/common/unicode/schriter.h" | 20 #include "third_party/icu/source/common/unicode/schriter.h" |
| 20 #include "third_party/icu/source/common/unicode/uscript.h" | 21 #include "third_party/icu/source/common/unicode/uscript.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 return false; | 328 return false; |
| 328 | 329 |
| 329 scoped_ptr<BreakIterator> iterator(new BreakIterator(base::string16(), rule)); | 330 scoped_ptr<BreakIterator> iterator(new BreakIterator(base::string16(), rule)); |
| 330 if (!iterator->Init()) { | 331 if (!iterator->Init()) { |
| 331 // Since we're not passing in any text, the only reason this could fail | 332 // Since we're not passing in any text, the only reason this could fail |
| 332 // is if we fail to parse the rules. Since the rules are hardcoded, | 333 // is if we fail to parse the rules. Since the rules are hardcoded, |
| 333 // that would be a bug in this class. | 334 // that would be a bug in this class. |
| 334 NOTREACHED() << "failed to open iterator (broken rules)"; | 335 NOTREACHED() << "failed to open iterator (broken rules)"; |
| 335 return false; | 336 return false; |
| 336 } | 337 } |
| 337 iterator_ = iterator.Pass(); | 338 iterator_ = std::move(iterator); |
| 338 | 339 |
| 339 // Set the character attributes so we can normalize the words extracted by | 340 // Set the character attributes so we can normalize the words extracted by |
| 340 // this iterator. | 341 // this iterator. |
| 341 attribute_ = attribute; | 342 attribute_ = attribute; |
| 342 return true; | 343 return true; |
| 343 } | 344 } |
| 344 | 345 |
| 345 bool SpellcheckWordIterator::IsInitialized() const { | 346 bool SpellcheckWordIterator::IsInitialized() const { |
| 346 // Return true iff we have an iterator. | 347 // Return true iff we have an iterator. |
| 347 return !!iterator_; | 348 return !!iterator_; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) | 430 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) |
| 430 return false; | 431 return false; |
| 431 | 432 |
| 432 // Copy the normalized text to the output. | 433 // Copy the normalized text to the output. |
| 433 icu::StringCharacterIterator it(output); | 434 icu::StringCharacterIterator it(output); |
| 434 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) | 435 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) |
| 435 attribute_->OutputChar(c, output_string); | 436 attribute_->OutputChar(c, output_string); |
| 436 | 437 |
| 437 return !output_string->empty(); | 438 return !output_string->empty(); |
| 438 } | 439 } |
| OLD | NEW |