Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: base/strings/sys_string_conversions_mac.mm

Issue 16917011: mac: Replace base::mac::ScopedCFTypeRef with base::ScopedCFTypeRef. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with fixed off-by-1 in git-clang-format Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/native_library_mac.mm ('k') | base/time_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/strings/sys_string_conversions.h" 5 #include "base/strings/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
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::mac::ScopedCFTypeRef<CFStringRef> cfstring( 81 base::ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy(
82 CFStringCreateWithBytesNoCopy(NULL, 82 NULL,
83 reinterpret_cast<const UInt8*>(in.data()), 83 reinterpret_cast<const UInt8*>(in.data()),
84 in_length * 84 in_length * sizeof(typename InStringType::value_type),
85 sizeof(typename InStringType::value_type), 85 in_encoding,
86 in_encoding, 86 false,
87 false, 87 kCFAllocatorNull));
88 kCFAllocatorNull));
89 if (!cfstring) 88 if (!cfstring)
90 return OutStringType(); 89 return OutStringType();
91 90
92 return CFStringToSTLStringWithEncodingT<OutStringType>(cfstring, 91 return CFStringToSTLStringWithEncodingT<OutStringType>(cfstring,
93 out_encoding); 92 out_encoding);
94 } 93 }
95 94
96 // Given an STL string |in| with an encoding specified by |in_encoding|, 95 // Given an STL string |in| with an encoding specified by |in_encoding|,
97 // return it as a CFStringRef. Returns NULL on failure. 96 // return it as a CFStringRef. Returns NULL on failure.
98 template<typename StringType> 97 template<typename StringType>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring)); 177 return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring));
179 } 178 }
180 179
181 string16 SysNSStringToUTF16(NSString* nsstring) { 180 string16 SysNSStringToUTF16(NSString* nsstring) {
182 if (!nsstring) 181 if (!nsstring)
183 return string16(); 182 return string16();
184 return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring)); 183 return SysCFStringRefToUTF16(reinterpret_cast<CFStringRef>(nsstring));
185 } 184 }
186 185
187 } // namespace base 186 } // namespace base
OLDNEW
« no previous file with comments | « base/native_library_mac.mm ('k') | base/time_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698