| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 "$CR = [\\p{Word_Break = CR}];" | 57 "$CR = [\\p{Word_Break = CR}];" |
| 58 "$LF = [\\p{Word_Break = LF}];" | 58 "$LF = [\\p{Word_Break = LF}];" |
| 59 "$Newline = [\\p{Word_Break = Newline}];" | 59 "$Newline = [\\p{Word_Break = Newline}];" |
| 60 "$Extend = [\\p{Word_Break = Extend}];" | 60 "$Extend = [\\p{Word_Break = Extend}];" |
| 61 "$Format = [\\p{Word_Break = Format}];" | 61 "$Format = [\\p{Word_Break = Format}];" |
| 62 "$Katakana = [\\p{Word_Break = Katakana}];" | 62 "$Katakana = [\\p{Word_Break = Katakana}];" |
| 63 // Not all the characters in a given script are ALetter. | 63 // Not all the characters in a given script are ALetter. |
| 64 // For instance, U+05F4 is MidLetter. So, this may be | 64 // For instance, U+05F4 is MidLetter. So, this may be |
| 65 // better, but it leads to an empty set error in Thai. | 65 // better, but it leads to an empty set error in Thai. |
| 66 // "$ALetter = [[\\p{script=%s}] & [\\p{Word_Break = ALetter}]];" | 66 // "$ALetter = [[\\p{script=%s}] & [\\p{Word_Break = ALetter}]];" |
| 67 "$ALetter = [\\p{script=%s} [0123456789]];" | 67 "$ALetter = [\\p{script=%s}%s];" |
| 68 "$MidNumLet = [\\p{Word_Break = MidNumLet}];" | 68 "$MidNumLet = [\\p{Word_Break = MidNumLet}];" |
| 69 "$MidLetter = [\\p{Word_Break = MidLetter}%s];" | 69 "$MidLetter = [\\p{Word_Break = MidLetter}%s];" |
| 70 "$MidNum = [\\p{Word_Break = MidNum}];" | 70 "$MidNum = [\\p{Word_Break = MidNum}];" |
| 71 "$Numeric = [\\p{Word_Break = Numeric}];" | 71 "$Numeric = [\\p{Word_Break = Numeric}];" |
| 72 "$ExtendNumLet = [\\p{Word_Break = ExtendNumLet}];" | 72 "$ExtendNumLet = [\\p{Word_Break = ExtendNumLet}];" |
| 73 | 73 |
| 74 "$Control = [\\p{Grapheme_Cluster_Break = Control}]; " | 74 "$Control = [\\p{Grapheme_Cluster_Break = Control}]; " |
| 75 "%s" // ALetterPlus | 75 "%s" // ALetterPlus |
| 76 | 76 |
| 77 "$KatakanaEx = $Katakana ($Extend | $Format)*;" | 77 "$KatakanaEx = $Katakana ($Extend | $Format)*;" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 aletter = "Latin"; | 147 aletter = "Latin"; |
| 148 | 148 |
| 149 const char kWithDictionary[] = | 149 const char kWithDictionary[] = |
| 150 "$dictionary = [:LineBreak = Complex_Context:];" | 150 "$dictionary = [:LineBreak = Complex_Context:];" |
| 151 "$ALetterPlus = [$ALetter [$dictionary-$Extend-$Control]];"; | 151 "$ALetterPlus = [$ALetter [$dictionary-$Extend-$Control]];"; |
| 152 const char kWithoutDictionary[] = "$ALetterPlus = $ALetter;"; | 152 const char kWithoutDictionary[] = "$ALetterPlus = $ALetter;"; |
| 153 const char* aletter_plus = kWithoutDictionary; | 153 const char* aletter_plus = kWithoutDictionary; |
| 154 if (script_code_ == USCRIPT_HANGUL || script_code_ == USCRIPT_THAI) | 154 if (script_code_ == USCRIPT_HANGUL || script_code_ == USCRIPT_THAI) |
| 155 aletter_plus = kWithDictionary; | 155 aletter_plus = kWithDictionary; |
| 156 | 156 |
| 157 // Treat numbers as word characters except for Arabic and Hebrew. |
| 158 const char* aletter_extra = " [0123456789]"; |
| 159 if (script_code_ == USCRIPT_HEBREW || script_code_ == USCRIPT_ARABIC) |
| 160 aletter_extra = ""; |
| 161 |
| 157 const char kMidLetterExtra[] = ""; | 162 const char kMidLetterExtra[] = ""; |
| 158 // For Hebrew, treat single/double quoation marks as MidLetter. | 163 // For Hebrew, treat single/double quoation marks as MidLetter. |
| 159 const char kMidLetterExtraHebrew[] = "\"'"; | 164 const char kMidLetterExtraHebrew[] = "\"'"; |
| 160 const char* midletter_extra = kMidLetterExtra; | 165 const char* midletter_extra = kMidLetterExtra; |
| 161 if (script_code_ == USCRIPT_HEBREW) | 166 if (script_code_ == USCRIPT_HEBREW) |
| 162 midletter_extra = kMidLetterExtraHebrew; | 167 midletter_extra = kMidLetterExtraHebrew; |
| 163 | 168 |
| 164 // Create two custom rule-sets: one allows contraction and the other does not. | 169 // Create two custom rule-sets: one allows contraction and the other does not. |
| 165 // We save these strings in UTF-16 so we can use it without conversions. (ICU | 170 // We save these strings in UTF-16 so we can use it without conversions. (ICU |
| 166 // needs UTF-16 strings.) | 171 // needs UTF-16 strings.) |
| 167 const char kAllowContraction[] = | 172 const char kAllowContraction[] = |
| 168 "$ALetterEx ($MidLetterEx | $MidNumLetEx) $ALetterEx {200};"; | 173 "$ALetterEx ($MidLetterEx | $MidNumLetEx) $ALetterEx {200};"; |
| 169 const char kDisallowContraction[] = ""; | 174 const char kDisallowContraction[] = ""; |
| 170 | 175 |
| 171 ruleset_allow_contraction_ = ASCIIToUTF16( | 176 ruleset_allow_contraction_ = ASCIIToUTF16( |
| 172 base::StringPrintf(kRuleTemplate, | 177 base::StringPrintf(kRuleTemplate, |
| 173 aletter, | 178 aletter, |
| 179 aletter_extra, |
| 174 midletter_extra, | 180 midletter_extra, |
| 175 aletter_plus, | 181 aletter_plus, |
| 176 kAllowContraction)); | 182 kAllowContraction)); |
| 177 ruleset_disallow_contraction_ = ASCIIToUTF16( | 183 ruleset_disallow_contraction_ = ASCIIToUTF16( |
| 178 base::StringPrintf(kRuleTemplate, | 184 base::StringPrintf(kRuleTemplate, |
| 179 aletter, | 185 aletter, |
| 186 aletter_extra, |
| 180 midletter_extra, | 187 midletter_extra, |
| 181 aletter_plus, | 188 aletter_plus, |
| 182 kDisallowContraction)); | 189 kDisallowContraction)); |
| 183 } | 190 } |
| 184 | 191 |
| 185 bool SpellcheckCharAttribute::OutputChar(UChar c, string16* output) const { | 192 bool SpellcheckCharAttribute::OutputChar(UChar c, string16* output) const { |
| 186 // Call the language-specific function if necessary. | 193 // Call the language-specific function if necessary. |
| 187 // Otherwise, we call the default one. | 194 // Otherwise, we call the default one. |
| 188 switch (script_code_) { | 195 switch (script_code_) { |
| 189 case USCRIPT_ARABIC: | 196 case USCRIPT_ARABIC: |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) | 411 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) |
| 405 return false; | 412 return false; |
| 406 | 413 |
| 407 // Copy the normalized text to the output. | 414 // Copy the normalized text to the output. |
| 408 icu::StringCharacterIterator it(output); | 415 icu::StringCharacterIterator it(output); |
| 409 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) | 416 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) |
| 410 attribute_->OutputChar(c, output_string); | 417 attribute_->OutputChar(c, output_string); |
| 411 | 418 |
| 412 return !output_string->empty(); | 419 return !output_string->empty(); |
| 413 } | 420 } |
| OLD | NEW |