git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14376 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-08-30 12:30:50 +00:00
parent d1591b0ea3
commit cbd9112a25
5 changed files with 133 additions and 109 deletions

View file

@ -3,6 +3,8 @@
* Source/NSString.m: Implemented new MacOS-X methods -
([-stringByPaddingToLength:withString:startingAtIndex:]), and
([-stringByTrimmingCharactersInSet:])
Tidied a couple of extension method names for consistency and
documented several methods.
2002-08-29 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -362,28 +362,22 @@ extern struct objc_class _NSConstantStringClassReference;
#ifndef NO_GNUSTEP
@interface NSString (GSString)
- (NSString*) stringWithoutSuffix: (NSString*)_suffix;
- (NSString*) stringWithoutPrefix: (NSString*)_prefix;
- (NSString*) stringByReplacingString: (NSString*)_replace
withString: (NSString*)_by;
@end
@interface NSString(GSTrimming)
@interface NSString (GNUstep)
- (NSString*) stringByRemovingPrefix: (NSString*)prefix;
- (NSString*) stringByRemovingSuffix: (NSString*)suffix;
- (NSString*) stringByReplacingString: (NSString*)replace
withString: (NSString*)by;
- (NSString*) stringByTrimmingLeadSpaces;
- (NSString*) stringByTrimmingTailSpaces;
- (NSString*) stringByTrimmingSpaces;
@end
@interface NSMutableString (GSString)
@interface NSMutableString (GNUstep)
- (NSString*) immutableProxy;
- (void) removeSuffix: (NSString*)_suffix;
- (void) removePrefix: (NSString*)_prefix;
- (void) replaceString: (NSString*)_replace
withString: (NSString*)_by;
@end
@interface NSMutableString (GSTrimming)
- (void) removeSuffix: (NSString*)suffix;
- (void) removePrefix: (NSString*)prefix;
- (void) replaceString: (NSString*)replace
withString: (NSString*)by;
- (void) trimLeadSpaces;
- (void) trimTailSpaces;
- (void) trimSpaces;

View file

@ -3923,7 +3923,9 @@ handle_printf_atsign (FILE *stream,
@end
/**
* This is the mutable form of the NSString class.
*/
@implementation NSMutableString
+ (id) allocWithZone: (NSZone*)z
@ -4086,10 +4088,40 @@ handle_printf_atsign (FILE *stream,
@end
#ifndef NO_GNUSTEP
@implementation NSString (GSTrimming)
/**
* 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 the suffix string from the
* receiver. Raises an exception if the suffix is not present.
*/
- (NSString*) stringByRemovingSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: suffix],
@"'%@' has not 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
{
NSCAssert2([self hasPrefix: prefix],
@"'%@' has not the prefix '%@'", self, prefix);
return [self substringFromIndex: [prefix length]];
}
/**
* Returns a string formed by removing leading white space from the
* receiver.
*/
- (NSString*) stringByTrimmingLeadSpaces
{
unsigned length = [self length];
@ -4112,6 +4144,10 @@ handle_printf_atsign (FILE *stream,
return self;
}
/**
* Returns a string formed by removing trailing white space from the
* receiver.
*/
- (NSString*) stringByTrimmingTailSpaces
{
unsigned length = [self length];
@ -4138,6 +4174,10 @@ handle_printf_atsign (FILE *stream,
return self;
}
/**
* Returns a string formed by removing both leading and trailing
* white space from the receiver.
*/
- (NSString*) stringByTrimmingSpaces
{
unsigned length = [self length];
@ -4177,80 +4217,6 @@ handle_printf_atsign (FILE *stream,
return self;
}
@end
@implementation NSMutableString (GSTrimming)
- (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)];
}
}
}
- (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)
{
if (!isspace((*caiImp)(self, caiSel, end - 1)))
{
break;
}
end--;
}
if (end < length)
{
[self deleteCharactersInRange: NSMakeRange(end, length - end)];
}
}
}
- (void) trimSpaces
{
[self trimTailSpaces];
[self trimLeadSpaces];
}
@end
@implementation NSString (GNUstep)
- (NSString*) stringWithoutSuffix: (NSString*)_suffix
{
NSCAssert2([self hasSuffix: _suffix],
@"'%@' has not the suffix '%@'",self,_suffix);
return [self substringToIndex: ([self length] - [_suffix length])];
}
- (NSString*) stringWithoutPrefix: (NSString*)_prefix
{
NSCAssert2([self hasPrefix: _prefix],
@"'%@' has not the prefix '%@'",self,_prefix);
return [self substringFromIndex: [_prefix length]];
}
/**
* Returns a string in which any (and all) occurrances of
* replace in the receiver have been replaced with by.
@ -4279,6 +4245,10 @@ handle_printf_atsign (FILE *stream,
@end
/**
* GNUstep specific (non-standard) additions to the NSMutableString class.
* The methods in this category are not available in MacOS-X
*/
@implementation NSMutableString (GNUstep)
@class NSImmutableString;
@class GSImmutableString;
@ -4303,25 +4273,25 @@ handle_printf_atsign (FILE *stream,
/**
* Removes the specified suffix from the string. Raises an exception
* if the prefix is not present.
* if the suffix is not present.
*/
- (void) removeSuffix: (NSString*)_suffix
- (void) removeSuffix: (NSString*)suffix
{
NSCAssert2([self hasSuffix: _suffix],
@"'%@' has not the suffix '%@'",self,_suffix);
NSCAssert2([self hasSuffix: suffix],
@"'%@' has not the suffix '%@'", self, suffix);
[self deleteCharactersInRange:
NSMakeRange([self length] - [_suffix length], [_suffix length])];
NSMakeRange([self length] - [suffix length], [suffix length])];
}
/**
* Removes the specified prefx from the string. Raises an exception
* Removes the specified prefix from the string. Raises an exception
* if the prefix is not present.
*/
- (void) removePrefix: (NSString*)_prefix;
- (void) removePrefix: (NSString*)prefix;
{
NSCAssert2([self hasPrefix: _prefix],
@"'%@' has not the prefix '%@'",self,_prefix);
[self deleteCharactersInRange: NSMakeRange(0, [_prefix length])];
NSCAssert2([self hasPrefix: prefix],
@"'%@' has not the prefix '%@'", self, prefix);
[self deleteCharactersInRange: NSMakeRange(0, [prefix length])];
}
/**
@ -4353,6 +4323,68 @@ handle_printf_atsign (FILE *stream,
while (range.length > 0);
}
}
/**
* 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)
{
if (!isspace((*caiImp)(self, caiSel, end - 1)))
{
break;
}
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
@ -5369,4 +5401,4 @@ GSPropertyListFromStringsFormat(NSString *string)
}
return AUTORELEASE(dict);
}
#endif /* NO_GNUSTEP */

View file

@ -43,7 +43,6 @@
static Class threadClass = Nil;
static NSNotificationCenter *nc = nil;
#ifndef NO_GNUSTEP
#if !defined(HAVE_OBJC_THREAD_ADD) && !defined(NeXT_RUNTIME)
/* We need to access these private vars in the objc runtime - because
the objc runtime's API is not enough powerful for the GNUstep
@ -67,7 +66,6 @@ inline static void objc_thread_remove ()
objc_mutex_unlock(__objc_runtime_mutex);
}
#endif /* not HAVE_OBJC_THREAD_ADD */
#endif
@interface NSThread (Private)
- (id) _initWithSelector: (SEL)s toTarget: (id)t withObject: (id)o;
@ -482,7 +480,6 @@ gnustep_base_thread_callback()
objc_thread_set_data(self);
_active = YES;
#ifndef NO_GNUSTEP
/*
* Let observers know a new thread is starting.
*/
@ -493,7 +490,6 @@ gnustep_base_thread_callback()
[nc postNotificationName: NSThreadDidStartNotification
object: self
userInfo: nil];
#endif
[_target performSelector: _selector withObject: _arg];
[NSThread exit];

View file

@ -113,7 +113,7 @@
extracted and wrapped round the rest of the documentation for
the class as the classes chapter.
The rest of the class documentation is normally
inserted at the end of the chapter, but may instead be sbstituted
inserted at the end of the chapter, but may instead be substituted
in in place of the &lt;unit /&gt; pseudo-element within the
&lt;chapter&gt; element.
</item>