Move more additional methods to the Additions libtrary.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16299 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2003-03-31 02:59:56 +00:00
parent ac22c2d05f
commit 0bfcabe78e
16 changed files with 511 additions and 258 deletions

View file

@ -4318,139 +4318,6 @@ handle_printf_atsign (FILE *stream,
@end
/**
* GNUstep specific (non-standard) additions to the NSString class.
* The methods in this category are not available in MacOS-X
*/
@implementation NSString (GNUstep)
/**
* Returns a string formed by removing leading white space from the
* receiver.
*/
- (NSString*) stringByTrimmingLeadSpaces
{
unsigned length = [self length];
if (length > 0)
{
unsigned start = 0;
unichar (*caiImp)(NSString*, SEL, unsigned int);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (start < length && isspace((*caiImp)(self, caiSel, start)))
{
start++;
}
if (start > 0)
{
return [self substringFromIndex: start];
}
}
return self;
}
/**
* Returns a string formed by removing trailing white space from the
* receiver.
*/
- (NSString*) stringByTrimmingTailSpaces
{
unsigned length = [self length];
if (length > 0)
{
unsigned end = length;
unichar (*caiImp)(NSString*, SEL, unsigned int);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (end > 0)
{
if (!isspace((*caiImp)(self, caiSel, end - 1)))
{
break;
}
end--;
}
if (end < length)
{
return [self substringToIndex: end];
}
}
return self;
}
/**
* Returns a string formed by removing both leading and trailing
* white space from the receiver.
*/
- (NSString*) stringByTrimmingSpaces
{
unsigned length = [self length];
if (length > 0)
{
unsigned start = 0;
unsigned end = length;
unichar (*caiImp)(NSString*, SEL, unsigned int);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (start < length && isspace((*caiImp)(self, caiSel, start)))
{
start++;
}
while (end > start)
{
if (!isspace((*caiImp)(self, caiSel, end - 1)))
{
break;
}
end--;
}
if (start > 0 || end < length)
{
if (start < end)
{
return [self substringFromRange:
NSMakeRange(start, end - start)];
}
else
{
return [NSStringClass string];
}
}
}
return self;
}
/**
* Returns a string in which any (and all) occurrances of
* replace in the receiver have been replaced with by.
* Returns the receiver if replace
* does not occur within the receiver. NB. an empty string is
* not considered to exist within the receiver.
*/
- (NSString*) stringByReplacingString: (NSString*)replace
withString: (NSString*)by
{
NSRange range = [self rangeOfString: replace];
if (range.length > 0)
{
NSMutableString *tmp = [self mutableCopy];
NSString *str;
[tmp replaceString: replace withString: by];
str = AUTORELEASE([tmp copy]);
RELEASE(tmp);
return str;
}
else
return self;
}
@end
/**
* GNUstep specific (non-standard) additions to the NSMutableString class.
* The methods in this category are not available in MacOS-X
@ -4478,81 +4345,6 @@ handle_printf_atsign (FILE *stream,
}
}
/**
* Replaces all occurrances of the string replace with the string by
* in the receiver.<br />
* Has no effect if replace does not occur within the
* receiver. NB. an empty string is not considered to exist within
* the receiver.<br />
* Calls - replaceOccurrencesOfString:withString:options:range: passing
* zero for the options and a range from 0 with the length of the receiver.
*/
- (void) replaceString: (NSString*)replace
withString: (NSString*)by
{
[self replaceOccurrencesOfString: replace
withString: by
options: 0
range: NSMakeRange(0, [self length])];
}
/**
* Removes all leading white space from the receiver.
*/
- (void) trimLeadSpaces
{
unsigned length = [self length];
if (length > 0)
{
unsigned start = 0;
unichar (*caiImp)(NSString*, SEL, unsigned int);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (start < length && isspace((*caiImp)(self, caiSel, start)))
{
start++;
}
if (start > 0)
{
[self deleteCharactersInRange: NSMakeRange(0, start)];
}
}
}
/**
* Removes all trailing white space from the receiver.
*/
- (void) trimTailSpaces
{
unsigned length = [self length];
if (length > 0)
{
unsigned end = length;
unichar (*caiImp)(NSString*, SEL, unsigned int);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
while (end > 0 && isspace((*caiImp)(self, caiSel, end - 1)))
{
end--;
}
if (end < length)
{
[self deleteCharactersInRange: NSMakeRange(end, length - end)];
}
}
}
/**
* Removes all leading or trailing white space from the receiver.
*/
- (void) trimSpaces
{
[self trimTailSpaces];
[self trimLeadSpaces];
}
@end