OLD | NEW |
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 #ifndef BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ | 5 #ifndef BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ |
6 #define BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ | 6 #define BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 | 17 |
18 // ---------------------------------------------------------------------------- | 18 // ---------------------------------------------------------------------------- |
19 // IMPORTANT MESSAGE FROM YOUR SPONSOR | 19 // IMPORTANT MESSAGE FROM YOUR SPONSOR |
20 // | 20 // |
21 // This file contains no "wstring" variants. New code should use string16. If | 21 // This file contains no "wstring" variants. New code should use string16. If |
22 // you need to make old code work, use the UTF8 version and convert. Please do | 22 // you need to make old code work, use the UTF8 version and convert. Please do |
23 // not add wstring variants. | 23 // not add wstring variants. |
24 // | 24 // |
25 // Please do not add "convenience" functions for converting strings to integers | 25 // Please do not add "convenience" functions for converting strings to integers |
26 // that return the value and ignore success/failure. That encourages people to | 26 // that return the value and ignore success/failure. That encourages people to |
27 // write code that doesn't properly handle the error conditions. | 27 // write code that doesn't properly handle the error conditions. |
| 28 // |
| 29 // DO NOT use these functions in any UI unless it's NOT localized on purpose. |
| 30 // Instead, use base::MessageFormatter for a complex message with numbers |
| 31 // (integer, float, double) embedded or base::Format{Number,Double,Percent} to |
| 32 // just format a single number/percent. Note that some languages use native |
| 33 // digits instead of ASCII digits while others use a group separator or decimal |
| 34 // point different from ',' and '.'. Using these functions in the UI would lead |
| 35 // numbers to be formatted in a non-native way. |
28 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
29 | 37 |
30 namespace base { | 38 namespace base { |
31 | 39 |
32 // Number -> string conversions ------------------------------------------------ | 40 // Number -> string conversions ------------------------------------------------ |
33 | 41 |
34 BASE_EXPORT std::string IntToString(int value); | 42 BASE_EXPORT std::string IntToString(int value); |
35 BASE_EXPORT string16 IntToString16(int value); | 43 BASE_EXPORT string16 IntToString16(int value); |
36 | 44 |
37 BASE_EXPORT std::string UintToString(unsigned value); | 45 BASE_EXPORT std::string UintToString(unsigned value); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Similar to the previous functions, except that output is a vector of bytes. | 136 // Similar to the previous functions, except that output is a vector of bytes. |
129 // |*output| will contain as many bytes as were successfully parsed prior to the | 137 // |*output| will contain as many bytes as were successfully parsed prior to the |
130 // error. There is no overflow, but input.size() must be evenly divisible by 2. | 138 // error. There is no overflow, but input.size() must be evenly divisible by 2. |
131 // Leading 0x or +/- are not allowed. | 139 // Leading 0x or +/- are not allowed. |
132 BASE_EXPORT bool HexStringToBytes(const std::string& input, | 140 BASE_EXPORT bool HexStringToBytes(const std::string& input, |
133 std::vector<uint8_t>* output); | 141 std::vector<uint8_t>* output); |
134 | 142 |
135 } // namespace base | 143 } // namespace base |
136 | 144 |
137 #endif // BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ | 145 #endif // BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_ |
OLD | NEW |