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 Frith-MacDonald 2000-10-24 11:58:25 +00:00
parent 677b2a8d9e
commit dec9cb1e22
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>
* Source/NSAttributedString.m: Added begin/endEditing to all

View file

@ -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

View file

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

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}