diff --git a/ChangeLog b/ChangeLog index fafd6b0f7..c3a7573aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-11-06 Richard Frith-Macdonald + + * Source/GSString.m: ([GSMutableString substringWithRange:]) fix to + allocate inline string classes for substrings. + 2000-11-04 Richard Frith-Macdonald * Source/NSCalendarDate.m ([NSCalendarDate -initWithString: diff --git a/Source/GSString.m b/Source/GSString.m index db5b84377..5a56a25d7 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -2618,34 +2618,54 @@ transmute(ivars self, NSString *aString) - (NSString*) substringFromRange: (NSRange)aRange { + NSString *sub; + GS_RANGE_CHECK(aRange, _count); - + if (_flags.wide == 1) { - return [GSUnicodeStringClass stringWithCharacters: - self->_contents.u + aRange.location length: aRange.length]; + sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, + _count*sizeof(unichar), NSDefaultMallocZone()); + sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location + length: aRange.length + freeWhenDone: NO]; } else { - return [GSCStringClass stringWithCString: - self->_contents.c + aRange.location length: aRange.length]; + sub = (NSString*)NSAllocateObject(GSCInlineStringClass, + _count, NSDefaultMallocZone()); + sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location + length: aRange.length + freeWhenDone: NO]; } + AUTORELEASE(sub); + return sub; } - (NSString*) substringWithRange: (NSRange)aRange { + NSString *sub; + GS_RANGE_CHECK(aRange, _count); - + if (_flags.wide == 1) { - return [GSUnicodeStringClass stringWithCharacters: - self->_contents.u + aRange.location length: aRange.length]; + sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, + _count*sizeof(unichar), NSDefaultMallocZone()); + sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location + length: aRange.length + freeWhenDone: NO]; } else { - return [GSCStringClass stringWithCString: - self->_contents.c + aRange.location length: aRange.length]; + sub = (NSString*)NSAllocateObject(GSCInlineStringClass, + _count, NSDefaultMallocZone()); + sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location + length: aRange.length + freeWhenDone: NO]; } + AUTORELEASE(sub); + return sub; } // private method for Unicode level 3 implementation diff --git a/Testing/string.m b/Testing/string.m index 491278955..830299922 100644 --- a/Testing/string.m +++ b/Testing/string.m @@ -24,6 +24,7 @@ int main() id s = @"This is a test string"; id s2, s3; int a; + unichar uc[6] = { '1', '2', '.', '3', '4', 0}; NSMutableString *fo = [NSMutableString stringWithString: @"abcdefg"]; NS_DURING @@ -37,6 +38,8 @@ int main() s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100)); print_string(s2); + printf("%f", [[NSString stringWithCharacters: uc length: 5] floatValue]); + s2 = [s copy]; print_string(s2); s3 = [s2 mutableCopy];