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

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

Issue 1092243002: Handle typographical apostrophe with spelling service client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Slight refactor. Created 5 years, 8 months 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
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck_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 #include "chrome/renderer/spellchecker/spellcheck.h" 5 #include "chrome/renderer/spellchecker/spellcheck.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/common/render_messages.h" 12 #include "chrome/common/render_messages.h"
11 #include "chrome/common/spellcheck_common.h" 13 #include "chrome/common/spellcheck_common.h"
12 #include "chrome/common/spellcheck_messages.h" 14 #include "chrome/common/spellcheck_messages.h"
13 #include "chrome/common/spellcheck_result.h" 15 #include "chrome/common/spellcheck_result.h"
14 #include "chrome/renderer/spellchecker/spellcheck_language.h" 16 #include "chrome/renderer/spellchecker/spellcheck_language.h"
15 #include "chrome/renderer/spellchecker/spellcheck_provider.h" 17 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
16 #include "content/public/renderer/render_thread.h" 18 #include "content/public/renderer/render_thread.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 const base::char16* text = line_text.c_str(); 388 const base::char16* text = line_text.c_str();
387 std::vector<WebTextCheckingResult> list; 389 std::vector<WebTextCheckingResult> list;
388 for (size_t i = 0; i < spellcheck_results.size(); ++i) { 390 for (size_t i = 0; i < spellcheck_results.size(); ++i) {
389 SpellCheckResult::Decoration decoration = spellcheck_results[i].decoration; 391 SpellCheckResult::Decoration decoration = spellcheck_results[i].decoration;
390 int word_location = spellcheck_results[i].location; 392 int word_location = spellcheck_results[i].location;
391 int word_length = spellcheck_results[i].length; 393 int word_length = spellcheck_results[i].length;
392 int misspelling_start = 0; 394 int misspelling_start = 0;
393 int misspelling_length = 0; 395 int misspelling_length = 0;
394 if (decoration == SpellCheckResult::SPELLING && 396 if (decoration == SpellCheckResult::SPELLING &&
395 filter == USE_NATIVE_CHECKER) { 397 filter == USE_NATIVE_CHECKER) {
398 // Ignore typographical apostrophe misspellings.
groby-ooo-7-16 2015/04/20 21:02:22 Eeew. Are all languages handling typographic apost
please use gerrit instead 2015/04/20 23:05:31 SpellcheckWordIterator says it's using ICU for wor
please use gerrit instead 2015/04/20 23:40:17 By the way, we can remove this hack once the serve
399 static const base::char16 kTypographicalApostrophe = 0x2019;
400 static const base::char16 kTypewriterApostrophe = 0x0027;
401 if (line_text.find(kTypographicalApostrophe, word_location) <
402 static_cast<size_t>(word_location + word_length)) {
403 base::string16 no_typographical_apostrophe(line_text, word_location,
404 word_length);
405 std::replace(no_typographical_apostrophe.begin(),
406 no_typographical_apostrophe.end(),
407 kTypographicalApostrophe, kTypewriterApostrophe);
408 if (no_typographical_apostrophe == spellcheck_results[i].replacement)
409 continue;
410 }
411
396 if (SpellCheckWord(text + word_location, word_length, 0, 412 if (SpellCheckWord(text + word_location, word_length, 0,
397 &misspelling_start, &misspelling_length, NULL)) { 413 &misspelling_start, &misspelling_length, NULL)) {
398 decoration = SpellCheckResult::GRAMMAR; 414 decoration = SpellCheckResult::GRAMMAR;
399 } 415 }
400 } 416 }
417
401 if (!custom_dictionary_.SpellCheckWord( 418 if (!custom_dictionary_.SpellCheckWord(
402 line_text, word_location, word_length)) { 419 line_text, word_location, word_length)) {
403 list.push_back(WebTextCheckingResult( 420 list.push_back(WebTextCheckingResult(
404 static_cast<WebTextDecorationType>(decoration), 421 static_cast<WebTextDecorationType>(decoration),
405 word_location + line_offset, 422 word_location + line_offset,
406 word_length, 423 word_length,
407 spellcheck_results[i].replacement, 424 spellcheck_results[i].replacement,
408 spellcheck_results[i].hash)); 425 spellcheck_results[i].hash));
409 } 426 }
410 } 427 }
411 textcheck_results->assign(list); 428 textcheck_results->assign(list);
412 } 429 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/spellchecker/spellcheck_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698