53 !FileURI methodsFor:'converting'! |
55 !FileURI methodsFor:'converting'! |
54 |
56 |
55 asFilename |
57 asFilename |
56 "answer the receiver represented as filename" |
58 "answer the receiver represented as filename" |
57 |
59 |
58 ^ authority notNil ifTrue:[ |
60 ^ authority notEmptyOrNil ifTrue:[ |
59 Filename remoteHost:authority rootComponents:pathSegments. |
61 Filename remoteHost:authority rootComponents:pathSegments. |
60 ] ifFalse:[ |
62 ] ifFalse:[ |
61 "kludge" |
63 isAbsolute ifTrue:[ |
62 (pathSegments first startsWith:$~) ifTrue:[ |
64 Filename rootComponents:pathSegments. |
63 pathSegments first asFilename construct:(Filename rootComponents:(pathSegments copyFrom:2)). |
|
64 ] ifFalse:[ |
65 ] ifFalse:[ |
65 Filename rootComponents:pathSegments. |
66 Filename fromComponents:pathSegments. |
66 ]. |
67 ]. |
67 ]. |
68 ]. |
68 |
69 |
69 " |
70 " |
70 (URI fromString:'file:~/bla') asFilename |
71 (URI fromString:'file:///dir/file') asFilename |
71 (URI fromString:'file:~root/bla') asFilename |
72 (URI fromString:'file:///C:dir/file') asFilename |
|
73 (URI fromString:'file:///C:/dir/file') asFilename |
|
74 (URI fromString:'file:///~/bla') asFilename |
|
75 (URI fromString:'file:///~root/bla') asFilename |
|
76 (URI fromString:'file:////host/dir/file') asFilename |
72 " |
77 " |
73 ! ! |
78 ! ! |
74 |
79 |
75 !FileURI methodsFor:'initialization'! |
80 !FileURI methodsFor:'initialization'! |
76 |
81 |
77 fromFilename:aFilename |
82 fromFilename:aFilename |
78 "create an URI based on an a filename" |
83 "create an URI based on an a filename" |
79 |
84 |
80 |components| |
85 |volume| |
81 |
86 |
82 components := aFilename components. |
87 pathSegments := aFilename components. |
83 aFilename isAbsolute ifTrue:[ |
88 aFilename isAbsolute ifTrue:[ |
84 (components size > 3 and:[(components at:2) size == 0]) ifTrue:[ |
89 (pathSegments notEmpty and:[pathSegments first startsWith:'\\']) ifTrue:[ |
85 "this is a MS-Windows network path: \\host\path" |
90 "this is a MS-Windows network path: \\host\path" |
86 authority := components at:3. |
91 isAbsolute := false. "there are already enogh / in the first pathComponent" |
87 pathSegments := components copyFrom:4. |
92 pathSegments at:1 put:(pathSegments first replaceAll:$\ with:$/). |
88 ] ifFalse:[ |
93 ] ifFalse:[ |
89 "this is an absolute path" |
94 "this is an absolute path" |
90 isAbsolute := true. |
95 isAbsolute := true. |
91 pathSegments := components copyFrom:2. |
96 volume := aFilename volume. |
|
97 volume notEmpty ifTrue:[ |
|
98 pathSegments at:1 put:volume. |
|
99 ]. |
92 ]. |
100 ]. |
93 ] ifFalse:[ |
101 ] ifFalse:[ |
94 "this is a relative path" |
102 "this is a relative path" |
95 isAbsolute := false. |
103 isAbsolute := false. |
96 pathSegments := components. |
|
97 ] |
104 ] |
98 |
105 |
99 " |
106 " |
100 self fromFilename:'/a/b/c' asFilename |
107 self fromFilename:'/a/b/c' asFilename |
101 self fromFilename:'//a/b/c' asFilename |
108 self fromFilename:'//a/b/c' asFilename |
102 self fromFilename:'a/b/c' asFilename |
109 self fromFilename:'a/b/c' asFilename |
|
110 |
|
111 self fromFilename:'\a\b\c' asFilename |
|
112 self fromFilename:'~user\a\b\c' asFilename |
|
113 self fromFilename:'C:\a\b\c' asFilename |
|
114 self fromFilename:'\\a\b\c' asFilename |
|
115 self fromFilename:'a\b\c' asFilename |
103 " |
116 " |
104 ! ! |
117 ! ! |
105 |
118 |
106 !FileURI methodsFor:'queries'! |
119 !FileURI methodsFor:'queries'! |
107 |
120 |