Some string mnethod tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14448 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-09-15 18:26:56 +00:00
parent b864196732
commit dbadb72311
4 changed files with 58 additions and 50 deletions

View file

@ -4096,28 +4096,28 @@ handle_printf_atsign (FILE *stream,
*/
@implementation NSString (GNUstep)
/**
* Returns a string formed by removing the suffix string from the
* receiver. Raises an exception if the suffix is not present.
*/
- (NSString*) stringByRemovingSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: suffix],
@"'%@' does not have the suffix '%@'", self, suffix);
return [self substringToIndex: ([self length] - [suffix length])];
}
/**
* Returns a string formed by removing the prefix string from the
* receiver. Raises an exception if the prefix is not present.
*/
- (NSString*) stringByRemovingPrefix: (NSString*)prefix
- (NSString*) stringByDeletingPrefix: (NSString*)prefix
{
NSCAssert2([self hasPrefix: prefix],
@"'%@' does not have the prefix '%@'", self, prefix);
return [self substringFromIndex: [prefix length]];
}
/**
* Returns a string formed by removing the suffix string from the
* receiver. Raises an exception if the suffix is not present.
*/
- (NSString*) stringByDeletingSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: suffix],
@"'%@' does not have the suffix '%@'", self, suffix);
return [self substringToIndex: ([self length] - [suffix length])];
}
/**
* Returns a string formed by removing leading white space from the
* receiver.
@ -4252,6 +4252,29 @@ handle_printf_atsign (FILE *stream,
@implementation NSMutableString (GNUstep)
@class NSImmutableString;
@class GSImmutableString;
/**
* Removes the specified suffix from the string. Raises an exception
* if the suffix is not present.
*/
- (void) deleteSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: suffix],
@"'%@' does not have the suffix '%@'", self, suffix);
[self deleteCharactersInRange:
NSMakeRange([self length] - [suffix length], [suffix length])];
}
/**
* Removes the specified prefix from the string. Raises an exception
* if the prefix is not present.
*/
- (void) deletePrefix: (NSString*)prefix;
{
NSCAssert2([self hasPrefix: prefix],
@"'%@' does not have the prefix '%@'", self, prefix);
[self deleteCharactersInRange: NSMakeRange(0, [prefix length])];
}
/**
* Returns a proxy to the receiver which will allow access to the
* receiver as an NSString, but which will not allow any of the
@ -4271,29 +4294,6 @@ handle_printf_atsign (FILE *stream,
}
}
/**
* Removes the specified suffix from the string. Raises an exception
* if the suffix is not present.
*/
- (void) removeSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: suffix],
@"'%@' does not have the suffix '%@'", self, suffix);
[self deleteCharactersInRange:
NSMakeRange([self length] - [suffix length], [suffix length])];
}
/**
* Removes the specified prefix from the string. Raises an exception
* if the prefix is not present.
*/
- (void) removePrefix: (NSString*)prefix;
{
NSCAssert2([self hasPrefix: prefix],
@"'%@' does not have the prefix '%@'", self, prefix);
[self deleteCharactersInRange: NSMakeRange(0, [prefix length])];
}
/**
* Replaces all occurrances of the string replace with the string by
* in the receiver.<br />