Bugfix for substring creation from mutable string

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8069 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-11-08 17:22:50 +00:00
parent e3c7b3fae5
commit 50a5077519
2 changed files with 33 additions and 14 deletions

View file

@ -1,3 +1,8 @@
2000-11-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: ([GSMutableString substringWithRange:]) fix to
initialize inline string classes correctly.
2000-11-06 Adam Fedor <fedor@gnu.org> 2000-11-06 Adam Fedor <fedor@gnu.org>
* Documentation: Move tmpl.texi files to texi and update GNUmakefile * Documentation: Move tmpl.texi files to texi and update GNUmakefile

View file

@ -1755,6 +1755,15 @@ transmute(ivars self, NSString *aString)
* in memory immediately after the object. * in memory immediately after the object.
*/ */
@implementation GSCInlineString @implementation GSCInlineString
- (id) initWithCStringNoCopy: (char*)chars
length: (unsigned)length
freeWhenDone: (BOOL)flag
{
RELEASE(self);
[NSException raise: NSInternalInconsistencyException
format: @"Illegal method used to initialise inline string"];
return nil;
}
- (id) initWithCString: (const char*)chars length: (unsigned)length - (id) initWithCString: (const char*)chars length: (unsigned)length
{ {
if (_contents.c != 0) if (_contents.c != 0)
@ -1844,7 +1853,7 @@ transmute(ivars self, NSString *aString)
NSString *obj; NSString *obj;
obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
_count*2, z); _count*sizeof(unichar), z);
obj = [obj initWithCharacters: _contents.u length: _count]; obj = [obj initWithCharacters: _contents.u length: _count];
return obj; return obj;
} }
@ -2031,6 +2040,15 @@ transmute(ivars self, NSString *aString)
@implementation GSUnicodeInlineString @implementation GSUnicodeInlineString
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned)length
freeWhenDone: (BOOL)flag
{
RELEASE(self);
[NSException raise: NSInternalInconsistencyException
format: @"Illegal method used to initialise inline string"];
return nil;
}
- (id) initWithCharacters: (const unichar*)chars length: (unsigned)length - (id) initWithCharacters: (const unichar*)chars length: (unsigned)length
{ {
if (_contents.u != 0) if (_contents.u != 0)
@ -2039,7 +2057,7 @@ transmute(ivars self, NSString *aString)
format: @"re-initialisation of string"]; format: @"re-initialisation of string"];
} }
_count = length; _count = length;
_contents.u = (unichar*)&self[1]; _contents.u = (unichar*)&((GSUnicodeInlineString*)self)[1];
if (_count > 0) if (_count > 0)
memcpy(_contents.u, chars, length*sizeof(unichar)); memcpy(_contents.u, chars, length*sizeof(unichar));
_flags.wide = 1; _flags.wide = 1;
@ -2620,17 +2638,15 @@ transmute(ivars self, NSString *aString)
{ {
sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
_count*sizeof(unichar), NSDefaultMallocZone()); _count*sizeof(unichar), NSDefaultMallocZone());
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location sub = [sub initWithCharacters: self->_contents.u + aRange.location
length: aRange.length length: aRange.length];
freeWhenDone: NO];
} }
else else
{ {
sub = (NSString*)NSAllocateObject(GSCInlineStringClass, sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
_count, NSDefaultMallocZone()); _count, NSDefaultMallocZone());
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location sub = [sub initWithCString: self->_contents.c + aRange.location
length: aRange.length length: aRange.length];
freeWhenDone: NO];
} }
AUTORELEASE(sub); AUTORELEASE(sub);
return sub; return sub;
@ -2646,17 +2662,15 @@ transmute(ivars self, NSString *aString)
{ {
sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
_count*sizeof(unichar), NSDefaultMallocZone()); _count*sizeof(unichar), NSDefaultMallocZone());
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location sub = [sub initWithCharacters: self->_contents.u + aRange.location
length: aRange.length length: aRange.length];
freeWhenDone: NO];
} }
else else
{ {
sub = (NSString*)NSAllocateObject(GSCInlineStringClass, sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
_count, NSDefaultMallocZone()); _count, NSDefaultMallocZone());
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location sub = [sub initWithCString: self->_contents.c + aRange.location
length: aRange.length length: aRange.length];
freeWhenDone: NO];
} }
AUTORELEASE(sub); AUTORELEASE(sub);
return sub; return sub;