OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #if defined(WEBRTC_MAC) || defined(WEBRTC_IOS) | 11 #if defined(WEBRTC_MAC) || defined(WEBRTC_IOS) |
12 | 12 |
13 #include <CoreFoundation/CoreFoundation.h> | 13 #include <CoreFoundation/CoreFoundation.h> |
14 | 14 |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 #include "webrtc/base/macconversion.h" | 16 #include "webrtc/base/macconversion.h" |
17 | 17 |
18 bool p_convertHostCFStringRefToCPPString( | 18 bool p_convertHostCFStringRefToCPPString( |
19 const CFStringRef cfstr, std::string& cppstr) { | 19 const CFStringRef cfstr, std::string& cppstr) { |
20 bool result = false; | 20 bool result = false; |
21 | 21 |
22 // First this must be non-null, | 22 // First this must be non-null, |
23 if (NULL != cfstr) { | 23 if (nullptr != cfstr) { |
24 // it must actually *be* a CFString, and not something just masquerading | 24 // it must actually *be* a CFString, and not something just masquerading |
25 // as one, | 25 // as one, |
26 if (CFGetTypeID(cfstr) == CFStringGetTypeID()) { | 26 if (CFGetTypeID(cfstr) == CFStringGetTypeID()) { |
27 // and we must be able to get the characters out of it. | 27 // and we must be able to get the characters out of it. |
28 // (The cfstr owns this buffer; it came from somewhere else, | 28 // (The cfstr owns this buffer; it came from somewhere else, |
29 // so someone else gets to take care of getting rid of the cfstr, | 29 // so someone else gets to take care of getting rid of the cfstr, |
30 // and then this buffer will go away automatically.) | 30 // and then this buffer will go away automatically.) |
31 unsigned length = CFStringGetLength(cfstr); | 31 unsigned length = CFStringGetLength(cfstr); |
32 char* buf = new char[1 + length]; | 32 char* buf = new char[1 + length]; |
33 if (CFStringGetCString(cfstr, buf, 1 + length, kCFStringEncodingASCII)) { | 33 if (CFStringGetCString(cfstr, buf, 1 + length, kCFStringEncodingASCII)) { |
34 if (strlen(buf) == length) { | 34 if (strlen(buf) == length) { |
35 cppstr.assign(buf); | 35 cppstr.assign(buf); |
36 result = true; | 36 result = true; |
37 } | 37 } |
38 } | 38 } |
39 delete [] buf; | 39 delete [] buf; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 bool p_convertCFNumberToInt(CFNumberRef cfn, int* i) { | 46 bool p_convertCFNumberToInt(CFNumberRef cfn, int* i) { |
47 bool converted = false; | 47 bool converted = false; |
48 | 48 |
49 // It must not be null. | 49 // It must not be null. |
50 if (NULL != cfn) { | 50 if (nullptr != cfn) { |
51 // It must actually *be* a CFNumber and not something just masquerading | 51 // It must actually *be* a CFNumber and not something just masquerading |
52 // as one. | 52 // as one. |
53 if (CFGetTypeID(cfn) == CFNumberGetTypeID()) { | 53 if (CFGetTypeID(cfn) == CFNumberGetTypeID()) { |
54 CFNumberType ntype = CFNumberGetType(cfn); | 54 CFNumberType ntype = CFNumberGetType(cfn); |
55 switch (ntype) { | 55 switch (ntype) { |
56 case kCFNumberSInt8Type: | 56 case kCFNumberSInt8Type: |
57 SInt8 sint8; | 57 SInt8 sint8; |
58 converted = CFNumberGetValue(cfn, ntype, static_cast<void*>(&sint8)); | 58 converted = CFNumberGetValue(cfn, ntype, static_cast<void*>(&sint8)); |
59 if (converted) *i = static_cast<int>(sint8); | 59 if (converted) *i = static_cast<int>(sint8); |
60 break; | 60 break; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 bool converted = p_convertCFNumberToInt(cfn, &asInt); | 150 bool converted = p_convertCFNumberToInt(cfn, &asInt); |
151 | 151 |
152 if (converted && (0 != asInt)) { | 152 if (converted && (0 != asInt)) { |
153 result = true; | 153 result = true; |
154 } | 154 } |
155 | 155 |
156 return result; | 156 return result; |
157 } | 157 } |
158 | 158 |
159 #endif // WEBRTC_MAC || WEBRTC_IOS | 159 #endif // WEBRTC_MAC || WEBRTC_IOS |
OLD | NEW |