Filename.st
changeset 10155 3cbef777449f
parent 10153 73f14e708d88
child 10271 9d6d37936af9
equal deleted inserted replaced
10154:abf2c5f9ba8c 10155:3cbef777449f
  5188     "
  5188     "
  5189 
  5189 
  5190     "Modified: 7.9.1997 / 02:55:25 / cg"
  5190     "Modified: 7.9.1997 / 02:55:25 / cg"
  5191 !
  5191 !
  5192 
  5192 
       
  5193 nameWithoutSuffix
       
  5194     "return the receivers name without the suffix.
       
  5195      If the name has no suffix, the original name is returned."
       
  5196 
       
  5197     |nm idx idxFromEnd|
       
  5198 
       
  5199     nm := self baseName.
       
  5200     idx := nm lastIndexOf:(self class suffixSeparator).
       
  5201     (idx == 0) ifTrue:[^ nameString].
       
  5202     "/ be careful: if the name consists only of suffix (i.e '.foo'),
       
  5203     "/ the suffix is considered empty.
       
  5204     (idx == 1) ifTrue:[^ nameString].
       
  5205 
       
  5206     idxFromEnd := nm size - idx.
       
  5207     idx := nameString size - idxFromEnd.
       
  5208 
       
  5209     ^ nameString copyTo:(idx - 1)
       
  5210 
       
  5211     "
       
  5212      'abc.st' asFilename nameWithoutSuffix         
       
  5213      'abc' asFilename nameWithoutSuffix            
       
  5214      '/abc' asFilename nameWithoutSuffix            
       
  5215      '/abc.d' asFilename nameWithoutSuffix            
       
  5216      './abc' asFilename nameWithoutSuffix            
       
  5217      './abc.d' asFilename nameWithoutSuffix            
       
  5218      './.abc' asFilename nameWithoutSuffix            
       
  5219      'a.b.c' asFilename nameWithoutSuffix           
       
  5220      'a.b.' asFilename nameWithoutSuffix           
       
  5221      '.b.c' asFilename nameWithoutSuffix           
       
  5222      '.b.' asFilename nameWithoutSuffix           
       
  5223      '.b' asFilename nameWithoutSuffix           
       
  5224      '/foo/bar/baz.c' asFilename nameWithoutSuffix     
       
  5225      '/foo/bar.x/baz.c' asFilename nameWithoutSuffix     
       
  5226      '/foo/bar.x/baz' asFilename nameWithoutSuffix     
       
  5227      '/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix   
       
  5228      '/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix   
       
  5229     "
       
  5230 
       
  5231     "Modified: / 07-09-1995 / 11:15:42 / claus"
       
  5232     "Created: / 07-11-2006 / 13:55:18 / cg"
       
  5233 !
       
  5234 
  5193 prefix
  5235 prefix
  5194     "return my prefix.
  5236     "return my prefix.
  5195      The suffix is the namepart after the final period character,
  5237      The suffix is the namepart after the final period character,
  5196      or the empty string, if the name does not contain a period."
  5238      or the empty string, if the name does not contain a period."
  5197 
  5239 
  5280      If the name already has a suffix, the new suffix replaces it;
  5322      If the name already has a suffix, the new suffix replaces it;
  5281      otherwise, the new suffix is simply appended to the name."
  5323      otherwise, the new suffix is simply appended to the name."
  5282 
  5324 
  5283     |prefixName|
  5325     |prefixName|
  5284 
  5326 
  5285     prefixName := self withoutSuffix name.
  5327     prefixName := self nameWithoutSuffix.
  5286     aSuffix isEmptyOrNil ifTrue:[
  5328     aSuffix isEmptyOrNil ifTrue:[
  5287         ^ self class named:prefixName
  5329         ^ self class named:prefixName
  5288     ].
  5330     ].
  5289 
  5331 
  5290     ^ self class named:
  5332     ^ self class named:
  5315      '/foo/bar/baz.c' asFilename withSuffix:'st'   
  5357      '/foo/bar/baz.c' asFilename withSuffix:'st'   
  5316      '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
  5358      '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
  5317      '/foo/bar.c/baz' asFilename withSuffix:'st'   
  5359      '/foo/bar.c/baz' asFilename withSuffix:'st'   
  5318     "
  5360     "
  5319 
  5361 
  5320     "Modified: 7.9.1995 / 11:15:42 / claus"
  5362     "Modified: / 07-09-1995 / 11:15:42 / claus"
  5321     "Modified: 11.12.1996 / 16:01:02 / cg"
  5363     "Modified: / 07-11-2006 / 13:58:45 / cg"
  5322 !
  5364 !
  5323 
  5365 
  5324 withoutSuffix
  5366 withoutSuffix
  5325     "return a new filename for the receivers name without the suffix.
  5367     "return a new filename for the receivers name without the suffix.
  5326      If the name has no suffix, the receiver is returned."
  5368      If the name has no suffix, a filename representing the same file as the receiver is returned."
  5327 
  5369 
  5328     |nm idx idxFromEnd|
  5370     |n|
  5329 
  5371 
  5330     nm := self baseName.
  5372     n := self nameWithoutSuffix.
  5331     idx := nm lastIndexOf:(self class suffixSeparator).
  5373     n = nameString ifTrue:[^ self].
  5332     (idx == 0) ifTrue:[^ self].
  5374     ^ self class named:n
  5333     "/ be careful: if the name consists only of suffix (i.e '.foo'),
       
  5334     "/ the suffix is considered empty.
       
  5335     (idx == 1) ifTrue:[^self].
       
  5336 
       
  5337     idxFromEnd := nm size - idx.
       
  5338     idx := nameString size - idxFromEnd.
       
  5339 
       
  5340     ^ self class named:(nameString copyTo:(idx - 1))
       
  5341 
  5375 
  5342     "
  5376     "
  5343      'abc.st' asFilename withoutSuffix         
  5377      'abc.st' asFilename withoutSuffix         
  5344      'abc' asFilename withoutSuffix            
  5378      'abc' asFilename withoutSuffix            
  5345      '/abc' asFilename withoutSuffix            
  5379      '/abc' asFilename withoutSuffix            
  5357      '/foo/bar.x/baz' asFilename withoutSuffix     
  5391      '/foo/bar.x/baz' asFilename withoutSuffix     
  5358      '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
  5392      '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
  5359      '/foo/bar/baz/foo.c/bar.c' asFilename withoutSuffix   
  5393      '/foo/bar/baz/foo.c/bar.c' asFilename withoutSuffix   
  5360     "
  5394     "
  5361 
  5395 
  5362     "Modified: 7.9.1995 / 11:15:42 / claus"
  5396     "Modified: / 07-09-1995 / 11:15:42 / claus"
  5363     "Modified: 3.7.1996 / 10:49:58 / cg"
  5397     "Modified: / 07-11-2006 / 13:57:45 / cg"
  5364 ! !
  5398 ! !
  5365 
  5399 
  5366 !Filename methodsFor:'testing'!
  5400 !Filename methodsFor:'testing'!
  5367 
  5401 
  5368 isFilename
  5402 isFilename
  5375 ! !
  5409 ! !
  5376 
  5410 
  5377 !Filename class methodsFor:'documentation'!
  5411 !Filename class methodsFor:'documentation'!
  5378 
  5412 
  5379 version
  5413 version
  5380     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.308 2006-11-06 10:45:32 cg Exp $'
  5414     ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.309 2006-11-07 12:58:59 cg Exp $'
  5381 ! !
  5415 ! !
  5382 
  5416 
  5383 Filename initialize!
  5417 Filename initialize!