diff --git a/basis/alien/strings/strings.factor b/basis/alien/strings/strings.factor index d482634772..e9053cd5c1 100644 --- a/basis/alien/strings/strings.factor +++ b/basis/alien/strings/strings.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays sequences kernel accessors math alien.accessors alien.c-types byte-arrays words io io.encodings -io.streams.byte-array io.streams.memory io.encodings.utf8 -io.encodings.utf16 system alien strings cpu.architecture fry ; +io.encodings.utf8 io.streams.byte-array io.streams.memory system +alien strings cpu.architecture fry vocabs.loader combinators ; IN: alien.strings GENERIC# alien>string 1 ( c-ptr encoding -- string/f ) @@ -88,27 +88,22 @@ M: string-type c-type-getter M: string-type c-type-setter drop [ set-alien-cell ] ; -! Native-order UTF-16 +HOOK: alien>native-string os ( alien -- string ) -SINGLETON: utf16n - -: utf16n ( -- descriptor ) - little-endian? utf16le utf16be ? ; foldable - -M: utf16n drop utf16n ; - -M: utf16n drop utf16n ; - -: alien>native-string ( alien -- string ) - os windows? [ utf16n ] [ utf8 ] if alien>string ; +HOOK: native-string>alien os ( string -- alien ) : dll-path ( dll -- string ) path>> alien>native-string ; : string>symbol ( str -- alien ) - [ os wince? [ utf16n ] [ utf8 ] if string>alien ] - over string? [ call ] [ map ] if ; + dup string? + [ native-string>alien ] + [ [ native-string>alien ] map ] if ; { "char*" utf8 } "char*" typedef -{ "char*" utf16n } "wchar_t*" typedef "char*" "uchar*" typedef + +{ + { [ os windows? ] [ "alien.strings.windows" require ] } + { [ os unix? ] [ "alien.strings.unix" require ] } +} cond diff --git a/basis/alien/strings/unix/unix.factor b/basis/alien/strings/unix/unix.factor new file mode 100644 index 0000000000..a7b1467344 --- /dev/null +++ b/basis/alien/strings/unix/unix.factor @@ -0,0 +1,8 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.strings io.encodings.utf8 system ; +IN: alien.strings.unix + +M: unix alien>native-string utf8 alien>string ; + +M: unix native-string>alien utf8 string>alien ; diff --git a/basis/alien/strings/windows/windows.factor b/basis/alien/strings/windows/windows.factor new file mode 100644 index 0000000000..55c69246de --- /dev/null +++ b/basis/alien/strings/windows/windows.factor @@ -0,0 +1,13 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.strings alien.c-types io.encodings.utf8 +io.encodings.utf16n system ; +IN: alien.strings.windows + +M: windows alien>native-string utf16n alien>string ; + +M: wince native-string>alien utf16n string>alien ; + +M: winnt native-string>alien utf8 string>alien ; + +{ "char*" utf16n } "wchar_t*" typedef