In general, P"" or `pathname` is a frontend/tooling convenience concept
with tab-complete for paths in the ui. Backend apis should see strings.
] with-variable
] with-test-directory
] unit-test
] with-variable
] with-test-directory
] unit-test
+
+! test P"" pathnames
+[ "resource:extra/math" recursive-directory-files drop ] must-not-fail
+
+{ "/foo/bar" } [ P"/foo" P"./bar" append-path ] unit-test
+{ "/bar/foo" } [ P"./foo" P"/bar" prepend-path ] unit-test
[ queue>> swap '[ _ _ [ push-front ] [ push-back ] if ] each ] bi ;
: <directory-iterator> ( path bfs? -- iter )
[ queue>> swap '[ _ _ [ push-front ] [ push-back ] if ] each ] bi ;
: <directory-iterator> ( path bfs? -- iter )
<dlist> directory-iterator boa
dup path>> over push-directory-entries ;
<dlist> directory-iterator boa
dup path>> over push-directory-entries ;
+TUPLE: pathname string ;
+
+C: <pathname> pathname
+
+: >pathname ( obj -- pathname )
+ dup pathname? [ <pathname> ] unless ;
+
+: pathname> ( pathname -- obj )
+ dup pathname? [ string>> ] when ;
+
: absolute-path? ( path -- ? )
{
{ [ dup empty? ] [ drop f ] }
: absolute-path? ( path -- ? )
{
{ [ dup empty? ] [ drop f ] }
[ trim-head-separators ] bi* "/" glue ;
: append-path ( path1 path2 -- path )
[ trim-head-separators ] bi* "/" glue ;
: append-path ( path1 path2 -- path )
{
{ [ over empty? ] [ append-path-empty ] }
{ [ dup empty? ] [ drop ] }
{
{ [ over empty? ] [ append-path-empty ] }
{ [ dup empty? ] [ drop ] }
: >windows-path ( path -- path' ) H{ { CHAR: / CHAR: \\ } } substitute ;
: >windows-path ( path -- path' ) H{ { CHAR: / CHAR: \\ } } substitute ;
-TUPLE: pathname string ;
-
-C: <pathname> pathname
-
M: pathname absolute-path string>> absolute-path ;
M: pathname <=> [ string>> ] compare ;
M: pathname absolute-path string>> absolute-path ;
M: pathname <=> [ string>> ] compare ;
-
-: >pathname ( obj -- pathname )
- dup pathname? [ <pathname> ] unless ;