forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoundation-string-cf.cpp
More file actions
53 lines (37 loc) · 1.68 KB
/
Copy pathfoundation-string-cf.cpp
File metadata and controls
53 lines (37 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include <foundation.h>
#include <foundation-auto.h>
#include "foundation-private.h"
#define integer_t cf_integer_t
#include <CoreFoundation/CoreFoundation.h>
#undef integer_t
////////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF
bool MCStringCreateWithCFString(CFStringRef p_cf_string, MCStringRef& r_string)
{
bool t_success;
t_success = true;
CFIndex t_string_length;
t_string_length = CFStringGetLength(p_cf_string);
CFIndex t_buffer_size;
t_buffer_size = CFStringGetMaximumSizeForEncoding(t_string_length, kCFStringEncodingUnicode) + 1;
MCAutoPointer<byte_t> t_buffer;
t_success = MCMemoryNewArray(t_buffer_size, &t_buffer);
CFIndex t_used_size;
if (t_success)
CFStringGetBytes(p_cf_string, CFRangeMake(0, t_string_length), kCFStringEncodingUnicode, '?', false, (UInt8*)*t_buffer, t_buffer_size, &t_used_size);
if (t_success)
t_success = MCStringCreateWithChars((unichar_t *)*t_buffer, t_used_size / 2, r_string);
return t_success;
}
////////////////////////////////////////////////////////////////////////////////