--- a/Filename.st Mon Mar 17 17:47:00 2003 +0100
+++ b/Filename.st Tue Mar 18 15:23:20 2003 +0100
@@ -4601,13 +4601,16 @@
mySuffix := self suffix.
self class isCaseSensitive ifTrue:[
- ^ mySuffix = aSuffixString
+ ^ mySuffix = aSuffixString
].
^ mySuffix asLowercase = aSuffixString asLowercase
"
'abc.st' asFilename hasSuffix:'st'
'abc.ST' asFilename hasSuffix:'st'
+ '.ST' asFilename hasSuffix:'st' -- false expected here
+ '.foorc' asFilename hasSuffix:'foorc' -- false expected here
+ '.foorc.sav' asFilename hasSuffix:'sav'
"
"Modified: 7.9.1997 / 02:55:25 / cg"
@@ -4621,27 +4624,34 @@
will consist of the files basename only.)
(on some systems, the suffix-character may be different from a period).
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'.
+ An exception to the above: if the name starts with the suffixCharacter,
+ that part is NOT considered a suffix. Thus, '.foorc' has no suffix and a prefix of
+ '.foorc'.
See also: #withoutSuffix and #withSuffix
Notice:
- there is currently no known system which uses other than
- the period character as suffixCharacter."
+ there is currently no known system which uses other than
+ the period character as suffixCharacter."
|nm idx|
nm := self baseName.
idx := nm lastIndexOf:(self class suffixSeparator).
- idx == 0 ifTrue:[
- ^ Array with:nm with:''
+ "/ be careful: if the name consists only of suffix (i.e '.foo'),
+ "/ the suffix is considered empty.
+ ((idx == 1) or:[ idx == 0 ]) ifTrue:[
+ ^ Array with:nm with:''
].
^ Array
- with:(nm copyTo:idx-1)
- with:(nm copyFrom:idx+1)
+ with:(nm copyTo:idx-1)
+ with:(nm copyFrom:idx+1)
"
'abc.st' asFilename prefixAndSuffix
'abc' asFilename prefixAndSuffix
'a.b.c' asFilename prefixAndSuffix
'/foo/bar.c/baz.c' asFilename prefixAndSuffix
+ 'a.' asFilename prefixAndSuffix
+ '.a' asFilename prefixAndSuffix
|parts|
parts := 'Object.st' asFilename prefixAndSuffix.
@@ -4663,6 +4673,9 @@
'abc.st' asFilename suffix
'abc' asFilename suffix
'a.b.c' asFilename suffix
+ 'a.b.c' asFilename suffix
+ 'a.' asFilename suffix
+ '.a' asFilename suffix
"
"Modified: 7.9.1995 / 11:09:03 / claus"
@@ -4673,20 +4686,37 @@
If the name already has a suffix, the new suffix replaces it;
otherwise, the new suffix is simply appended to the name."
- aSuffix isNil ifTrue:[
- ^ self withoutSuffix
+ |prefixName|
+
+ prefixName := self withoutSuffix name.
+ aSuffix isEmptyOrNil ifTrue:[
+ ^ self class named:prefixName
].
^ self class named:
- (self withoutSuffix name
+ (prefixName
, self class suffixSeparator asString
, aSuffix asString)
"
'abc.st' asFilename withSuffix:nil
+ 'a.b.c' asFilename withSuffix:nil
+ '.b.c.' asFilename withSuffix:nil
+ '.b.c' asFilename withSuffix:nil
+ '.c.' asFilename withSuffix:nil
+ '.c' asFilename withSuffix:nil
+ 'c.' asFilename withSuffix:nil
+ '.' asFilename withSuffix:nil
+
'abc.st' asFilename withSuffix:'o'
'abc' asFilename withSuffix:'o'
'a.b.c' asFilename withSuffix:'o'
+ 'a.b.c.' asFilename withSuffix:'o'
+ '.b.c.' asFilename withSuffix:'o'
+ '.c.' asFilename withSuffix:'o'
+ '.c' asFilename withSuffix:'o'
+ 'c.' asFilename withSuffix:'o'
+ '.' asFilename withSuffix:'o'
'/foo/bar/baz.st' asFilename withSuffix:'c'
'/foo/bar/baz.c' asFilename withSuffix:'st'
'/foo/bar.c/baz.c' asFilename withSuffix:'st'
@@ -4706,6 +4736,9 @@
nm := self baseName.
idx := nm lastIndexOf:(self class suffixSeparator).
(idx == 0) ifTrue:[^ self].
+ "/ be careful: if the name consists only of suffix (i.e '.foo'),
+ "/ the suffix is considered empty.
+ (idx == 1) ifTrue:[^self].
idxFromEnd := nm size - idx.
idx := nameString size - idxFromEnd.
@@ -4719,7 +4752,12 @@
'/abc.d' asFilename withoutSuffix
'./abc' asFilename withoutSuffix
'./abc.d' asFilename withoutSuffix
+ './.abc' asFilename withoutSuffix
'a.b.c' asFilename withoutSuffix
+ 'a.b.' asFilename withoutSuffix
+ '.b.c' asFilename withoutSuffix
+ '.b.' asFilename withoutSuffix
+ '.b' asFilename withoutSuffix
'/foo/bar/baz.c' asFilename withoutSuffix
'/foo/bar.x/baz.c' asFilename withoutSuffix
'/foo/bar.x/baz' asFilename withoutSuffix
@@ -4745,7 +4783,7 @@
!Filename class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.246 2003-03-02 18:41:11 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.247 2003-03-18 14:23:20 cg Exp $'
! !
Filename initialize!