author | Stefan Vogel <sv@exept.de> |
Wed, 01 Aug 2018 15:12:02 +0200 | |
changeset 4708 | 713e81a051ec |
parent 4268 | fff51d808999 |
child 4960 | b7afd7586747 |
permissions | -rw-r--r-- |
1309 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1005 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
4181 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1005 | 16 |
URI subclass:#HierarchicalURI |
1257 | 17 |
instanceVariableNames:'authority isAbsolute isDirectory pathSegments query fragment' |
1005 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
1310 | 20 |
category:'Net-Resources' |
1005 | 21 |
! |
22 |
||
23 |
!HierarchicalURI class methodsFor:'documentation'! |
|
24 |
||
1309 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
1005 | 39 |
documentation |
40 |
" |
|
41 |
Hierarchical URI as defined in RFC2396: |
|
42 |
||
43 |
<scheme:[//authority][/absolute_path][?query][#fragment]> |
|
44 |
||
45 |
[author:] |
|
46 |
Stefan Vogel (stefan@zwerg) |
|
47 |
||
48 |
[see also:] |
|
49 |
||
50 |
[instance variables:] |
|
51 |
||
52 |
[class variables:] |
|
53 |
" |
|
54 |
! |
|
55 |
||
56 |
examples |
|
57 |
" |
|
58 |
||
59 |
more examples to be added: |
|
60 |
[exBegin] |
|
1254 | 61 |
|u1 u2| |
62 |
||
63 |
u1 := URI fromString:'file:/phys/exept/tmp/'. |
|
64 |
u2 := u1 construct:'test.txt'. |
|
65 |
Transcript showCR:u1. |
|
66 |
Transcript showCR:u2. |
|
67 |
[exEnd] |
|
68 |
||
69 |
[exBegin] |
|
70 |
|u1 u2| |
|
71 |
||
72 |
u1 := URI fromString:'file:/phys/exept/tmp'. |
|
73 |
u2 := u1 construct:'test.txt'. |
|
74 |
Transcript showCR:u1. |
|
75 |
Transcript showCR:u2. |
|
1005 | 76 |
[exEnd] |
77 |
" |
|
78 |
! ! |
|
79 |
||
80 |
!HierarchicalURI class methodsFor:'instance creation'! |
|
81 |
||
82 |
new |
|
83 |
||
84 |
^ self basicNew initialize |
|
85 |
! |
|
86 |
||
87 |
scheme:aSchemeString fromString:aString |
|
88 |
"parse the hierarchical information. |
|
89 |
schemeString is ignored here" |
|
90 |
||
91 |
^ self new scheme:aSchemeString; |
|
92 |
fromString:aString |
|
93 |
! ! |
|
94 |
||
95 |
!HierarchicalURI methodsFor:'accessing'! |
|
96 |
||
97 |
authority |
|
98 |
"return the value of the instance variable 'authority' (automatically generated)" |
|
99 |
||
100 |
^ authority |
|
101 |
! |
|
102 |
||
103 |
authority:something |
|
104 |
"set the value of the instance variable 'authority' (automatically generated)" |
|
105 |
||
106 |
authority := something. |
|
107 |
! |
|
108 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
109 |
baseName |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
110 |
^ pathSegments last |
1520 | 111 |
|
112 |
" |
|
113 |
(URI fromString:'file:/phys/exept/tmp/foo.html') baseName. |
|
114 |
(URI fromString:'file:/phys/exept/tmp/foo') baseName. |
|
115 |
(URI fromString:'file:/phys/exept/tmp/') baseName. |
|
116 |
(URI fromString:'file:/phys/') baseName. |
|
117 |
(URI fromString:'file:/phys') baseName. |
|
118 |
||
119 |
(URI fromString:'file://phys/exept/tmp/foo.html') baseName. |
|
120 |
(URI fromString:'file://phys/exept/tmp/foo') baseName. |
|
121 |
(URI fromString:'file://phys/exept/tmp/') baseName. |
|
122 |
(URI fromString:'file://phys/exept/tmp') baseName. |
|
123 |
(URI fromString:'file://phys/exept/') baseName. |
|
124 |
(URI fromString:'file://phys/exept') baseName. |
|
125 |
(URI fromString:'file://phys/') baseName. |
|
126 |
(URI fromString:'file://phys') baseName. |
|
127 |
(URI fromString:'file://') baseName. |
|
128 |
" |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
129 |
! |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
130 |
|
1254 | 131 |
examples |
132 |
" |
|
133 |
||
134 |
more examples to be added: |
|
135 |
[exBegin] |
|
136 |
URI fromString:'file:/phys/exept/home/tm/tmp' |
|
137 |
[exEnd] |
|
138 |
" |
|
139 |
! |
|
140 |
||
1005 | 141 |
fragment |
142 |
"return the value of the instance variable 'fragment' (automatically generated)" |
|
143 |
||
144 |
^ fragment |
|
145 |
! |
|
146 |
||
147 |
fragment:something |
|
148 |
"set the value of the instance variable 'fragment' (automatically generated)" |
|
149 |
||
150 |
fragment := something. |
|
151 |
! |
|
152 |
||
153 |
isAbsolute |
|
154 |
"return the value of the instance variable 'isAbsolute' (automatically generated)" |
|
155 |
||
156 |
^ isAbsolute |
|
157 |
! |
|
158 |
||
1257 | 159 |
isDirectory |
160 |
"return the value of the instance variable 'isDirectory' (automatically generated)" |
|
161 |
||
162 |
^ isDirectory ? false |
|
163 |
! |
|
164 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
165 |
pathSegments |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
166 |
"return the value of the instance variable 'pathSegments' (automatically generated)" |
1005 | 167 |
|
168 |
^ pathSegments |
|
169 |
! |
|
170 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
171 |
pathSegments:something |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
172 |
"set the value of the instance variable 'pathSegments' (automatically generated)" |
1005 | 173 |
|
174 |
pathSegments := something. |
|
175 |
! |
|
176 |
||
177 |
query |
|
178 |
"return the value of the instance variable 'query' (automatically generated)" |
|
179 |
||
180 |
^ query |
|
181 |
! |
|
182 |
||
183 |
query:something |
|
184 |
"set the value of the instance variable 'query' (automatically generated)" |
|
185 |
||
186 |
query := something. |
|
187 |
! ! |
|
188 |
||
189 |
!HierarchicalURI methodsFor:'accessing-details'! |
|
190 |
||
191 |
host |
|
192 |
"answer the host part of authority" |
|
193 |
||
194 |
|start end| |
|
195 |
||
196 |
authority isNil ifTrue:[ |
|
197 |
^ nil |
|
198 |
]. |
|
199 |
start := (authority indexOf:$@) + 1. |
|
200 |
end := (authority indexOf:$: startingAt:start) - 1. |
|
201 |
end == -1 ifTrue:[ |
|
202 |
end := authority size |
|
203 |
]. |
|
204 |
^ authority copyFrom:start to:end |
|
205 |
||
206 |
" |
|
207 |
(self fromString:'ftp://stefan@www.exept.de:80/test') host |
|
208 |
(self fromString:'ftp://www.exept.de:80/test') host |
|
209 |
(self fromString:'ftp://www.exept.de/test') host |
|
210 |
" |
|
211 |
! |
|
212 |
||
213 |
password |
|
214 |
"answer the user part of authority" |
|
215 |
||
216 |
|end start| |
|
217 |
||
218 |
authority isNil ifTrue:[ |
|
219 |
^ nil |
|
220 |
]. |
|
221 |
end := authority indexOf:$@. |
|
222 |
end == 0 ifTrue:[ |
|
223 |
^ nil |
|
224 |
]. |
|
225 |
start := authority indexOf:$:. |
|
226 |
(start == 0 or:[start > end]) ifTrue:[ |
|
227 |
^ nil |
|
228 |
]. |
|
229 |
^ authority copyFrom:start+1 to:end-1 |
|
230 |
||
231 |
" |
|
232 |
(self fromString:'ftp://stefan@www.exept.de:80/test') password |
|
233 |
(self fromString:'ftp://stefan:pass@www.exept.de:80/test') password |
|
234 |
(self fromString:'ftp://www.exept.de:80/test') password |
|
235 |
" |
|
236 |
! |
|
237 |
||
238 |
port |
|
239 |
"answer the port part of authority" |
|
240 |
||
241 |
|start| |
|
242 |
||
243 |
authority isNil ifTrue:[ |
|
244 |
^ self defaultPort |
|
245 |
]. |
|
1992 | 246 |
start := authority indexOf:$@ ifAbsent:1. |
1005 | 247 |
start := authority indexOf:$: startingAt:start. |
1992 | 248 |
|
1005 | 249 |
start == 0 ifTrue:[ |
250 |
^ self defaultPort |
|
251 |
]. |
|
252 |
||
253 |
^ authority copyFrom:start+1 |
|
254 |
||
255 |
" |
|
1992 | 256 |
(self fromString:'ftp://stefan@www.exept.de:80/test') port |
257 |
(self fromString:'ftp://www.exept.de:80/test') port |
|
258 |
(self fromString:'ftp://www.exept.de/test') port |
|
1005 | 259 |
" |
260 |
! |
|
261 |
||
262 |
user |
|
263 |
"answer the user part of authority" |
|
264 |
||
265 |
|end end1| |
|
266 |
||
267 |
authority isNil ifTrue:[ |
|
268 |
^ nil |
|
269 |
]. |
|
270 |
end := authority indexOf:$@. |
|
271 |
end == 0 ifTrue:[ |
|
272 |
^ nil |
|
273 |
]. |
|
274 |
end1 := authority indexOf:$:. |
|
275 |
end1 ~~ 0 ifTrue:[ |
|
276 |
end := end min:end1. |
|
277 |
]. |
|
278 |
^ authority copyTo:end-1 |
|
279 |
||
280 |
" |
|
281 |
(self fromString:'ftp://stefan@www.exept.de:80/test') user |
|
282 |
(self fromString:'ftp://stefan:pass@www.exept.de:80/test') user |
|
283 |
(self fromString:'ftp://www.exept.de:80/test') user |
|
284 |
" |
|
285 |
! ! |
|
286 |
||
1289 | 287 |
!HierarchicalURI methodsFor:'comparing'! |
288 |
||
289 |
= anHierarchicalUri |
|
290 |
||
291 |
^ self class == anHierarchicalUri class |
|
292 |
and:[self scheme = anHierarchicalUri scheme |
|
293 |
and:[pathSegments = anHierarchicalUri pathSegments |
|
294 |
and:[authority = anHierarchicalUri authority |
|
295 |
and:[self isAbsolute = anHierarchicalUri isAbsolute |
|
296 |
and:[self isDirectory = anHierarchicalUri isDirectory |
|
297 |
and:[query = anHierarchicalUri query |
|
298 |
and:[fragment = anHierarchicalUri fragment]]]]]]] |
|
299 |
! |
|
300 |
||
301 |
hash |
|
302 |
||
4268 | 303 |
^ pathSegments hash bitXor:query hash |
304 |
||
305 |
"Modified: / 20-01-2017 / 19:49:30 / stefan" |
|
1289 | 306 |
! ! |
307 |
||
1254 | 308 |
!HierarchicalURI methodsFor:'copying'! |
309 |
||
310 |
postCopy |
|
311 |
||
312 |
pathSegments := pathSegments copy |
|
313 |
! ! |
|
314 |
||
1005 | 315 |
!HierarchicalURI methodsFor:'defaults'! |
316 |
||
317 |
defaultPort |
|
318 |
"answer the default port for the given scheme. |
|
319 |
Concrete subclasses redefine this method" |
|
320 |
||
321 |
^ nil |
|
322 |
! ! |
|
323 |
||
324 |
!HierarchicalURI methodsFor:'escape'! |
|
325 |
||
326 |
unEscape |
|
327 |
"convert escaped characters (such as %20 for ' ') to their native |
|
328 |
representation" |
|
329 |
||
330 |
authority := self class unEscape:authority readStream. |
|
331 |
pathSegments keysAndValuesDo:[:i :v| |
|
332 |
pathSegments at:i put:(self class unEscape:v readStream). |
|
333 |
]. |
|
334 |
query := self class unEscape:query readStream. |
|
335 |
fragment := self class unEscape:fragment readStream. |
|
336 |
! ! |
|
337 |
||
1374 | 338 |
!HierarchicalURI methodsFor:'initialization'! |
1005 | 339 |
|
340 |
fromString:aString |
|
341 |
|i i1 separator| |
|
342 |
||
343 |
(aString startsWith:'//') ifTrue:[ |
|
1268 | 344 |
i := aString indexOfAny:'/?#' startingAt:3. |
1005 | 345 |
i == 0 ifTrue:[ |
346 |
authority := aString copyFrom:3. |
|
347 |
^ self. |
|
348 |
] ifFalse:[ |
|
349 |
separator := aString at:i. |
|
350 |
authority := aString copyFrom:3 to:i-1. |
|
351 |
]. |
|
4181 | 352 |
isAbsolute := (aString at:i) == $/. |
1005 | 353 |
] ifFalse:[ |
354 |
(isAbsolute := aString startsWith:$/) ifTrue:[ |
|
355 |
i := 1. |
|
356 |
] ifFalse:[ |
|
357 |
i := 0. |
|
358 |
] |
|
359 |
]. |
|
360 |
||
361 |
[ |
|
362 |
i1 := aString indexOfAny:'/?#' startingAt:i+1. |
|
1254 | 363 |
i1 == 0 ifTrue:[ |path| |
364 |
path := aString copyFrom:i+1. |
|
365 |
path size ~~ 0 ifTrue:[ |
|
366 |
pathSegments add:path. |
|
1257 | 367 |
] ifFalse:[ |
368 |
(aString at:i) == $/ ifTrue:[ |
|
369 |
isDirectory := true |
|
370 |
]. |
|
1254 | 371 |
]. |
1005 | 372 |
^ self. |
373 |
] ifFalse:[ |
|
374 |
separator := aString at:i1. |
|
375 |
pathSegments add:(aString copyFrom:i+1 to:i1-1). |
|
1267 | 376 |
isAbsolute ifTrue:[ |
377 |
pathSegments size == 1 ifTrue:[ |
|
1268 | 378 |
(pathSegments first startsWith:$~) ifTrue:[ |
1267 | 379 |
isAbsolute := false |
380 |
]. |
|
381 |
]. |
|
382 |
]. |
|
1005 | 383 |
i := i1. |
384 |
]. |
|
385 |
] doWhile:[separator == $/]. |
|
386 |
||
387 |
separator == $? ifTrue:[ |
|
388 |
i1 := aString indexOf:$# startingAt:i+1. |
|
389 |
i1 == 0 ifTrue:[ |
|
390 |
query := aString copyFrom:i+1. |
|
391 |
^ self. |
|
392 |
] ifFalse:[ |
|
393 |
separator := aString at:i1. |
|
394 |
query := aString copyFrom:i+1 to:i1-1. |
|
395 |
i := i1. |
|
396 |
]. |
|
397 |
]. |
|
398 |
separator == $# ifTrue:[ |
|
399 |
fragment := aString copyFrom:i+1. |
|
400 |
]. |
|
401 |
||
402 |
" |
|
1267 | 403 |
self new fromString:'//exept~/tmp' |
404 |
self new fromString:'~/tmp' |
|
405 |
self new fromString:'/~/tmp' |
|
1257 | 406 |
self new fromString:'//authority/path1/path2/' |
1005 | 407 |
self new fromString:'//authority/path1/path2?query' |
408 |
self new fromString:'//authority/path1/path2?query#fragment' |
|
409 |
self new fromString:'/path1/path2?query#fragment' |
|
410 |
self new fromString:'/path1/path2#fragment' |
|
411 |
self new fromString:'path1/path2#fragment' |
|
412 |
" |
|
413 |
! |
|
414 |
||
415 |
initialize |
|
416 |
||
417 |
pathSegments := OrderedCollection new. |
|
418 |
! ! |
|
419 |
||
420 |
!HierarchicalURI methodsFor:'printing & storing'! |
|
421 |
||
1268 | 422 |
directoryPath |
423 |
"answer the directory path part of the URI" |
|
424 |
||
425 |
|aStream| |
|
426 |
||
427 |
aStream := WriteStream on:''. |
|
428 |
||
429 |
pathSegments size ~~ 0 ifTrue: [ |
|
430 |
self isAbsolute ifTrue:[ |
|
431 |
aStream nextPut:$/. |
|
432 |
]. |
|
433 |
pathSegments size > 1 ifTrue:[ |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
434 |
(pathSegments copyTo:pathSegments size-1) do:[:p| |
1268 | 435 |
self class escape:p allow:'~;:@&=+",' on:aStream |
436 |
] separatedBy:[ |
|
437 |
aStream nextPut:$/ |
|
438 |
]. |
|
439 |
]. |
|
440 |
]. |
|
441 |
||
442 |
^ aStream contents |
|
443 |
! |
|
444 |
||
1005 | 445 |
path |
446 |
"answer the path part of the URI" |
|
447 |
||
448 |
|aStream| |
|
449 |
||
450 |
aStream := WriteStream on:''. |
|
451 |
||
452 |
pathSegments size ~~ 0 ifTrue: [ |
|
1268 | 453 |
self isAbsolute ifTrue:[ |
1005 | 454 |
aStream nextPut:$/. |
455 |
]. |
|
456 |
pathSegments do:[:p| |
|
1268 | 457 |
self class escape:p allow:'~;:@&=+",' on:aStream |
1005 | 458 |
] separatedBy:[ |
459 |
aStream nextPut:$/ |
|
460 |
]. |
|
461 |
]. |
|
462 |
query notNil ifTrue: [ |
|
463 |
aStream nextPut:$?. |
|
464 |
self class escape:query allow:nil on:aStream |
|
465 |
]. |
|
466 |
fragment notNil ifTrue: [ |
|
467 |
aStream nextPut:$#. |
|
468 |
self class escape:fragment allow:nil on:aStream |
|
469 |
]. |
|
470 |
||
471 |
^ aStream contents |
|
472 |
! |
|
473 |
||
474 |
printOn:aStream |
|
475 |
||
476 |
self printOn:aStream escape:false |
|
477 |
! |
|
478 |
||
479 |
printOn:aStream escape:doEscape |
|
480 |
"print the URI on aStream. If doEscape is set, escape special |
|
481 |
characters" |
|
482 |
||
483 |
super printOn:aStream. |
|
4181 | 484 |
aStream nextPutAll:'//'. |
485 |
authority notNil ifTrue:[ |
|
1005 | 486 |
doEscape ifTrue:[ |
1268 | 487 |
self class escape:authority allow:'~$,;:@&=+' on:aStream |
1005 | 488 |
] ifFalse:[ |
489 |
aStream nextPutAll:authority |
|
490 |
] |
|
491 |
]. |
|
1276 | 492 |
|
493 |
self printPathOn:aStream escape:doEscape. |
|
494 |
! |
|
495 |
||
496 |
printPathOn:aStream escape:doEscape |
|
497 |
"print the path part" |
|
498 |
||
1005 | 499 |
pathSegments size ~~ 0 ifTrue: [ |
1268 | 500 |
self isAbsolute ifTrue:[ |
1005 | 501 |
aStream nextPut:$/. |
502 |
]. |
|
503 |
pathSegments do:[:p| |
|
504 |
doEscape ifTrue:[ |
|
1268 | 505 |
self class escape:p allow:'~;:@&=+",' on:aStream |
1005 | 506 |
] ifFalse:[ |
507 |
aStream nextPutAll:p |
|
508 |
] |
|
509 |
] separatedBy:[ |
|
510 |
aStream nextPut:$/ |
|
511 |
]. |
|
512 |
]. |
|
513 |
query notNil ifTrue: [ |
|
514 |
aStream nextPut:$?. |
|
515 |
doEscape ifTrue:[ |
|
516 |
self class escape:query allow:nil on:aStream |
|
517 |
] ifFalse:[ |
|
518 |
aStream nextPutAll:query |
|
519 |
] |
|
520 |
||
521 |
]. |
|
522 |
fragment notNil ifTrue: [ |
|
523 |
aStream nextPut:$#. |
|
524 |
doEscape ifTrue:[ |
|
525 |
self class escape:fragment allow:nil on:aStream |
|
526 |
] ifFalse:[ |
|
527 |
aStream nextPutAll:fragment |
|
528 |
] |
|
529 |
]. |
|
1276 | 530 |
! |
531 |
||
532 |
publicPrintOn:aStream |
|
533 |
"print, but omit password information" |
|
534 |
||
535 |
|password| |
|
536 |
||
537 |
password := self password. |
|
538 |
password size ~~ 0 ifTrue:[ |
|
1277 | 539 |
super printOn:aStream. |
1276 | 540 |
aStream |
541 |
nextPutAll:'//'; |
|
542 |
nextPutAll:self user; |
|
543 |
nextPut:$@; |
|
544 |
nextPutAll:self host. |
|
1277 | 545 |
self printPathOn:aStream escape:true. |
546 |
] ifFalse:[ |
|
547 |
"no password, use normal printing" |
|
548 |
self printOn:aStream |
|
1276 | 549 |
]. |
1005 | 550 |
! ! |
551 |
||
552 |
!HierarchicalURI methodsFor:'resolution'! |
|
553 |
||
1962
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
554 |
/ aString |
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
555 |
"concatenate aString to my path. |
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
556 |
Same as #construct:, but simpler to use" |
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
557 |
|
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
558 |
^ self construct:aString. |
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
559 |
! |
b2044230fdc4
added #'/' (synonym of #construct:)
Stefan Vogel <sv@exept.de>
parents:
1520
diff
changeset
|
560 |
|
1005 | 561 |
addComponent:aString |
562 |
"concatenate aString to my path" |
|
563 |
||
564 |
(aString = '..' |
|
565 |
and:[pathSegments size ~~ 0 |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
566 |
and:[pathSegments last ~= '..']]) ifTrue:[ |
1005 | 567 |
pathSegments removeLast. |
568 |
] ifFalse:[ |
|
569 |
pathSegments add:aString |
|
570 |
]. |
|
571 |
! |
|
572 |
||
573 |
construct:aString |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
574 |
"concatenate aString to my path" |
1005 | 575 |
|
576 |
^ self copy |
|
577 |
addComponent:aString; |
|
578 |
yourself. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
579 |
! |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
580 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
581 |
directory |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
582 |
"remove the last path component" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
583 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
584 |
^ self copy |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
585 |
removeLastComponent; |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
586 |
yourself. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
587 |
! |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
588 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
589 |
removeLastComponent |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
590 |
"remove the last component" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
591 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
592 |
pathSegments size ~~ 0 ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
593 |
pathSegments last = '..' ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
594 |
pathSegments add:'..'. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
595 |
] ifFalse:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
596 |
pathSegments removeLast. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
597 |
]. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
598 |
]. |
1005 | 599 |
! ! |
600 |
||
601 |
!HierarchicalURI class methodsFor:'documentation'! |
|
602 |
||
603 |
version |
|
4181 | 604 |
^ '$Header$' |
1005 | 605 |
! ! |
4181 | 606 |