]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/core-foundation/strings/strings.factor
Updating code to use with-out-parameters
[factor.git] / basis / core-foundation / strings / strings.factor
index 413709d142ee2fbddf49dc243b69446df4160ac1..b78e1046fee3822c33447aeb584e6ae9ed54a6ed 100644 (file)
@@ -1,8 +1,9 @@
-! 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
@@ -37,7 +38,7 @@ FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex l
 
 FUNCTION: Boolean CFStringGetCString (
     CFStringRef theString,
-    char* buffer,
+    UInt8* buffer,
     CFIndex bufferSize,
     CFStringEncoding encoding
 ) ;
@@ -55,7 +56,7 @@ FUNCTION: CFIndex CFStringGetBytes (
 
 FUNCTION: CFStringRef CFStringCreateWithCString (
     CFAllocatorRef alloc,
-    char* cStr,
+    UInt8* cStr,
     CFStringEncoding encoding
 ) ;
 
@@ -75,11 +76,20 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
 : 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 ;