-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax alien.strings io.encodings.string kernel
-sequences byte-arrays io.encodings.utf8 math core-foundation
-core-foundation.arrays destructors ;
+USING: alien.c-types alien.data alien.syntax alien.strings
+io.encodings.string kernel sequences byte-arrays
+io.encodings.utf8 math core-foundation core-foundation.arrays
+destructors parser fry alien words ;
IN: core-foundation.strings
TYPEDEF: void* CFStringRef
FUNCTION: Boolean CFStringGetCString (
CFStringRef theString,
- char* buffer,
+ UInt8* buffer,
CFIndex bufferSize,
CFStringEncoding encoding
) ;
FUNCTION: CFStringRef CFStringCreateWithCString (
CFAllocatorRef alloc,
- char* cStr,
+ UInt8* cStr,
CFStringEncoding encoding
) ;
: CF>string ( alien -- string )
dup CFStringGetLength
[ 0 swap <CFRange> kCFStringEncodingUTF8 0 f ] keep
- 4 * 1 + <byte-array> [ dup length 0 <CFIndex> [ CFStringGetBytes drop ] keep ] keep
- swap *CFIndex head-slice utf8 decode ;
+ 4 * 1 + <byte-array> [
+ dup length
+ { CFIndex } [ CFStringGetBytes drop ] [ ]
+ with-out-parameters
+ ] keep
+ swap head-slice utf8 decode ;
: CF>string-array ( alien -- seq )
CF>array [ CF>string ] map ;
: <CFStringArray> ( seq -- alien )
[ [ <CFString> &CFRelease ] map <CFArray> ] with-destructors ;
+
+SYNTAX: CFSTRING:
+ CREATE scan-object
+ [ drop ] [ '[ _ [ _ <CFString> ] initialize-alien ] ] 2bi
+ (( -- alien )) define-declared ;