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

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

Issue 1200393002: Add more string_util functions to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string
Patch Set: Android 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 | « ash/system/user/login_status.cc ('k') | base/strings/string_util.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 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 inline bool IsUnicodeWhitespace(wchar_t c) { 410 inline bool IsUnicodeWhitespace(wchar_t c) {
411 return wcschr(base::kWhitespaceWide, c) != NULL; 411 return wcschr(base::kWhitespaceWide, c) != NULL;
412 } 412 }
413 413
414 // Return a byte string in human-readable format with a unit suffix. Not 414 // Return a byte string in human-readable format with a unit suffix. Not
415 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is 415 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is
416 // highly recommended instead. TODO(avi): Figure out how to get callers to use 416 // highly recommended instead. TODO(avi): Figure out how to get callers to use
417 // FormatBytes instead; remove this. 417 // FormatBytes instead; remove this.
418 BASE_EXPORT string16 FormatBytesUnlocalized(int64 bytes); 418 BASE_EXPORT string16 FormatBytesUnlocalized(int64 bytes);
419 419
420 } // namespace base
421
422 #if defined(OS_WIN)
423 #include "base/strings/string_util_win.h"
424 #elif defined(OS_POSIX)
425 #include "base/strings/string_util_posix.h"
426 #else
427 #error Define string operations appropriately for your platform
428 #endif
429
430 // Starting at |start_offset| (usually 0), replace the first instance of 420 // Starting at |start_offset| (usually 0), replace the first instance of
431 // |find_this| with |replace_with|. 421 // |find_this| with |replace_with|.
432 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( 422 BASE_EXPORT void ReplaceFirstSubstringAfterOffset(
433 base::string16* str, 423 base::string16* str,
434 size_t start_offset, 424 size_t start_offset,
435 const base::string16& find_this, 425 StringPiece16 find_this,
436 const base::string16& replace_with); 426 StringPiece16 replace_with);
437 BASE_EXPORT void ReplaceFirstSubstringAfterOffset( 427 BASE_EXPORT void ReplaceFirstSubstringAfterOffset(
438 std::string* str, 428 std::string* str,
439 size_t start_offset, 429 size_t start_offset,
440 const std::string& find_this, 430 StringPiece find_this,
441 const std::string& replace_with); 431 StringPiece replace_with);
442 432
443 // Starting at |start_offset| (usually 0), look through |str| and replace all 433 // Starting at |start_offset| (usually 0), look through |str| and replace all
444 // instances of |find_this| with |replace_with|. 434 // instances of |find_this| with |replace_with|.
445 // 435 //
446 // This does entire substrings; use std::replace in <algorithm> for single 436 // This does entire substrings; use std::replace in <algorithm> for single
447 // characters, for example: 437 // characters, for example:
448 // std::replace(str.begin(), str.end(), 'a', 'b'); 438 // std::replace(str.begin(), str.end(), 'a', 'b');
449 BASE_EXPORT void ReplaceSubstringsAfterOffset( 439 BASE_EXPORT void ReplaceSubstringsAfterOffset(
450 base::string16* str, 440 base::string16* str,
451 size_t start_offset, 441 size_t start_offset,
452 const base::string16& find_this, 442 StringPiece16 find_this,
453 const base::string16& replace_with); 443 StringPiece16 replace_with);
454 BASE_EXPORT void ReplaceSubstringsAfterOffset(std::string* str, 444 BASE_EXPORT void ReplaceSubstringsAfterOffset(
455 size_t start_offset, 445 std::string* str,
456 const std::string& find_this, 446 size_t start_offset,
457 const std::string& replace_with); 447 StringPiece find_this,
448 StringPiece replace_with);
449
450 } // namespace base
451
452 #if defined(OS_WIN)
453 #include "base/strings/string_util_win.h"
454 #elif defined(OS_POSIX)
455 #include "base/strings/string_util_posix.h"
456 #else
457 #error Define string operations appropriately for your platform
458 #endif
458 459
459 // Reserves enough memory in |str| to accommodate |length_with_null| characters, 460 // Reserves enough memory in |str| to accommodate |length_with_null| characters,
460 // sets the size of |str| to |length_with_null - 1| characters, and returns a 461 // sets the size of |str| to |length_with_null - 1| characters, and returns a
461 // pointer to the underlying contiguous array of characters. This is typically 462 // pointer to the underlying contiguous array of characters. This is typically
462 // used when calling a function that writes results into a character array, but 463 // used when calling a function that writes results into a character array, but
463 // the caller wants the data to be managed by a string-like object. It is 464 // the caller wants the data to be managed by a string-like object. It is
464 // convenient in that is can be used inline in the call, and fast in that it 465 // convenient in that is can be used inline in the call, and fast in that it
465 // avoids copying the results of the call from a char* into a string. 466 // avoids copying the results of the call from a char* into a string.
466 // 467 //
467 // |length_with_null| must be at least 2, since otherwise the underlying string 468 // |length_with_null| must be at least 2, since otherwise the underlying string
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // string can contain wildcards like * and ? 542 // string can contain wildcards like * and ?
542 // The backslash character (\) is an escape character for * and ? 543 // The backslash character (\) is an escape character for * and ?
543 // We limit the patterns to having a max of 16 * or ? characters. 544 // We limit the patterns to having a max of 16 * or ? characters.
544 // ? matches 0 or 1 character, while * matches 0 or more characters. 545 // ? matches 0 or 1 character, while * matches 0 or more characters.
545 BASE_EXPORT bool MatchPattern(const base::StringPiece& string, 546 BASE_EXPORT bool MatchPattern(const base::StringPiece& string,
546 const base::StringPiece& pattern); 547 const base::StringPiece& pattern);
547 BASE_EXPORT bool MatchPattern(const base::string16& string, 548 BASE_EXPORT bool MatchPattern(const base::string16& string,
548 const base::string16& pattern); 549 const base::string16& pattern);
549 550
550 #endif // BASE_STRINGS_STRING_UTIL_H_ 551 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « ash/system/user/login_status.cc ('k') | base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698