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> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/foundation_utils_mac.h" | 11 #include "base/foundation_utils_mac.h" |
12 #include "base/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // 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 |
20 // 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. |
21 // | 21 // |
22 // Do not assert in this function since it is used by the asssertion code! | 22 // Do not assert in this function since it is used by the asssertion code! |
(...skipping 48 matching lines...) Loading... |
71 // Do not assert in this function since it is used by the asssertion code! | 71 // Do not assert in this function since it is used by the asssertion code! |
72 template<typename InStringType, typename OutStringType> | 72 template<typename InStringType, typename OutStringType> |
73 static OutStringType STLStringToSTLStringWithEncodingsT( | 73 static OutStringType STLStringToSTLStringWithEncodingsT( |
74 const InStringType& in, | 74 const InStringType& in, |
75 CFStringEncoding in_encoding, | 75 CFStringEncoding in_encoding, |
76 CFStringEncoding out_encoding) { | 76 CFStringEncoding out_encoding) { |
77 typename InStringType::size_type in_length = in.length(); | 77 typename InStringType::size_type in_length = in.length(); |
78 if (in_length == 0) | 78 if (in_length == 0) |
79 return OutStringType(); | 79 return OutStringType(); |
80 | 80 |
81 scoped_cftyperef<CFStringRef> cfstring( | 81 base::mac::ScopedCFTypeRef<CFStringRef> cfstring( |
82 CFStringCreateWithBytesNoCopy(NULL, | 82 CFStringCreateWithBytesNoCopy(NULL, |
83 reinterpret_cast<const UInt8*>(in.data()), | 83 reinterpret_cast<const UInt8*>(in.data()), |
84 in_length * | 84 in_length * |
85 sizeof(typename InStringType::value_type), | 85 sizeof(typename InStringType::value_type), |
86 in_encoding, | 86 in_encoding, |
87 false, | 87 false, |
88 kCFAllocatorNull)); | 88 kCFAllocatorNull)); |
89 if (!cfstring) | 89 if (!cfstring) |
90 return OutStringType(); | 90 return OutStringType(); |
91 | 91 |
(...skipping 103 matching lines...) Loading... |
195 return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring)); | 195 return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring)); |
196 } | 196 } |
197 | 197 |
198 std::wstring SysNSStringToWide(NSString* nsstring) { | 198 std::wstring SysNSStringToWide(NSString* nsstring) { |
199 if (!nsstring) | 199 if (!nsstring) |
200 return std::wstring(); | 200 return std::wstring(); |
201 return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring)); | 201 return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring)); |
202 } | 202 } |
203 | 203 |
204 } // namespace base | 204 } // namespace base |
OLD | NEW |