| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" |
| 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/renderer/spellchecker/spellcheck.h" |
| 12 #include "unicode/normlzr.h" | 17 #include "unicode/normlzr.h" |
| 13 #include "unicode/schriter.h" | 18 #include "unicode/schriter.h" |
| 14 #include "unicode/uscript.h" | 19 #include "unicode/uscript.h" |
| 15 #include "unicode/ulocdata.h" | 20 #include "unicode/ulocdata.h" |
| 16 | 21 |
| 17 #include "base/basictypes.h" | |
| 18 #include "base/logging.h" | |
| 19 #include "base/string_util.h" | |
| 20 #include "base/utf_string_conversions.h" | |
| 21 #include "chrome/renderer/spellchecker/spellcheck.h" | |
| 22 | |
| 23 // SpellcheckCharAttribute implementation: | 22 // SpellcheckCharAttribute implementation: |
| 24 | 23 |
| 25 SpellcheckCharAttribute::SpellcheckCharAttribute() | 24 SpellcheckCharAttribute::SpellcheckCharAttribute() |
| 26 : script_code_(USCRIPT_LATIN) { | 25 : script_code_(USCRIPT_LATIN) { |
| 27 } | 26 } |
| 28 | 27 |
| 29 SpellcheckCharAttribute::~SpellcheckCharAttribute() { | 28 SpellcheckCharAttribute::~SpellcheckCharAttribute() { |
| 30 } | 29 } |
| 31 | 30 |
| 32 void SpellcheckCharAttribute::SetDefaultLanguage(const std::string& language) { | 31 void SpellcheckCharAttribute::SetDefaultLanguage(const std::string& language) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (script_code_ == USCRIPT_HEBREW) | 161 if (script_code_ == USCRIPT_HEBREW) |
| 163 midletter_extra = kMidLetterExtraHebrew; | 162 midletter_extra = kMidLetterExtraHebrew; |
| 164 | 163 |
| 165 // Create two custom rule-sets: one allows contraction and the other does not. | 164 // Create two custom rule-sets: one allows contraction and the other does not. |
| 166 // We save these strings in UTF-16 so we can use it without conversions. (ICU | 165 // We save these strings in UTF-16 so we can use it without conversions. (ICU |
| 167 // needs UTF-16 strings.) | 166 // needs UTF-16 strings.) |
| 168 const char kAllowContraction[] = | 167 const char kAllowContraction[] = |
| 169 "$ALetterEx ($MidLetterEx | $MidNumLetEx) $ALetterEx {200};"; | 168 "$ALetterEx ($MidLetterEx | $MidNumLetEx) $ALetterEx {200};"; |
| 170 const char kDisallowContraction[] = ""; | 169 const char kDisallowContraction[] = ""; |
| 171 | 170 |
| 172 ruleset_allow_contraction_ = ASCIIToUTF16(StringPrintf(kRuleTemplate, | 171 ruleset_allow_contraction_ = ASCIIToUTF16( |
| 173 aletter, midletter_extra, aletter_plus, kAllowContraction)); | 172 base::StringPrintf(kRuleTemplate, |
| 174 ruleset_disallow_contraction_ = ASCIIToUTF16(StringPrintf(kRuleTemplate, | 173 aletter, |
| 175 aletter, midletter_extra, aletter_plus, kDisallowContraction)); | 174 midletter_extra, |
| 175 aletter_plus, |
| 176 kAllowContraction)); |
| 177 ruleset_disallow_contraction_ = ASCIIToUTF16( |
| 178 base::StringPrintf(kRuleTemplate, |
| 179 aletter, |
| 180 midletter_extra, |
| 181 aletter_plus, |
| 182 kDisallowContraction)); |
| 176 } | 183 } |
| 177 | 184 |
| 178 bool SpellcheckCharAttribute::OutputChar(UChar c, string16* output) const { | 185 bool SpellcheckCharAttribute::OutputChar(UChar c, string16* output) const { |
| 179 // Call the language-specific function if necessary. | 186 // Call the language-specific function if necessary. |
| 180 // Otherwise, we call the default one. | 187 // Otherwise, we call the default one. |
| 181 switch (script_code_) { | 188 switch (script_code_) { |
| 182 case USCRIPT_ARABIC: | 189 case USCRIPT_ARABIC: |
| 183 return OutputArabic(c, output); | 190 return OutputArabic(c, output); |
| 184 | 191 |
| 185 case USCRIPT_HANGUL: | 192 case USCRIPT_HANGUL: |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) | 381 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) |
| 375 return false; | 382 return false; |
| 376 | 383 |
| 377 // Copy the normalized text to the output. | 384 // Copy the normalized text to the output. |
| 378 icu::StringCharacterIterator it(output); | 385 icu::StringCharacterIterator it(output); |
| 379 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) | 386 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) |
| 380 attribute_->OutputChar(c, output_string); | 387 attribute_->OutputChar(c, output_string); |
| 381 | 388 |
| 382 return !output_string->empty(); | 389 return !output_string->empty(); |
| 383 } | 390 } |
| OLD | NEW |