Fix for substrings of mutable strings

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8043 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-11-06 14:15:27 +00:00
parent c19fd6da52
commit 324f4f6778
3 changed files with 38 additions and 10 deletions

View file

@ -1,3 +1,8 @@
2000-11-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: ([GSMutableString substringWithRange:]) fix to
allocate inline string classes for substrings.
2000-11-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSCalendarDate.m ([NSCalendarDate -initWithString:

View file

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

View file

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