Fix to conform to MacOS-X documentation

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9950 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-05-15 13:35:28 +00:00
parent 1f7efc480e
commit 5dfb5c0a5d
2 changed files with 58 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2001-05-15 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: ([stringByDeletingPathExtension]) rewrite to
conform to MacOS-X documentation.
([pathComponents]) ditto.
2001-05-14 Adam Fedor <fedor@gnu.org>
* Headers/gnustep/base/objc-gnu2next.h: Add error prototypes.

View file

@ -2540,18 +2540,48 @@ handle_printf_atsign (FILE *stream,
return substring;
}
/* Returns a new string with the path extension removed from the receiver.
See pathExtension for a definition of the path extension */
/*
* Returns a new string with the path extension removed from the receiver.
* Strips any trailing path separators before checking for the extension
* separator.
*/
- (NSString*) stringByDeletingPathExtension
{
NSRange range;
NSString *substring;
NSRange range;
NSRange r0;
NSRange r1;
NSString *substring;
unsigned length = [self length];
range = [self rangeOfString: [self pathExtension] options: NSBackwardsSearch];
if (range.length != 0)
substring = [self substringToIndex: range.location-1];
else
substring = AUTORELEASE([self copy]);
/*
* Skip past any trailing path separators... but not a leading one.
*/
while (length > 1 && pathSepMember([self characterAtIndex: length-1]) == YES)
{
length--;
}
range = NSMakeRange(0, length);
/*
* Locate path extension.
*/
r0 = [self rangeOfString: @"."
options: NSBackwardsSearch
range: range];
/*
* Locate a path separator.
*/
r1 = [self rangeOfCharacterFromSet: pathSeps()
options: NSBackwardsSearch
range: range];
/*
* Assuming the extension separator was found in the last path
* component, set the length of the substring we want.
*/
if (r0.length > 0 && (r1.length == 0 || r1.location < r0.location))
{
length = r0.location;
}
substring = [self substringToIndex: length];
return substring;
}
@ -2958,7 +2988,8 @@ handle_printf_atsign (FILE *stream,
{
int i;
/* If the path began with a '/' then the first path component must
/*
* If the path began with a '/' then the first path component must
* be a '/' rather than an empty string so that our output could be
* fed into [+pathWithComponents: ]
*/
@ -2966,6 +2997,17 @@ handle_printf_atsign (FILE *stream,
{
[a replaceObjectAtIndex: 0 withObject: pathSepString];
}
/*
* Similarly if the path ended with a path separator (other than the
* leading one).
*/
if ([[a objectAtIndex: [a count]-1] length] == 0)
{
if ([self length] > 1)
{
[a replaceObjectAtIndex: [a count]-1 withObject: pathSepString];
}
}
/* Any empty path components must be removed. */
for (i = [a count] - 1; i > 0; i--)
{