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

Side by Side Diff: base/strings/string_util.h

Issue 2691193002: Added StringPiece overloads for base::JoinString. (Closed)
Patch Set: Go back to single implementation and overload append function. Created 3 years, 10 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 | base/strings/string_util.cc » ('j') | base/strings/string_util.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRINGS_STRING_UTIL_H_ 7 #ifndef BASE_STRINGS_STRING_UTIL_H_
8 #define BASE_STRINGS_STRING_UTIL_H_ 8 #define BASE_STRINGS_STRING_UTIL_H_
9 9
10 #include <ctype.h> 10 #include <ctype.h>
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // immediately write over this memory, but there is no other way to set the size 422 // immediately write over this memory, but there is no other way to set the size
423 // of the string, and not doing that will mean people who access |str| rather 423 // of the string, and not doing that will mean people who access |str| rather
424 // than str.c_str() will get back a string of whatever size |str| had on entry 424 // than str.c_str() will get back a string of whatever size |str| had on entry
425 // to this function (probably 0). 425 // to this function (probably 0).
426 BASE_EXPORT char* WriteInto(std::string* str, size_t length_with_null); 426 BASE_EXPORT char* WriteInto(std::string* str, size_t length_with_null);
427 BASE_EXPORT char16* WriteInto(string16* str, size_t length_with_null); 427 BASE_EXPORT char16* WriteInto(string16* str, size_t length_with_null);
428 #ifndef OS_WIN 428 #ifndef OS_WIN
429 BASE_EXPORT wchar_t* WriteInto(std::wstring* str, size_t length_with_null); 429 BASE_EXPORT wchar_t* WriteInto(std::wstring* str, size_t length_with_null);
430 #endif 430 #endif
431 431
432 // Does the opposite of SplitString(). 432 // Does the opposite of SplitString()/SplitStringPiece(). Joins a vector or list
433 // of strings into a single string, inserting |separator| (which may be empty)
434 // in between all elements.
435 //
436 // Prefer the StringPiece variant if possible, to avoid unnecessary copying.
dcheng 2017/02/22 07:22:18 I don't think it prevents copies though? It all de
danakj 2017/02/22 15:10:46 Right, the setup code to make the vector may have
Matt Giuca 2017/02/23 04:48:06 Right, JoinString doesn't create any more/less cop
433 BASE_EXPORT std::string JoinString(const std::vector<std::string>& parts, 437 BASE_EXPORT std::string JoinString(const std::vector<std::string>& parts,
434 StringPiece separator); 438 StringPiece separator);
435 BASE_EXPORT string16 JoinString(const std::vector<string16>& parts, 439 BASE_EXPORT string16 JoinString(const std::vector<string16>& parts,
436 StringPiece16 separator); 440 StringPiece16 separator);
441 BASE_EXPORT std::string JoinString(const std::vector<StringPiece>& parts,
442 StringPiece separator);
443 BASE_EXPORT string16 JoinString(const std::vector<StringPiece16>& parts,
444 StringPiece16 separator);
445 // Explicit initializer_list overloads are required to break ambiguity when used
446 // with a literal initializer list (otherwise the compiler would not be able to
447 // decide between the two other overloads).
448 BASE_EXPORT std::string JoinString(
449 const std::initializer_list<StringPiece>& parts,
dcheng 2017/02/22 07:22:18 FWIW, it seems much more common to pass by value (
Matt Giuca 2017/02/23 04:48:06 Done.
450 StringPiece separator);
451 BASE_EXPORT string16
452 JoinString(const std::initializer_list<StringPiece16>& parts,
453 StringPiece16 separator);
437 454
438 // Replace $1-$2-$3..$9 in the format string with values from |subst|. 455 // Replace $1-$2-$3..$9 in the format string with values from |subst|.
439 // Additionally, any number of consecutive '$' characters is replaced by that 456 // Additionally, any number of consecutive '$' characters is replaced by that
440 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be 457 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be
441 // NULL. This only allows you to use up to nine replacements. 458 // NULL. This only allows you to use up to nine replacements.
442 BASE_EXPORT string16 ReplaceStringPlaceholders( 459 BASE_EXPORT string16 ReplaceStringPlaceholders(
443 const string16& format_string, 460 const string16& format_string,
444 const std::vector<string16>& subst, 461 const std::vector<string16>& subst,
445 std::vector<size_t>* offsets); 462 std::vector<size_t>* offsets);
446 463
(...skipping 11 matching lines...) Expand all
458 475
459 #if defined(OS_WIN) 476 #if defined(OS_WIN)
460 #include "base/strings/string_util_win.h" 477 #include "base/strings/string_util_win.h"
461 #elif defined(OS_POSIX) 478 #elif defined(OS_POSIX)
462 #include "base/strings/string_util_posix.h" 479 #include "base/strings/string_util_posix.h"
463 #else 480 #else
464 #error Define string operations appropriately for your platform 481 #error Define string operations appropriately for your platform
465 #endif 482 #endif
466 483
467 #endif // BASE_STRINGS_STRING_UTIL_H_ 484 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/strings/string_util.cc » ('j') | base/strings/string_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698