From 5c87e04018c5132ede59cfa8fcb35dc9458fa352 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 24 Oct 2000 11:58:25 +0000 Subject: [PATCH] Various tidups. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7902 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 16 ++++ Headers/gnustep/base/NSAttributedString.h | 7 ++ Headers/gnustep/base/NSProxy.h | 4 - Source/GSString.m | 90 ++++++++++++++++------- Source/NSAttributedString.m | 9 ++- Source/NSDistantObject.m | 36 +++++++++ Source/NSObject.m | 10 +-- Source/NSProxy.m | 52 +++++++------ Source/NSScanner.m | 8 +- 9 files changed, 164 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d9edc88e..cc9db637b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2000-10-24 Richard Frith-Macdonald + + * 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 * Source/NSAttributedString.m: Added begin/endEditing to all diff --git a/Headers/gnustep/base/NSAttributedString.h b/Headers/gnustep/base/NSAttributedString.h index 02f2ba9cf..fdf541909 100644 --- a/Headers/gnustep/base/NSAttributedString.h +++ b/Headers/gnustep/base/NSAttributedString.h @@ -84,6 +84,13 @@ //Extracting a substring - (NSAttributedString*) attributedSubstringFromRange: (NSRange)aRange; +#ifndef NO_GNUSTEP +/* + * Synonym for attributedSubstringFromRange: - for consistency with NSString + */ +- (NSAttributedString*) attributedSubstringWithRange: (NSRange)aRange; +#endif + @end //NSAttributedString diff --git a/Headers/gnustep/base/NSProxy.h b/Headers/gnustep/base/NSProxy.h index 18d5452b0..df9088542 100644 --- a/Headers/gnustep/base/NSProxy.h +++ b/Headers/gnustep/base/NSProxy.h @@ -47,10 +47,6 @@ @end -@interface NSProxy(GNUstepExtensions) -- (id) forward: (SEL)aSel :(arglist_t)frame; -@end - @interface Object (IsProxy) - (BOOL) isProxy; @end diff --git a/Source/GSString.m b/Source/GSString.m index 2e4879943..89a5fe992 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1066,6 +1066,40 @@ rangeOfString_u(ivars self, NSString *aString, unsigned mask, NSRange 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 * string classes. Converts the mutable string (self) from 8-bit to 16-bit @@ -1427,22 +1461,16 @@ transmute(ivars self, NSString *aString) return defEnc; } +- (NSString*) substringFromRange: (NSRange)aRange +{ + GS_RANGE_CHECK(aRange, _count); + return substring_c((ivars)self, aRange); +} + - (NSString*) substringWithRange: (NSRange)aRange { - GSCSubString *sub; - GS_RANGE_CHECK(aRange, _count); - - 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; + return substring_c((ivars)self, aRange); } // private method for Unicode level 3 implementation @@ -1695,22 +1723,16 @@ transmute(ivars self, NSString *aString) return NSUnicodeStringEncoding; } +- (NSString*) substringFromRange: (NSRange)aRange +{ + GS_RANGE_CHECK(aRange, _count); + return substring_u((ivars)self, aRange); +} + - (NSString*) substringWithRange: (NSRange)aRange { - GSUSubString *sub; - GS_RANGE_CHECK(aRange, _count); - - 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; + return substring_u((ivars)self, aRange); } // private method for Unicode level 3 implementation @@ -2267,6 +2289,22 @@ transmute(ivars self, NSString *aString) 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 { GS_RANGE_CHECK(aRange, _count); diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 6071c1aae..82a2c0838 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -248,7 +248,7 @@ static Class NSMutableAttributedString_concrete_class; (attrs = [self attributesAtIndex: index effectiveRange: &r]) != nil) { index = NSMaxRange(r); - [desc appendFormat: @"%@%@", [string substringFromRange: r], attrs]; + [desc appendFormat: @"%@%@", [string substringWithRange: r], attrs]; } return desc; } @@ -487,7 +487,7 @@ static Class NSMutableAttributedString_concrete_class; GS_RANGE_CHECK(aRange, len); - newSubstring = [[self string] substringFromRange: aRange]; + newSubstring = [[self string] substringWithRange: aRange]; attrs = [self attributesAtIndex: aRange.location effectiveRange: &range]; range = NSIntersectionRange(range, aRange); @@ -522,6 +522,11 @@ static Class NSMutableAttributedString_concrete_class; return newAttrString; } +- (NSAttributedString*) attributedSubstringWithRange: (NSRange)aRange +{ + return [self attributedSubstringFromRange: aRange]; +} + @end //NSAttributedString @implementation NSMutableAttributedString diff --git a/Source/NSDistantObject.m b/Source/NSDistantObject.m index 5eff4481f..2896092a1 100644 --- a/Source/NSDistantObject.m +++ b/Source/NSDistantObject.m @@ -899,6 +899,42 @@ static inline BOOL class_is_kind_of (Class self, Class aClassObject) 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 { return self; diff --git a/Source/NSObject.m b/Source/NSObject.m index 000ca91e7..9b7151072 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -856,8 +856,8 @@ static BOOL deallocNotifications = NO; { NSInvocation *inv; - inv = [[[NSInvocation alloc] initWithArgframe: argFrame - selector: aSel] autorelease]; + inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame + selector: aSel]); [self forwardInvocation:inv]; return [inv returnFrame: argFrame]; } @@ -1399,9 +1399,9 @@ static BOOL deallocNotifications = NO; - (id) subclassResponsibility: (SEL)aSel { - [NSException - raise: NSGenericException - format: @"subclass %s should override %s", object_get_class_name(self), sel_get_name(aSel)]; + [NSException raise: NSGenericException + format: @"subclass %s should override %s", object_get_class_name(self), + sel_get_name(aSel)]; return nil; } diff --git a/Source/NSProxy.m b/Source/NSProxy.m index 7251a21ef..cfbb9cd2d 100644 --- a/Source/NSProxy.m +++ b/Source/NSProxy.m @@ -86,7 +86,9 @@ - (id) autorelease { - [NSAutoreleasePool addObject:self]; +#if GS_WITH_GC == 0 + [NSAutoreleasePool addObject: self]; +#endif return self; } @@ -95,22 +97,13 @@ return object_get_class(self); } -#if 0 - (BOOL) conformsToProtocol: (Protocol*)aProtocol { - NSInvocation *inv; - NSMethodSignature *sig; - BOOL result; - - 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; + [NSException raise: NSGenericException + format: @"subclass %s should override %s", object_get_class_name(self), + sel_get_name(_cmd)]; + return NO; } -#endif - (void) dealloc { @@ -123,6 +116,16 @@ 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 { [NSException raise: NSInvalidArgumentException @@ -241,32 +244,27 @@ - (void) release { +#if GS_WITH_GC == 0 if (_retain_count-- == 0) { [self dealloc]; } +#endif } -#if 0 - (BOOL) respondsToSelector: (SEL)aSelector { - NSInvocation* inv; - NSMethodSignature* sig; - BOOL result; - - 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; + [NSException raise: NSGenericException + format: @"subclass %s should override %s", object_get_class_name(self), + sel_get_name(_cmd)]; + return NO; } -#endif - (id) retain { +#if GS_WITH_GC == 0 _retain_count++; +#endif return self; } diff --git a/Source/NSScanner.m b/Source/NSScanner.m index a16ab5ef6..33ad28a52 100644 --- a/Source/NSScanner.m +++ b/Source/NSScanner.m @@ -732,7 +732,7 @@ typedef struct { range.location = start; range.length = _scanLocation - start; - *value = [_string substringFromRange: range]; + *value = [_string substringWithRange: range]; } return YES; } @@ -795,7 +795,7 @@ typedef struct { range.location = start; range.length = _scanLocation - start; - *value = [_string substringFromRange: range]; + *value = [_string substringWithRange: range]; } return YES; } @@ -827,7 +827,7 @@ typedef struct { return NO; } if (value) - *value = [_string substringFromRange: range]; + *value = [_string substringWithRange: range]; _scanLocation += range.length; return YES; } @@ -860,7 +860,7 @@ typedef struct { return NO; } if (value) - *value = [_string substringFromRange: range]; + *value = [_string substringWithRange: range]; _scanLocation += range.length; return YES; }