OLD | NEW |
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 #ifndef BASE_SYS_STRING_CONVERSIONS_H_ | 5 #ifndef BASE_SYS_STRING_CONVERSIONS_H_ |
6 #define BASE_SYS_STRING_CONVERSIONS_H_ | 6 #define BASE_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. |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 | 14 |
15 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
16 #include <CoreFoundation/CoreFoundation.h> | 16 #include <CoreFoundation/CoreFoundation.h> |
| 17 #ifdef __OBJC__ |
| 18 @class NSString; |
| 19 #else |
| 20 class NSString; |
17 #endif | 21 #endif |
| 22 #endif // OS_MACOSX |
18 | 23 |
19 class StringPiece; | 24 class StringPiece; |
20 | 25 |
21 namespace base { | 26 namespace base { |
22 | 27 |
23 // Converts between wide and UTF-8 representations of a string. On error, the | 28 // Converts between wide and UTF-8 representations of a string. On error, the |
24 // result is system-dependent. | 29 // result is system-dependent. |
25 std::string SysWideToUTF8(const std::wstring& wide); | 30 std::string SysWideToUTF8(const std::wstring& wide); |
26 std::wstring SysUTF8ToWide(const StringPiece& utf8); | 31 std::wstring SysUTF8ToWide(const StringPiece& utf8); |
27 | 32 |
(...skipping 12 matching lines...) Expand all Loading... |
40 // MultiByteToWideChar(). | 45 // MultiByteToWideChar(). |
41 std::wstring SysMultiByteToWide(const StringPiece& mb, uint32 code_page); | 46 std::wstring SysMultiByteToWide(const StringPiece& mb, uint32 code_page); |
42 std::string SysWideToMultiByte(const std::wstring& wide, uint32 code_page); | 47 std::string SysWideToMultiByte(const std::wstring& wide, uint32 code_page); |
43 | 48 |
44 #endif // defined(OS_WIN) | 49 #endif // defined(OS_WIN) |
45 | 50 |
46 // Mac-specific ---------------------------------------------------------------- | 51 // Mac-specific ---------------------------------------------------------------- |
47 | 52 |
48 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
49 | 54 |
50 // Converts between STL strings and CFStringRefs. | 55 // Converts between STL strings and CFStringRefs/NSStrings. |
51 | 56 |
52 // Creates a string, and returns it with a refcount of 1. You are responsible | 57 // Creates a string, and returns it with a refcount of 1. You are responsible |
53 // for releasing it. Returns NULL on failure. | 58 // for releasing it. Returns NULL on failure. |
54 CFStringRef SysUTF8ToCFStringRef(const std::string& utf8); | 59 CFStringRef SysUTF8ToCFStringRef(const std::string& utf8); |
55 CFStringRef SysWideToCFStringRef(const std::wstring& wide); | 60 CFStringRef SysWideToCFStringRef(const std::wstring& wide); |
56 | 61 |
| 62 // Same, but returns an autoreleased NSString. |
| 63 NSString* SysUTF8ToNSString(const std::string& utf8); |
| 64 NSString* SysWideToNSString(const std::wstring& wide); |
| 65 |
57 // Converts a CFStringRef to an STL string. Returns an empty string on failure. | 66 // Converts a CFStringRef to an STL string. Returns an empty string on failure. |
58 std::string SysCFStringRefToUTF8(CFStringRef ref); | 67 std::string SysCFStringRefToUTF8(CFStringRef ref); |
59 std::wstring SysCFStringRefToWide(CFStringRef ref); | 68 std::wstring SysCFStringRefToWide(CFStringRef ref); |
60 | 69 |
| 70 // Same, but accepts NSString input. |
| 71 std::string SysNSStringToUTF8(NSString* ref); |
| 72 std::wstring SysNSStringToWide(NSString* ref); |
| 73 |
61 #endif // defined(OS_MACOSX) | 74 #endif // defined(OS_MACOSX) |
62 | 75 |
63 } // namespace base | 76 } // namespace base |
64 | 77 |
65 #endif // BASE_SYS_STRING_CONVERSIONS_H_ | 78 #endif // BASE_SYS_STRING_CONVERSIONS_H_ |
66 | |
OLD | NEW |