<CFString> doesn't bomb if string contains invalid codepoints > 0x10ffff
parent
669548e62e
commit
a4362512f7
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: core-foundation.strings core-foundation tools.test kernel ;
|
USING: core-foundation.strings core-foundation tools.test kernel
|
||||||
|
strings ;
|
||||||
IN: core-foundation
|
IN: core-foundation
|
||||||
|
|
||||||
[ ] [ "Hello" <CFString> CFRelease ] unit-test
|
[ ] [ "Hello" <CFString> CFRelease ] unit-test
|
||||||
|
@ -9,3 +10,6 @@ IN: core-foundation
|
||||||
[ "Hello\u013456" ] [ "Hello\u013456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
[ "Hello\u013456" ] [ "Hello\u013456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
||||||
[ ] [ "\0" <CFString> CFRelease ] unit-test
|
[ ] [ "\0" <CFString> CFRelease ] unit-test
|
||||||
[ "\0" ] [ "\0" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
[ "\0" ] [ "\0" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
||||||
|
|
||||||
|
! This shouldn't fail
|
||||||
|
[ ] [ { HEX: 123456 } >string <CFString> CFRelease ] unit-test
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax alien.strings io.encodings.string kernel
|
USING: alien.syntax alien.strings io.encodings.string kernel
|
||||||
sequences byte-arrays io.encodings.utf8 math core-foundation
|
sequences byte-arrays io.encodings.utf8 math core-foundation
|
||||||
core-foundation.arrays destructors ;
|
core-foundation.arrays destructors unicode.data ;
|
||||||
IN: core-foundation.strings
|
IN: core-foundation.strings
|
||||||
|
|
||||||
TYPEDEF: void* CFStringRef
|
TYPEDEF: void* CFStringRef
|
||||||
|
@ -59,8 +59,17 @@ FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||||
CFStringEncoding encoding
|
CFStringEncoding encoding
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
|
: prepare-CFString ( string -- byte-array )
|
||||||
|
[
|
||||||
|
dup HEX: 10ffff >
|
||||||
|
[ drop CHAR: replacement-character ] when
|
||||||
|
] map utf8 encode ;
|
||||||
|
|
||||||
: <CFString> ( string -- alien )
|
: <CFString> ( string -- alien )
|
||||||
[ f ] dip utf8 encode dup length kCFStringEncodingUTF8 f CFStringCreateWithBytes
|
[ f ] dip
|
||||||
|
prepare-CFString dup length
|
||||||
|
kCFStringEncodingUTF8 f
|
||||||
|
CFStringCreateWithBytes
|
||||||
[ "CFStringCreateWithBytes failed" throw ] unless* ;
|
[ "CFStringCreateWithBytes failed" throw ] unless* ;
|
||||||
|
|
||||||
: CF>string ( alien -- string )
|
: CF>string ( alien -- string )
|
||||||
|
|
Loading…
Reference in New Issue