aboutsummaryrefslogtreecommitdiff
path: root/src/base/Osx.cpp
blob: 6b8d0bd9cab817781c28b90d58c2d55d38b100b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "cru/base/Osx.h"

namespace cru {
CFWrapper<CFStringRef> ToCFStringRef(StringView string) {
  return CFWrapper<CFStringRef>(CFStringCreateWithBytes(
      nullptr, reinterpret_cast<const UInt8*>(string.data()),
      string.size() * sizeof(std::uint16_t), kCFStringEncodingUTF16, false));
}

String FromCFStringRef(CFStringRef string) {
  auto length = CFStringGetLength(string);

  String result;

  for (int i = 0; i < length; i++) {
    result.AppendCodePoint(CFStringGetCharacterAtIndex(string, i));
  }

  return result;
}
}  // namespace cru