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

Side by Side Diff: base/string_util.h

Issue 11002: Make unit_tests pass with pt_BR.UTF-8 locale. (Closed)
Patch Set: all platforms Created 12 years, 1 month 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 | « base/json_writer.cc ('k') | base/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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 9
10 #include <string> 10 #include <string>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // - 'F', which is not identified by Windows wprintf documentation. 88 // - 'F', which is not identified by Windows wprintf documentation.
89 // - 'D', 'O', and 'U', which are deprecated and not available on all systems. 89 // - 'D', 'O', and 'U', which are deprecated and not available on all systems.
90 // Use %ld, %lo, and %lu instead. 90 // Use %ld, %lo, and %lu instead.
91 // 91 //
92 // Note that there is no portable conversion specifier for char data when 92 // Note that there is no portable conversion specifier for char data when
93 // working with wprintf. 93 // working with wprintf.
94 // 94 //
95 // This function is intended to be called from base::vswprintf. 95 // This function is intended to be called from base::vswprintf.
96 bool IsWprintfFormatPortable(const wchar_t* format); 96 bool IsWprintfFormatPortable(const wchar_t* format);
97 97
98 enum LocaleDependence {
99 LOCALE_DEPENDENT,
100 LOCALE_INDEPENDENT
101 };
102
103 std::string DoubleToString(double value, LocaleDependence locale_dependent);
104 std::wstring DoubleToWString(double value, LocaleDependence locale_dependent);
105
106 bool StringToDouble(const std::string& input, double* output,
107 LocaleDependence locale_dependent);
108 bool StringToDouble(const std::wstring& input, double* output,
109 LocaleDependence locale_dependent);
110 double StringToDouble(const std::string& value,
111 LocaleDependence locale_dependent);
112 double StringToDouble(const std::wstring& value,
113 LocaleDependence locale_dependent);
114
98 } // namespace base 115 } // namespace base
99 116
100 #if defined(OS_WIN) 117 #if defined(OS_WIN)
101 #include "base/string_util_win.h" 118 #include "base/string_util_win.h"
102 #elif defined(OS_POSIX) 119 #elif defined(OS_POSIX)
103 #include "base/string_util_posix.h" 120 #include "base/string_util_posix.h"
104 #else 121 #else
105 #error Define string operations appropriately for your platform 122 #error Define string operations appropriately for your platform
106 #endif 123 #endif
107 124
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Specialized string-conversion functions. 364 // Specialized string-conversion functions.
348 std::string IntToString(int value); 365 std::string IntToString(int value);
349 std::wstring IntToWString(int value); 366 std::wstring IntToWString(int value);
350 std::string UintToString(unsigned int value); 367 std::string UintToString(unsigned int value);
351 std::wstring UintToWString(unsigned int value); 368 std::wstring UintToWString(unsigned int value);
352 std::string Int64ToString(int64 value); 369 std::string Int64ToString(int64 value);
353 std::wstring Int64ToWString(int64 value); 370 std::wstring Int64ToWString(int64 value);
354 std::string Uint64ToString(uint64 value); 371 std::string Uint64ToString(uint64 value);
355 std::wstring Uint64ToWString(uint64 value); 372 std::wstring Uint64ToWString(uint64 value);
356 373
374
357 // Perform a best-effort conversion of the input string to a numeric type, 375 // Perform a best-effort conversion of the input string to a numeric type,
358 // setting |*output| to the result of the conversion. Returns true for 376 // setting |*output| to the result of the conversion. Returns true for
359 // "perfect" conversions; returns false in the following cases: 377 // "perfect" conversions; returns false in the following cases:
360 // - Overflow/underflow. |*output| will be set to the maximum value supported 378 // - Overflow/underflow. |*output| will be set to the maximum value supported
361 // by the data type. 379 // by the data type.
362 // - Trailing characters in the string after parsing the number. |*output| 380 // - Trailing characters in the string after parsing the number. |*output|
363 // will be set to the value of the number that was parsed. 381 // will be set to the value of the number that was parsed.
364 // - No characters parseable as a number at the beginning of the string. 382 // - No characters parseable as a number at the beginning of the string.
365 // |*output| will be set to 0. 383 // |*output| will be set to 0.
366 // - Empty string. |*output| will be set to 0. 384 // - Empty string. |*output| will be set to 0.
367 bool StringToInt(const std::string& input, int* output); 385 bool StringToInt(const std::string& input, int* output);
368 bool StringToInt(const std::wstring& input, int* output); 386 bool StringToInt(const std::wstring& input, int* output);
369 bool StringToInt64(const std::string& input, int64* output); 387 bool StringToInt64(const std::string& input, int64* output);
370 bool StringToInt64(const std::wstring& input, int64* output); 388 bool StringToInt64(const std::wstring& input, int64* output);
371 bool HexStringToInt(const std::string& input, int* output); 389 bool HexStringToInt(const std::string& input, int* output);
372 bool HexStringToInt(const std::wstring& input, int* output); 390 bool HexStringToInt(const std::wstring& input, int* output);
373 391
374 // For floating-point conversions, only conversions of input strings in decimal 392 // For floating-point conversions, only conversions of input strings in decimal
375 // form are defined to work. Behavior with strings representing floating-point 393 // form are defined to work. Behavior with strings representing floating-point
376 // numbers in hexadecimal, and strings representing non-fininte values (such 394 // numbers in hexadecimal, and strings representing non-fininte values (such
377 // as NaN and inf) is undefined. Otherwise, these behave the same as the 395 // as NaN and inf) is undefined. Otherwise, these behave the same as the
378 // integral variants above. 396 // integral variants above.
397 //
398 // By default, locale-dependent variant is used.
379 bool StringToDouble(const std::string& input, double* output); 399 bool StringToDouble(const std::string& input, double* output);
380 bool StringToDouble(const std::wstring& input, double* output); 400 bool StringToDouble(const std::wstring& input, double* output);
381 401
382 // Convenience forms of the above, when the caller is uninterested in the 402 // Convenience forms of the above, when the caller is uninterested in the
383 // boolean return value. These return only the |*output| value from the 403 // boolean return value. These return only the |*output| value from the
384 // above conversions: a best-effort conversion when possible, otherwise, 0. 404 // above conversions: a best-effort conversion when possible, otherwise, 0.
385 int StringToInt(const std::string& value); 405 int StringToInt(const std::string& value);
386 int StringToInt(const std::wstring& value); 406 int StringToInt(const std::wstring& value);
387 int64 StringToInt64(const std::string& value); 407 int64 StringToInt64(const std::string& value);
388 int64 StringToInt64(const std::wstring& value); 408 int64 StringToInt64(const std::wstring& value);
389 int HexStringToInt(const std::string& value); 409 int HexStringToInt(const std::string& value);
390 int HexStringToInt(const std::wstring& value); 410 int HexStringToInt(const std::wstring& value);
411 // By default, locale-dependent variant is used.
391 double StringToDouble(const std::string& value); 412 double StringToDouble(const std::string& value);
392 double StringToDouble(const std::wstring& value); 413 double StringToDouble(const std::wstring& value);
393 414
394 // Return a C++ string given printf-like input. 415 // Return a C++ string given printf-like input.
395 std::string StringPrintf(const char* format, ...); 416 std::string StringPrintf(const char* format, ...);
396 std::wstring StringPrintf(const wchar_t* format, ...); 417 std::wstring StringPrintf(const wchar_t* format, ...);
397 418
398 // Store result into a supplied string and return it 419 // Store result into a supplied string and return it
399 const std::string& SStringPrintf(std::string* dst, const char* format, ...); 420 const std::string& SStringPrintf(std::string* dst, const char* format, ...);
400 const std::wstring& SStringPrintf(std::wstring* dst, 421 const std::wstring& SStringPrintf(std::wstring* dst,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Returns true if the string passed in matches the pattern. The pattern 542 // Returns true if the string passed in matches the pattern. The pattern
522 // string can contain wildcards like * and ? 543 // string can contain wildcards like * and ?
523 // TODO(iyengar) This function may not work correctly for CJK strings as 544 // TODO(iyengar) This function may not work correctly for CJK strings as
524 // it does individual character matches. 545 // it does individual character matches.
525 // The backslash character (\) is an escape character for * and ? 546 // The backslash character (\) is an escape character for * and ?
526 bool MatchPattern(const std::wstring& string, const std::wstring& pattern); 547 bool MatchPattern(const std::wstring& string, const std::wstring& pattern);
527 bool MatchPattern(const std::string& string, const std::string& pattern); 548 bool MatchPattern(const std::string& string, const std::string& pattern);
528 549
529 #endif // BASE_STRING_UTIL_H_ 550 #endif // BASE_STRING_UTIL_H_
530 551
OLDNEW
« no previous file with comments | « base/json_writer.cc ('k') | base/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698