Various tidups.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7902 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-10-24 11:58:25 +00:00
parent bcb218e8c5
commit 5c87e04018
9 changed files with 164 additions and 68 deletions

View file

@ -1,3 +1,19 @@
2000-10-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: Implement ([-substringWithRange:]) and
([-substringFromRange:]) equally. The 'from' method is the
'official OpenStep' one, the 'with' method is a MacOS-X compatibility
addition.
* Source/NSAttributedString.m: Added ([-attributedSubstringWithRange:])
in the expectation that Apple will rename the method and remove
([-attributedSubstringFromRange:])
* Source/NSScanner.m: Use substringWithRange.
* Source/NSProxy.m: Implement ([-forward::]) to use
([-forwardInvocation:]). Implement ([-conformsToProtocol:]) to raise
exception, Implement ([-respondsToSelector:]) to raise exception.
* Source/NSDistantObject.m: Implement ([-conformsToProtocol:]) to
forward to remote. Implement ([-respondsToSelector:]) to forward.
2000-10-24 Fred Kiefer <FredKiefer@gmx.de> 2000-10-24 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSAttributedString.m: Added begin/endEditing to all * Source/NSAttributedString.m: Added begin/endEditing to all

View file

@ -84,6 +84,13 @@
//Extracting a substring //Extracting a substring
- (NSAttributedString*) attributedSubstringFromRange: (NSRange)aRange; - (NSAttributedString*) attributedSubstringFromRange: (NSRange)aRange;
#ifndef NO_GNUSTEP
/*
* Synonym for attributedSubstringFromRange: - for consistency with NSString
*/
- (NSAttributedString*) attributedSubstringWithRange: (NSRange)aRange;
#endif
@end //NSAttributedString @end //NSAttributedString

View file

@ -47,10 +47,6 @@
@end @end
@interface NSProxy(GNUstepExtensions)
- (id) forward: (SEL)aSel :(arglist_t)frame;
@end
@interface Object (IsProxy) @interface Object (IsProxy)
- (BOOL) isProxy; - (BOOL) isProxy;
@end @end

View file

@ -1066,6 +1066,40 @@ rangeOfString_u(ivars self, NSString *aString, unsigned mask, NSRange aRange)
return strRangeUsNs((id)self, aString, mask, aRange); return strRangeUsNs((id)self, aString, mask, aRange);
} }
static inline NSString*
substring_c(ivars self, NSRange aRange)
{
GSCSubString *sub;
sub = [GSCSubStringClass allocWithZone: NSDefaultMallocZone()];
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location
length: aRange.length
freeWhenDone: NO];
if (sub != nil)
{
sub->_parent = RETAIN((id)self);
AUTORELEASE(sub);
}
return sub;
}
static inline NSString*
substring_u(ivars self, NSRange aRange)
{
GSUSubString *sub;
sub = [GSUSubStringClass allocWithZone: NSDefaultMallocZone()];
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location
length: aRange.length
freeWhenDone: NO];
if (sub != nil)
{
sub->_parent = RETAIN((id)self);
AUTORELEASE(sub);
}
return sub;
}
/* /*
* Function to examine the given string and see if it is one of our concrete * Function to examine the given string and see if it is one of our concrete
* string classes. Converts the mutable string (self) from 8-bit to 16-bit * string classes. Converts the mutable string (self) from 8-bit to 16-bit
@ -1427,22 +1461,16 @@ transmute(ivars self, NSString *aString)
return defEnc; return defEnc;
} }
- (NSString*) substringFromRange: (NSRange)aRange
{
GS_RANGE_CHECK(aRange, _count);
return substring_c((ivars)self, aRange);
}
- (NSString*) substringWithRange: (NSRange)aRange - (NSString*) substringWithRange: (NSRange)aRange
{ {
GSCSubString *sub;
GS_RANGE_CHECK(aRange, _count); GS_RANGE_CHECK(aRange, _count);
return substring_c((ivars)self, aRange);
sub = [GSCSubStringClass allocWithZone: NSDefaultMallocZone()];
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location
length: aRange.length
freeWhenDone: NO];
if (sub != nil)
{
sub->_parent = RETAIN(self);
AUTORELEASE(sub);
}
return sub;
} }
// private method for Unicode level 3 implementation // private method for Unicode level 3 implementation
@ -1695,22 +1723,16 @@ transmute(ivars self, NSString *aString)
return NSUnicodeStringEncoding; return NSUnicodeStringEncoding;
} }
- (NSString*) substringFromRange: (NSRange)aRange
{
GS_RANGE_CHECK(aRange, _count);
return substring_u((ivars)self, aRange);
}
- (NSString*) substringWithRange: (NSRange)aRange - (NSString*) substringWithRange: (NSRange)aRange
{ {
GSUSubString *sub;
GS_RANGE_CHECK(aRange, _count); GS_RANGE_CHECK(aRange, _count);
return substring_u((ivars)self, aRange);
sub = [GSUStringClass allocWithZone: NSDefaultMallocZone()];
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location
length: aRange.length
freeWhenDone: NO];
if (sub != nil)
{
sub->_parent = RETAIN(self);
AUTORELEASE(sub);
}
return sub;
} }
// private method for Unicode level 3 implementation // private method for Unicode level 3 implementation
@ -2267,6 +2289,22 @@ transmute(ivars self, NSString *aString)
return defEnc; return defEnc;
} }
- (NSString*) substringFromRange: (NSRange)aRange
{
GS_RANGE_CHECK(aRange, _count);
if (_flags.wide == 1)
{
return [GSUStringClass stringWithCharacters:
self->_contents.u + aRange.location length: aRange.length];
}
else
{
return [GSCStringClass stringWithCString:
self->_contents.c + aRange.location length: aRange.length];
}
}
- (NSString*) substringWithRange: (NSRange)aRange - (NSString*) substringWithRange: (NSRange)aRange
{ {
GS_RANGE_CHECK(aRange, _count); GS_RANGE_CHECK(aRange, _count);

View file

@ -248,7 +248,7 @@ static Class NSMutableAttributedString_concrete_class;
(attrs = [self attributesAtIndex: index effectiveRange: &r]) != nil) (attrs = [self attributesAtIndex: index effectiveRange: &r]) != nil)
{ {
index = NSMaxRange(r); index = NSMaxRange(r);
[desc appendFormat: @"%@%@", [string substringFromRange: r], attrs]; [desc appendFormat: @"%@%@", [string substringWithRange: r], attrs];
} }
return desc; return desc;
} }
@ -487,7 +487,7 @@ static Class NSMutableAttributedString_concrete_class;
GS_RANGE_CHECK(aRange, len); GS_RANGE_CHECK(aRange, len);
newSubstring = [[self string] substringFromRange: aRange]; newSubstring = [[self string] substringWithRange: aRange];
attrs = [self attributesAtIndex: aRange.location effectiveRange: &range]; attrs = [self attributesAtIndex: aRange.location effectiveRange: &range];
range = NSIntersectionRange(range, aRange); range = NSIntersectionRange(range, aRange);
@ -522,6 +522,11 @@ static Class NSMutableAttributedString_concrete_class;
return newAttrString; return newAttrString;
} }
- (NSAttributedString*) attributedSubstringWithRange: (NSRange)aRange
{
return [self attributedSubstringFromRange: aRange];
}
@end //NSAttributedString @end //NSAttributedString
@implementation NSMutableAttributedString @implementation NSMutableAttributedString

View file

@ -899,6 +899,42 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject)
return object_get_class (self); return object_get_class (self);
} }
- (BOOL) conformsToProtocol: (Protocol*)aProtocol
{
arglist_t args;
void *retframe;
BOOL retframe_bool (void *rframe)
{
__builtin_return (rframe);
}
/*
* Try forwarding the message.
*/
args = __builtin_apply_args();
retframe = [self forward: _cmd : args];
return retframe_bool(retframe);
}
- (BOOL) respondsToSelector: (SEL)aSelector
{
arglist_t args;
void *retframe;
BOOL retframe_bool (void *rframe)
{
__builtin_return (rframe);
}
/*
* Try forwarding the message.
*/
args = __builtin_apply_args();
retframe = [self forward: _cmd : args];
return retframe_bool(retframe);
}
- (id) replacementObjectForCoder: (NSCoder*)aCoder - (id) replacementObjectForCoder: (NSCoder*)aCoder
{ {
return self; return self;

View file

@ -856,8 +856,8 @@ static BOOL deallocNotifications = NO;
{ {
NSInvocation *inv; NSInvocation *inv;
inv = [[[NSInvocation alloc] initWithArgframe: argFrame inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame
selector: aSel] autorelease]; selector: aSel]);
[self forwardInvocation:inv]; [self forwardInvocation:inv];
return [inv returnFrame: argFrame]; return [inv returnFrame: argFrame];
} }
@ -1399,9 +1399,9 @@ static BOOL deallocNotifications = NO;
- (id) subclassResponsibility: (SEL)aSel - (id) subclassResponsibility: (SEL)aSel
{ {
[NSException [NSException raise: NSGenericException
raise: NSGenericException format: @"subclass %s should override %s", object_get_class_name(self),
format: @"subclass %s should override %s", object_get_class_name(self), sel_get_name(aSel)]; sel_get_name(aSel)];
return nil; return nil;
} }

View file

@ -86,7 +86,9 @@
- (id) autorelease - (id) autorelease
{ {
[NSAutoreleasePool addObject:self]; #if GS_WITH_GC == 0
[NSAutoreleasePool addObject: self];
#endif
return self; return self;
} }
@ -95,22 +97,13 @@
return object_get_class(self); return object_get_class(self);
} }
#if 0
- (BOOL) conformsToProtocol: (Protocol*)aProtocol - (BOOL) conformsToProtocol: (Protocol*)aProtocol
{ {
NSInvocation *inv; [NSException raise: NSGenericException
NSMethodSignature *sig; format: @"subclass %s should override %s", object_get_class_name(self),
BOOL result; sel_get_name(_cmd)];
return NO;
sig = [self methodSignatureForSelector:@selector(conformsToProtocol:)];
inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setSelector:@selector(conformsToProtocol:)];
[inv setArgument:aProtocol atIndex:2];
[self forwardInvocation:inv];
[inv getReturnValue: &result];
return result;
} }
#endif
- (void) dealloc - (void) dealloc
{ {
@ -123,6 +116,16 @@
object_get_class_name(self), (unsigned long)self]; object_get_class_name(self), (unsigned long)self];
} }
- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame
{
NSInvocation *inv;
inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame
selector: aSel]);
[self forwardInvocation:inv];
return [inv returnFrame: argFrame];
}
- (void) forwardInvocation: (NSInvocation*)anInvocation - (void) forwardInvocation: (NSInvocation*)anInvocation
{ {
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
@ -241,32 +244,27 @@
- (void) release - (void) release
{ {
#if GS_WITH_GC == 0
if (_retain_count-- == 0) if (_retain_count-- == 0)
{ {
[self dealloc]; [self dealloc];
} }
#endif
} }
#if 0
- (BOOL) respondsToSelector: (SEL)aSelector - (BOOL) respondsToSelector: (SEL)aSelector
{ {
NSInvocation* inv; [NSException raise: NSGenericException
NSMethodSignature* sig; format: @"subclass %s should override %s", object_get_class_name(self),
BOOL result; sel_get_name(_cmd)];
return NO;
sig = [self methodSignatureForSelector:@selector(respondsToSelector:)];
inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setSelector:@selector(respondsToSelector:)];
[inv setArgument:(void*)aSelector atIndex:2];
[self forwardInvocation:inv];
[inv getReturnValue: &result];
return result;
} }
#endif
- (id) retain - (id) retain
{ {
#if GS_WITH_GC == 0
_retain_count++; _retain_count++;
#endif
return self; return self;
} }

View file

@ -732,7 +732,7 @@ typedef struct {
range.location = start; range.location = start;
range.length = _scanLocation - start; range.length = _scanLocation - start;
*value = [_string substringFromRange: range]; *value = [_string substringWithRange: range];
} }
return YES; return YES;
} }
@ -795,7 +795,7 @@ typedef struct {
range.location = start; range.location = start;
range.length = _scanLocation - start; range.length = _scanLocation - start;
*value = [_string substringFromRange: range]; *value = [_string substringWithRange: range];
} }
return YES; return YES;
} }
@ -827,7 +827,7 @@ typedef struct {
return NO; return NO;
} }
if (value) if (value)
*value = [_string substringFromRange: range]; *value = [_string substringWithRange: range];
_scanLocation += range.length; _scanLocation += range.length;
return YES; return YES;
} }
@ -860,7 +860,7 @@ typedef struct {
return NO; return NO;
} }
if (value) if (value)
*value = [_string substringFromRange: range]; *value = [_string substringWithRange: range];
_scanLocation += range.length; _scanLocation += range.length;
return YES; return YES;
} }