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_SYS_STRING_CONVERSIONS_H_ | 5 #ifndef BASE_STRINGS_SYS_STRING_CONVERSIONS_H_ |
6 #define BASE_STRINGS_SYS_STRING_CONVERSIONS_H_ | 6 #define BASE_STRINGS_SYS_STRING_CONVERSIONS_H_ |
7 | 7 |
8 // Provides system-dependent string type conversions for cases where it's | 8 // Provides system-dependent string type conversions for cases where it's |
9 // necessary to not use ICU. Generally, you should not need this in Chrome, | 9 // necessary to not use ICU. Generally, you should not need this in Chrome, |
10 // but it is used in some shared code. Dependencies should be minimal. | 10 // but it is used in some shared code. Dependencies should be minimal. |
(...skipping 20 matching lines...) Expand all Loading... |
31 // result is system-dependent. | 31 // result is system-dependent. |
32 BASE_EXPORT std::string SysWideToUTF8(const std::wstring& wide); | 32 BASE_EXPORT std::string SysWideToUTF8(const std::wstring& wide); |
33 BASE_EXPORT std::wstring SysUTF8ToWide(const StringPiece& utf8); | 33 BASE_EXPORT std::wstring SysUTF8ToWide(const StringPiece& utf8); |
34 | 34 |
35 // Converts between wide and the system multi-byte representations of a string. | 35 // Converts between wide and the system multi-byte representations of a string. |
36 // DANGER: This will lose information and can change (on Windows, this can | 36 // DANGER: This will lose information and can change (on Windows, this can |
37 // change between reboots). | 37 // change between reboots). |
38 BASE_EXPORT std::string SysWideToNativeMB(const std::wstring& wide); | 38 BASE_EXPORT std::string SysWideToNativeMB(const std::wstring& wide); |
39 BASE_EXPORT std::wstring SysNativeMBToWide(const StringPiece& native_mb); | 39 BASE_EXPORT std::wstring SysNativeMBToWide(const StringPiece& native_mb); |
40 | 40 |
41 // Windows-specific ------------------------------------------------------------ | |
42 | |
43 #if defined(OS_WIN) | |
44 | |
45 // Converts between 8-bit and wide strings, using the given code page. The | |
46 // code page identifier is one accepted by the Windows function | |
47 // MultiByteToWideChar(). | |
48 BASE_EXPORT std::wstring SysMultiByteToWide(const StringPiece& mb, | |
49 uint32 code_page); | |
50 BASE_EXPORT std::string SysWideToMultiByte(const std::wstring& wide, | |
51 uint32 code_page); | |
52 | |
53 #endif // defined(OS_WIN) | |
54 | |
55 // Mac-specific ---------------------------------------------------------------- | 41 // Mac-specific ---------------------------------------------------------------- |
56 | 42 |
57 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
58 | 44 |
59 // Converts between STL strings and CFStringRefs/NSStrings. | 45 // Converts between STL strings and CFStringRefs/NSStrings. |
60 | 46 |
61 // Creates a string, and returns it with a refcount of 1. You are responsible | 47 // Creates a string, and returns it with a refcount of 1. You are responsible |
62 // for releasing it. Returns NULL on failure. | 48 // for releasing it. Returns NULL on failure. |
63 BASE_EXPORT CFStringRef SysUTF8ToCFStringRef(const std::string& utf8); | 49 BASE_EXPORT CFStringRef SysUTF8ToCFStringRef(const std::string& utf8); |
64 BASE_EXPORT CFStringRef SysUTF16ToCFStringRef(const string16& utf16); | 50 BASE_EXPORT CFStringRef SysUTF16ToCFStringRef(const string16& utf16); |
65 | 51 |
66 // Same, but returns an autoreleased NSString. | 52 // Same, but returns an autoreleased NSString. |
67 BASE_EXPORT NSString* SysUTF8ToNSString(const std::string& utf8); | 53 BASE_EXPORT NSString* SysUTF8ToNSString(const std::string& utf8); |
68 BASE_EXPORT NSString* SysUTF16ToNSString(const string16& utf16); | 54 BASE_EXPORT NSString* SysUTF16ToNSString(const string16& utf16); |
69 | 55 |
70 // Converts a CFStringRef to an STL string. Returns an empty string on failure. | 56 // Converts a CFStringRef to an STL string. Returns an empty string on failure. |
71 BASE_EXPORT std::string SysCFStringRefToUTF8(CFStringRef ref); | 57 BASE_EXPORT std::string SysCFStringRefToUTF8(CFStringRef ref); |
72 BASE_EXPORT string16 SysCFStringRefToUTF16(CFStringRef ref); | 58 BASE_EXPORT string16 SysCFStringRefToUTF16(CFStringRef ref); |
73 | 59 |
74 // Same, but accepts NSString input. Converts nil NSString* to the appropriate | 60 // Same, but accepts NSString input. Converts nil NSString* to the appropriate |
75 // string type of length 0. | 61 // string type of length 0. |
76 BASE_EXPORT std::string SysNSStringToUTF8(NSString* ref); | 62 BASE_EXPORT std::string SysNSStringToUTF8(NSString* ref); |
77 BASE_EXPORT string16 SysNSStringToUTF16(NSString* ref); | 63 BASE_EXPORT string16 SysNSStringToUTF16(NSString* ref); |
78 | 64 |
79 #endif // defined(OS_MACOSX) | 65 #endif // defined(OS_MACOSX) |
80 | 66 |
81 } // namespace base | 67 } // namespace base |
82 | 68 |
83 #endif // BASE_STRINGS_SYS_STRING_CONVERSIONS_H_ | 69 #endif // BASE_STRINGS_SYS_STRING_CONVERSIONS_H_ |
OLD | NEW |