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 #include "base/sys_string_conversions.h" | 5 #include "base/sys_string_conversions.h" |
6 | 6 |
| 7 #import <Foundation/Foundation.h> |
| 8 |
7 #include <vector> | 9 #include <vector> |
8 | 10 |
| 11 #include "base/foundation_utils_mac.h" |
9 #include "base/scoped_cftyperef.h" | 12 #include "base/scoped_cftyperef.h" |
10 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
11 | 14 |
12 namespace base { | 15 namespace base { |
13 | 16 |
14 namespace { | 17 namespace { |
15 | 18 |
16 // Convert the supplied CFString into the specified encoding, and return it as | 19 // Convert the supplied CFString into the specified encoding, and return it as |
17 // an STL string of the template type. Returns an empty string on failure. | 20 // an STL string of the template type. Returns an empty string on failure. |
18 // | 21 // |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 151 } |
149 | 152 |
150 CFStringRef SysUTF8ToCFStringRef(const std::string& utf8) { | 153 CFStringRef SysUTF8ToCFStringRef(const std::string& utf8) { |
151 return STLStringToCFStringWithEncodingsT(utf8, kNarrowStringEncoding); | 154 return STLStringToCFStringWithEncodingsT(utf8, kNarrowStringEncoding); |
152 } | 155 } |
153 | 156 |
154 CFStringRef SysWideToCFStringRef(const std::wstring& wide) { | 157 CFStringRef SysWideToCFStringRef(const std::wstring& wide) { |
155 return STLStringToCFStringWithEncodingsT(wide, kWideStringEncoding); | 158 return STLStringToCFStringWithEncodingsT(wide, kWideStringEncoding); |
156 } | 159 } |
157 | 160 |
| 161 NSString* SysUTF8ToNSString(const std::string& utf8) { |
| 162 return CFTypeRefToNSObjectAutorelease(SysUTF8ToCFStringRef(utf8)); |
| 163 } |
| 164 |
| 165 NSString* SysWideToNSString(const std::wstring& wide) { |
| 166 return CFTypeRefToNSObjectAutorelease(SysWideToCFStringRef(wide)); |
| 167 } |
| 168 |
158 std::string SysCFStringRefToUTF8(CFStringRef ref) { | 169 std::string SysCFStringRefToUTF8(CFStringRef ref) { |
159 return CFStringToSTLStringWithEncodingT<std::string>(ref, | 170 return CFStringToSTLStringWithEncodingT<std::string>(ref, |
160 kNarrowStringEncoding); | 171 kNarrowStringEncoding); |
161 } | 172 } |
162 | 173 |
163 std::wstring SysCFStringRefToWide(CFStringRef ref) { | 174 std::wstring SysCFStringRefToWide(CFStringRef ref) { |
164 return CFStringToSTLStringWithEncodingT<std::wstring>(ref, | 175 return CFStringToSTLStringWithEncodingT<std::wstring>(ref, |
165 kWideStringEncoding); | 176 kWideStringEncoding); |
166 } | 177 } |
167 | 178 |
| 179 std::string SysNSStringToUTF8(NSString* nsstring) { |
| 180 return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring)); |
| 181 } |
| 182 |
| 183 std::wstring SysNSStringToWide(NSString* nsstring) { |
| 184 return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring)); |
| 185 } |
| 186 |
168 } // namespace base | 187 } // namespace base |
169 | |
OLD | NEW |