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

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

Issue 11413054: [Spellcheck] Don't initialize SpellcheckWordIterator with empty rulesets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | « no previous file | chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc » ('j') | 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 305
306 bool SpellcheckWordIterator::Initialize( 306 bool SpellcheckWordIterator::Initialize(
307 const SpellcheckCharAttribute* attribute, 307 const SpellcheckCharAttribute* attribute,
308 bool allow_contraction) { 308 bool allow_contraction) {
309 // Create a custom ICU break iterator with empty text used in this object. (We 309 // Create a custom ICU break iterator with empty text used in this object. (We
310 // allow setting text later so we can re-use this iterator.) 310 // allow setting text later so we can re-use this iterator.)
311 DCHECK(attribute); 311 DCHECK(attribute);
312 UErrorCode open_status = U_ZERO_ERROR; 312 UErrorCode open_status = U_ZERO_ERROR;
313 UParseError parse_status; 313 UParseError parse_status;
314 string16 rule(attribute->GetRuleSet(allow_contraction)); 314 string16 rule(attribute->GetRuleSet(allow_contraction));
315
316 // If there is no rule set, the attributes were invalid.
317 if (rule.empty())
318 return false;
319
315 iterator_ = ubrk_openRules(rule.c_str(), rule.length(), NULL, 0, 320 iterator_ = ubrk_openRules(rule.c_str(), rule.length(), NULL, 0,
316 &parse_status, &open_status); 321 &parse_status, &open_status);
317 if (U_FAILURE(open_status)) 322 if (U_FAILURE(open_status))
318 return false; 323 return false;
319 324
320 // Set the character attributes so we can normalize the words extracted by 325 // Set the character attributes so we can normalize the words extracted by
321 // this iterator. 326 // this iterator.
322 attribute_ = attribute; 327 attribute_ = attribute;
323 return true; 328 return true;
324 } 329 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING) 416 if (status != U_ZERO_ERROR && status != U_STRING_NOT_TERMINATED_WARNING)
412 return false; 417 return false;
413 418
414 // Copy the normalized text to the output. 419 // Copy the normalized text to the output.
415 icu::StringCharacterIterator it(output); 420 icu::StringCharacterIterator it(output);
416 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next()) 421 for (UChar c = it.first(); c != icu::CharacterIterator::DONE; c = it.next())
417 attribute_->OutputChar(c, output_string); 422 attribute_->OutputChar(c, output_string);
418 423
419 return !output_string->empty(); 424 return !output_string->empty();
420 } 425 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck_worditerator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698