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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_util.cc

Issue 296593003: Make various string_util functions take StringPieces instead of char[]. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resync Created 6 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 | Annotate | Revision Log
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/safe_browsing/safe_browsing_util.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::string url_unescaped_str(Unescape(url_without_fragment.spec())); 328 std::string url_unescaped_str(Unescape(url_without_fragment.spec()));
329 url::Parsed parsed; 329 url::Parsed parsed;
330 url::ParseStandardURL(url_unescaped_str.data(), url_unescaped_str.length(), 330 url::ParseStandardURL(url_unescaped_str.data(), url_unescaped_str.length(),
331 &parsed); 331 &parsed);
332 332
333 // 3. In hostname, remove all leading and trailing dots. 333 // 3. In hostname, remove all leading and trailing dots.
334 const std::string host = 334 const std::string host =
335 (parsed.host.len > 0) 335 (parsed.host.len > 0)
336 ? url_unescaped_str.substr(parsed.host.begin, parsed.host.len) 336 ? url_unescaped_str.substr(parsed.host.begin, parsed.host.len)
337 : std::string(); 337 : std::string();
338 const char kCharsToTrim[] = ".";
339 std::string host_without_end_dots; 338 std::string host_without_end_dots;
340 base::TrimString(host, kCharsToTrim, &host_without_end_dots); 339 base::TrimString(host, ".", &host_without_end_dots);
341 340
342 // 4. In hostname, replace consecutive dots with a single dot. 341 // 4. In hostname, replace consecutive dots with a single dot.
343 std::string host_without_consecutive_dots(RemoveConsecutiveChars( 342 std::string host_without_consecutive_dots(RemoveConsecutiveChars(
344 host_without_end_dots, '.')); 343 host_without_end_dots, '.'));
345 344
346 // 5. In path, replace runs of consecutive slashes with a single slash. 345 // 5. In path, replace runs of consecutive slashes with a single slash.
347 std::string path = 346 std::string path =
348 (parsed.path.len > 0) 347 (parsed.path.len > 0)
349 ? url_unescaped_str.substr(parsed.path.begin, parsed.path.len) 348 ? url_unescaped_str.substr(parsed.path.begin, parsed.path.len)
350 : std::string(); 349 : std::string();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); 527 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length);
529 return hash_out; 528 return hash_out;
530 } 529 }
531 530
532 std::string SBFullHashToString(const SBFullHash& hash) { 531 std::string SBFullHashToString(const SBFullHash& hash) {
533 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); 532 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash));
534 return std::string(hash.full_hash, sizeof(hash.full_hash)); 533 return std::string(hash.full_hash, sizeof(hash.full_hash));
535 } 534 }
536 535
537 } // namespace safe_browsing_util 536 } // namespace safe_browsing_util
OLDNEW
« no previous file with comments | « chrome/browser/renderer_context_menu/render_view_context_menu.cc ('k') | chrome/browser/ui/omnibox/location_bar_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698