diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 3913f3c8d5..94401f3e1f 100755 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -3,7 +3,7 @@ USING: io.backend io.files.private io hashtables kernel math memory namespaces sequences strings assocs arrays definitions system combinators splitting sbufs continuations io.encodings -io.encodings.binary init ; +io.encodings.binary init unicode.categories ; IN: io.files HOOK: (file-reader) io-backend ( path -- stream ) @@ -98,11 +98,19 @@ ERROR: no-parent-directory path ; PRIVATE> +: windows-absolute-path? ( path -- path ? ) + { + { [ dup length 2 < ] [ f ] } + { [ dup first2 >r Letter? r> CHAR: : = and ] [ t ] } + { [ t ] [ f ] } + } cond ; + : absolute-path? ( path -- ? ) { { [ dup empty? ] [ f ] } { [ dup "resource:" head? ] [ t ] } { [ dup first path-separator? ] [ t ] } + { [ windows? ] [ windows-absolute-path? ] } { [ t ] [ f ] } } cond nip ; diff --git a/extra/io/windows/nt/files/files-tests.factor b/extra/io/windows/nt/files/files-tests.factor new file mode 100644 index 0000000000..a96bd6dad8 --- /dev/null +++ b/extra/io/windows/nt/files/files-tests.factor @@ -0,0 +1,11 @@ +USING: kernel tools.test ; +IN: io.windows.nt.files.tests + +[ f ] [ "" root-directory? ] unit-test +[ t ] [ "\\" root-directory? ] unit-test +[ t ] [ "\\\\" root-directory? ] unit-test +[ t ] [ "\\\\\\\\\\\\" root-directory? ] unit-test +[ t ] [ "/" root-directory? ] unit-test +[ t ] [ "//" root-directory? ] unit-test +[ t ] [ "//////////////" root-directory? ] unit-test +[ t ] [ "\\foo" absolute-path? ] unit-test