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

Side by Side Diff: base/string_util.h

Issue 7189076: Localize strings, speeds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright dates Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_STRING_UTIL_H_ 7 #ifndef BASE_STRING_UTIL_H_
8 #define BASE_STRING_UTIL_H_ 8 #define BASE_STRING_UTIL_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (c >= 'a' && c <= 'f') 400 if (c >= 'a' && c <= 'f')
401 return c - 'a' + 10; 401 return c - 'a' + 10;
402 return 0; 402 return 0;
403 } 403 }
404 404
405 // Returns true if it's a whitespace character. 405 // Returns true if it's a whitespace character.
406 inline bool IsWhitespace(wchar_t c) { 406 inline bool IsWhitespace(wchar_t c) {
407 return wcschr(kWhitespaceWide, c) != NULL; 407 return wcschr(kWhitespaceWide, c) != NULL;
408 } 408 }
409 409
410 enum DataUnits { 410 // Return a byte string in human-readable format with a unit suffix. Not
411 DATA_UNITS_BYTE = 0, 411 // appropriate for use in any UI; use of FormatBytes and friends in ui/base is
412 DATA_UNITS_KIBIBYTE, 412 // highly recommended instead. TODO(avi): Figure out how to get callers to use
413 DATA_UNITS_MEBIBYTE, 413 // FormatBytes instead; remove this.
Mark Mentovai 2011/06/22 20:24:11 Where is FormatBytes? It’s not in this file any lo
Avi (use Gerrit) 2011/06/22 20:27:37 It's in ui/base as noted.
Mark Mentovai 2011/06/22 20:29:23 Avi wrote:
414 DATA_UNITS_GIBIBYTE, 414 BASE_API string16 FormatBytesUnlocalized(int64 bytes);
415 };
416
417 // Return the unit type that is appropriate for displaying the amount of bytes
418 // passed in.
419 BASE_API DataUnits GetByteDisplayUnits(int64 bytes);
420
421 // Return a byte string in human-readable format, displayed in units appropriate
422 // specified by 'units', with an optional unit suffix.
423 // Ex: FormatBytes(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB"
424 // Ex: FormatBytes(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1"
425 BASE_API string16 FormatBytes(int64 bytes, DataUnits units, bool show_units);
426
427 // As above, but with "/s" units.
428 // Ex: FormatSpeed(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB/s"
429 // Ex: FormatSpeed(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1"
430 BASE_API string16 FormatSpeed(int64 bytes, DataUnits units, bool show_units);
431
432 // Return a number formated with separators in the user's locale way.
433 // Ex: FormatNumber(1234567) => 1,234,567
434 BASE_API string16 FormatNumber(int64 number);
435 415
436 // Starting at |start_offset| (usually 0), replace the first instance of 416 // Starting at |start_offset| (usually 0), replace the first instance of
437 // |find_this| with |replace_with|. 417 // |find_this| with |replace_with|.
438 BASE_API void ReplaceFirstSubstringAfterOffset(string16* str, 418 BASE_API void ReplaceFirstSubstringAfterOffset(string16* str,
439 string16::size_type start_offset, 419 string16::size_type start_offset,
440 const string16& find_this, 420 const string16& find_this,
441 const string16& replace_with); 421 const string16& replace_with);
442 BASE_API void ReplaceFirstSubstringAfterOffset( 422 BASE_API void ReplaceFirstSubstringAfterOffset(
443 std::string* str, 423 std::string* str,
444 std::string::size_type start_offset, 424 std::string::size_type start_offset,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 #elif defined(WCHAR_T_IS_UTF32) 535 #elif defined(WCHAR_T_IS_UTF32)
556 typedef uint32 Unsigned; 536 typedef uint32 Unsigned;
557 #endif 537 #endif
558 }; 538 };
559 template<> 539 template<>
560 struct ToUnsigned<short> { 540 struct ToUnsigned<short> {
561 typedef unsigned short Unsigned; 541 typedef unsigned short Unsigned;
562 }; 542 };
563 543
564 #endif // BASE_STRING_UTIL_H_ 544 #endif // BASE_STRING_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698