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

Side by Side Diff: chrome/browser/spellchecker/spelling_service_client.cc

Issue 1092243002: Handle typographical apostrophe with spelling service client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: base::char16 Created 5 years, 6 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/browser/spellchecker/spelling_service_client_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/browser/spellchecker/spelling_service_client.h" 5 #include "chrome/browser/spellchecker/spelling_service_client.h"
6 6
7 #include <algorithm>
8
7 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
8 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/stl_util.h" 13 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const PrefService* pref = user_prefs::UserPrefs::Get(context); 61 const PrefService* pref = user_prefs::UserPrefs::Get(context);
60 DCHECK(pref); 62 DCHECK(pref);
61 63
62 std::string language_code; 64 std::string language_code;
63 std::string country_code; 65 std::string country_code;
64 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale(
65 pref->GetString(prefs::kSpellCheckDictionary), 67 pref->GetString(prefs::kSpellCheckDictionary),
66 &language_code, 68 &language_code,
67 &country_code); 69 &country_code);
68 70
71 // Replace typographical apostrophes with typewriter apostrophes, so that
72 // server word breaker behaves correctly.
73 const base::char16 kApostrophe = 0x27;
74 const base::char16 kRightSingleQuotationMark = 0x2019;
75 base::string16 text_copy = text;
76 std::replace(text_copy.begin(), text_copy.end(), kRightSingleQuotationMark,
77 kApostrophe);
78
69 // Format the JSON request to be sent to the Spelling service. 79 // Format the JSON request to be sent to the Spelling service.
70 std::string encoded_text = base::GetQuotedJSONString(text); 80 std::string encoded_text = base::GetQuotedJSONString(text_copy);
71 81
72 static const char kSpellingRequest[] = 82 static const char kSpellingRequest[] =
73 "{" 83 "{"
74 "\"method\":\"spelling.check\"," 84 "\"method\":\"spelling.check\","
75 "\"apiVersion\":\"v%d\"," 85 "\"apiVersion\":\"v%d\","
76 "\"params\":{" 86 "\"params\":{"
77 "\"text\":%s," 87 "\"text\":%s,"
78 "\"language\":\"%s\"," 88 "\"language\":\"%s\","
79 "\"originCountry\":\"%s\"," 89 "\"originCountry\":\"%s\","
80 "\"key\":%s" 90 "\"key\":%s"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 260
251 // The callback may release the last (transitive) dependency on |this|. It 261 // The callback may release the last (transitive) dependency on |this|. It
252 // MUST be the last function called. 262 // MUST be the last function called.
253 callback_data->callback.Run(success, callback_data->text, results); 263 callback_data->callback.Run(success, callback_data->text, results);
254 } 264 }
255 265
256 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( 266 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher(
257 const GURL& url) { 267 const GURL& url) {
258 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 268 return net::URLFetcher::Create(url, net::URLFetcher::POST, this);
259 } 269 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/spellchecker/spelling_service_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698