blob: d3f2919abf6b30c17cd37051f81846dafd5951dd [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
2 * Copyright 2007 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
erikchene606a172016-10-10 18:19:1511#include <cstring>
jbauch555604a2016-04-26 10:13:2212#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:2613#include <sstream>
14
erikchene606a172016-10-10 18:19:1515#include <sys/utsname.h>
kthelgasond5472242016-09-09 10:19:4816
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "rtc_base/checks.h"
18#include "rtc_base/logging.h"
19#include "rtc_base/macutils.h"
20#include "rtc_base/stringutils.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2621
22namespace rtc {
23
henrike@webrtc.orgf0488722014-05-13 18:00:2624bool ToUtf8(const CFStringRef str16, std::string* str8) {
deadbeef37f5ecf2017-02-27 22:06:4125 if ((nullptr == str16) || (nullptr == str8)) {
henrike@webrtc.orgf0488722014-05-13 18:00:2626 return false;
27 }
28 size_t maxlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str16),
29 kCFStringEncodingUTF8) + 1;
jbauch555604a2016-04-26 10:13:2230 std::unique_ptr<char[]> buffer(new char[maxlen]);
henrike@webrtc.orgf0488722014-05-13 18:00:2631 if (!buffer || !CFStringGetCString(str16, buffer.get(), maxlen,
32 kCFStringEncodingUTF8)) {
33 return false;
34 }
35 str8->assign(buffer.get());
36 return true;
37}
38
39bool ToUtf16(const std::string& str8, CFStringRef* str16) {
deadbeef37f5ecf2017-02-27 22:06:4140 if (nullptr == str16) {
henrike@webrtc.orgf0488722014-05-13 18:00:2641 return false;
42 }
43 *str16 = CFStringCreateWithBytes(kCFAllocatorDefault,
44 reinterpret_cast<const UInt8*>(str8.data()),
45 str8.length(), kCFStringEncodingUTF8,
46 false);
deadbeef37f5ecf2017-02-27 22:06:4147 return nullptr != *str16;
henrike@webrtc.orgf0488722014-05-13 18:00:2648}
henrike@webrtc.orgf0488722014-05-13 18:00:2649} // namespace rtc