git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22946 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-05-20 10:09:21 +00:00
parent 130716fd38
commit 700375a98e

View file

@ -125,11 +125,17 @@ we need to free the buffer when we are deallocated.
@interface GSCBufferString : GSCString @interface GSCBufferString : GSCString
{ {
} }
- (id) initWithCStringNoCopy: (char*)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag;
@end @end
@interface GSUnicodeBufferString : GSUnicodeString @interface GSUnicodeBufferString : GSUnicodeString
{ {
} }
- (id) initWithCharactersNoCopy: (unichar *)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag;
@end @end
@ -140,11 +146,13 @@ the instance iself.
@interface GSCInlineString : GSCString @interface GSCInlineString : GSCString
{ {
} }
- (id) initWithCString: (const char*)chars length: (unsigned)length;
@end @end
@interface GSUnicodeInlineString : GSUnicodeString @interface GSUnicodeInlineString : GSUnicodeString
{ {
} }
- (id) initWithCharacters: (const unichar*)chars length: (unsigned)length;
@end @end
@ -157,6 +165,8 @@ instance.
@public @public
GSCString *_parent; GSCString *_parent;
} }
- (id) initWithCString: (char *)chars length: (unsigned)length
fromParent: (GSCString *)parent;
@end @end
@interface GSUnicodeSubString : GSUnicodeString @interface GSUnicodeSubString : GSUnicodeString
@ -164,6 +174,8 @@ instance.
@public @public
GSUnicodeString *_parent; GSUnicodeString *_parent;
} }
- (id) initWithCharacters: (unichar *)chars length: (unsigned)length
fromParent: (GSUnicodeString *)parent;
@end @end
@ -463,7 +475,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
freeWhenDone: YES]; freeWhenDone: YES];
} }
- (id) initWithBytesNoCopy: (void*)bytes - (id) initWithBytesNoCopy: (const void*)bytes
length: (unsigned int)length length: (unsigned int)length
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
@ -478,7 +490,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
{ {
if (flag == YES && bytes != 0) if (flag == YES && bytes != 0)
{ {
NSZoneFree(NSZoneFromPointer(bytes), bytes); NSZoneFree(NSZoneFromPointer((void*)bytes), (void*)bytes);
} }
return nil; // Invalid encoding return nil; // Invalid encoding
} }
@ -606,7 +618,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
length: (unsigned)length length: (unsigned)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
return [self initWithBytesNoCopy: (void*)chars return [self initWithBytesNoCopy: (const void*)chars
length: length * sizeof(unichar) length: length * sizeof(unichar)
encoding: NSUnicodeStringEncoding encoding: NSUnicodeStringEncoding
freeWhenDone: flag]; freeWhenDone: flag];
@ -624,7 +636,7 @@ fixBOM(unsigned char **bytes, unsigned *length, BOOL *shouldFree,
length: (unsigned)length length: (unsigned)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
return [self initWithBytesNoCopy: (void*)chars return [self initWithBytesNoCopy: (const void*)chars
length: length length: length
encoding: externalEncoding encoding: externalEncoding
freeWhenDone: flag]; freeWhenDone: flag];
@ -2450,37 +2462,48 @@ rangeOfString_u(GSStr self, NSString *aString, unsigned mask, NSRange aRange)
static inline NSString* static inline NSString*
substring_c(GSStr self, NSRange aRange) substring_c(GSStr self, NSRange aRange)
{ {
struct { id sub;
@defs(GSCSubString)
} *o;
o = (typeof(o))NSAllocateObject(GSCSubStringClass, if (self->_flags.free == 1)
0, NSDefaultMallocZone()); {
o->_contents.c = self->_contents.c + aRange.location; sub = NSAllocateObject(GSCSubStringClass, 0, NSDefaultMallocZone());
o->_count = aRange.length; sub = [sub initWithCString: (char*)self->_contents.c + aRange.location
o->_flags.wide = 0; length: aRange.length
o->_flags.free = 0; fromParent: (GSCString *)self];
ASSIGN(o->_parent, self); }
AUTORELEASE((id)o); else
return (id)o; {
sub = NSAllocateObject(GSCInlineStringClass,
aRange.length, NSDefaultMallocZone());
sub = [sub initWithCString: (char*)self->_contents.c + aRange.location
length: aRange.length];
}
AUTORELEASE(sub);
return sub;
} }
static inline NSString* static inline NSString*
substring_u(GSStr self, NSRange aRange) substring_u(GSStr self, NSRange aRange)
{ {
struct { id sub;
@defs(GSUnicodeSubString)
} *o;
o = (typeof(o))NSAllocateObject(GSUnicodeSubStringClass, if (self->_flags.free == 1)
0, NSDefaultMallocZone()); {
o->_contents.u = self->_contents.u + aRange.location; sub = NSAllocateObject(GSUnicodeSubStringClass, 0, NSDefaultMallocZone());
o->_count = aRange.length; sub = [sub initWithCharacters: self->_contents.u + aRange.location
o->_flags.wide = 1; length: aRange.length
o->_flags.free = 0; fromParent: (GSUnicodeString *)self];
ASSIGN(o->_parent, self); }
AUTORELEASE((id)o); else
return (id)o; {
sub = NSAllocateObject(GSUnicodeInlineStringClass,
aRange.length*sizeof(unichar),
NSDefaultMallocZone());
sub = [sub initWithCharacters: self->_contents.u + aRange.location
length: aRange.length];
}
AUTORELEASE(sub);
return sub;
} }
/* /*
@ -2601,13 +2624,13 @@ transmute(GSStr self, NSString *aString)
memcpy(tmp, chars, length); memcpy(tmp, chars, length);
chars = tmp; chars = tmp;
} }
return [self initWithBytesNoCopy: (void*)chars return [self initWithBytesNoCopy: chars
length: length length: length
encoding: encoding encoding: encoding
freeWhenDone: YES]; freeWhenDone: YES];
} }
- (id) initWithBytesNoCopy: (void*)chars - (id) initWithBytesNoCopy: (const void*)chars
length: (unsigned int)length length: (unsigned int)length
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
@ -2621,7 +2644,7 @@ transmute(GSStr self, NSString *aString)
return nil; return nil;
} }
- (id) initWithCharacters: (const unichar*)chars - (id) initWithCharacters: (unichar*)chars
length: (unsigned int)length length: (unsigned int)length
{ {
return [self initWithBytes: chars return [self initWithBytes: chars
@ -2639,14 +2662,14 @@ transmute(GSStr self, NSString *aString)
freeWhenDone: flag]; freeWhenDone: flag];
} }
- (id) initWithCString: (const char*)chars - (id) initWithCString: (char*)chars
{ {
return [self initWithBytes: chars return [self initWithBytes: chars
length: strlen(chars) length: strlen(chars)
encoding: externalEncoding]; encoding: externalEncoding];
} }
- (id) initWithCString: (const char*)chars - (id) initWithCString: (char*)chars
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
{ {
return [self initWithBytes: chars return [self initWithBytes: chars
@ -2654,7 +2677,7 @@ transmute(GSStr self, NSString *aString)
encoding: encoding]; encoding: encoding];
} }
- (id) initWithCString: (const char*)chars - (id) initWithCString: (char*)chars
length: (unsigned int)length length: (unsigned int)length
{ {
return [self initWithBytes: chars return [self initWithBytes: chars
@ -2911,17 +2934,11 @@ agree, create a new GSCInlineString otherwise.
{ {
if (!_flags.free || NSShouldRetainWithZone(self, z) == NO) if (!_flags.free || NSShouldRetainWithZone(self, z) == NO)
{ {
struct { NSString *obj;
@defs(GSCInlineString)
} *o;
o = (typeof(o))NSAllocateObject(GSCInlineStringClass, _count, z); obj = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, z);
o->_contents.c = (unsigned char*)&o[1]; obj = [obj initWithCString: (char*)_contents.c length: _count];
o->_count = _count; return obj;
memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0;
o->_flags.free = 0;
return (id)o;
} }
else else
{ {
@ -2934,6 +2951,25 @@ agree, create a new GSCInlineString otherwise.
@implementation GSCBufferString @implementation GSCBufferString
- (id) initWithCStringNoCopy: (char*)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag
{
if (_contents.c != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.c = (unsigned char*)chars;
_flags.wide = 0;
if (flag == YES)
{
_flags.free = 1;
}
return self;
}
- (void) dealloc - (void) dealloc
{ {
if (_flags.free && _contents.c != 0) if (_flags.free && _contents.c != 0)
@ -2948,6 +2984,22 @@ agree, create a new GSCInlineString otherwise.
@implementation GSCInlineString @implementation GSCInlineString
- (id) initWithCString: (const char*)chars length: (unsigned)length
{
if (_contents.c != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.c = (unsigned char*)&self[1];
if (_count > 0)
memcpy(_contents.c, chars, length);
_flags.wide = 0;
_flags.free = 1;
return self;
}
- (void) dealloc - (void) dealloc
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
@ -2957,23 +3009,32 @@ agree, create a new GSCInlineString otherwise.
@implementation GSCSubString @implementation GSCSubString
- (id) initWithCString: (char *)chars length: (unsigned)length
fromParent: (GSCString *)parent
{
if (_contents.c != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.c = (unsigned char *)chars;
_flags.wide = 0;
_flags.free = 1;
ASSIGN(_parent, parent);
return self;
}
/* /*
* Assume that a copy should be a new string, never just a retained substring. * Assume that a copy should be a new string, never just a retained substring.
*/ */
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
struct { NSString *obj;
@defs(GSCInlineString)
} *o;
o = (typeof(o))NSAllocateObject(GSCInlineStringClass, _count, z); obj = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, z);
o->_contents.c = (unsigned char*)&o[1]; obj = [obj initWithCString: (char*)_contents.c length: _count];
o->_count = _count; return obj;
memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0;
o->_flags.free = 0;
return (id)o;
} }
- (void) dealloc - (void) dealloc
@ -3147,9 +3208,7 @@ agree, create a new GSCInlineString otherwise.
obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0,
NSDefaultMallocZone()); NSDefaultMallocZone());
obj = [obj initWithBytes: (const void*)_contents.u obj = [obj initWithCharacters: _contents.u length: _count];
length: _count * sizeof(unichar)
encoding: NSUnicodeStringEncoding];
return obj; return obj;
} }
@ -3158,9 +3217,7 @@ agree, create a new GSCInlineString otherwise.
GSMutableString *obj; GSMutableString *obj;
obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, z); obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, z);
obj = [obj initWithBytes: (const void*)_contents.u obj = [obj initWithCharacters: _contents.u length: _count];
length: _count * sizeof(unichar)
encoding: NSUnicodeStringEncoding];
return obj; return obj;
} }
@ -3221,18 +3278,12 @@ agree, create a new GSUnicodeInlineString otherwise.
{ {
if (!_flags.free || NSShouldRetainWithZone(self, z) == NO) if (!_flags.free || NSShouldRetainWithZone(self, z) == NO)
{ {
struct { NSString *obj;
@defs(GSUnicodeInlineString)
} *o;
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass, obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
_count * sizeof(unichar), z); _count*sizeof(unichar), z);
o->_contents.u = (unichar*)&o[1]; obj = [obj initWithCharacters: _contents.u length: _count];
o->_count = _count; return obj;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1;
o->_flags.free = 0;
return (id)o;
} }
else else
{ {
@ -3245,6 +3296,62 @@ agree, create a new GSUnicodeInlineString otherwise.
@implementation GSUnicodeBufferString @implementation GSUnicodeBufferString
- (id) initWithCharactersNoCopy: (unichar *)chars
length: (unsigned int)length
freeWhenDone: (BOOL)flag
{
BOOL isASCII;
BOOL isLatin1;
if (GSUnicode(chars, length, &isASCII, &isLatin1) != length)
{
RELEASE(self);
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return nil; // Invalid data
}
if (isASCII == YES
|| (internalEncoding == NSISOLatin1StringEncoding && isLatin1 == YES))
{
GSStr me;
/*
* OK ... we can do a more compact version
*/
me = (GSStr)NSAllocateObject(GSCInlineStringClass, length,
GSObjCZone(self));
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1];
me->_count = length;
me->_flags.wide = 0;
me->_flags.free = 1;
while (length-- > 0)
{
me->_contents.c[length] = (unsigned char)chars[length];
}
RELEASE(self);
if (flag == YES && chars != 0)
{
NSZoneFree(NSZoneFromPointer(chars), chars);
}
return (id)me;
}
if (_contents.u != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.u = chars;
_flags.wide = 1;
if (flag == YES)
{
_flags.free = 1;
}
return self;
}
- (void) dealloc - (void) dealloc
{ {
if (_flags.free && _contents.u != 0) if (_flags.free && _contents.u != 0)
@ -3259,6 +3366,51 @@ agree, create a new GSUnicodeInlineString otherwise.
@implementation GSUnicodeInlineString @implementation GSUnicodeInlineString
- (id) initWithCharacters: (const unichar*)chars length: (unsigned)length
{
BOOL isASCII;
BOOL isLatin1;
if (GSUnicode(chars, length, &isASCII, &isLatin1) != length)
{
RELEASE(self);
return nil; // Invalid data
}
if (isASCII == YES
|| (internalEncoding == NSISOLatin1StringEncoding && isLatin1 == YES))
{
GSStr me;
/*
* OK ... we can do a more compact version
*/
me = (GSStr)NSAllocateObject(GSCInlineStringClass, length,
GSObjCZone(self));
me->_contents.c = (unsigned char*)&((GSCInlineString*)me)[1];
me->_count = length;
me->_flags.wide = 0;
me->_flags.free = 1;
while (length-- > 0)
{
me->_contents.c[length] = (unsigned char)chars[length];
}
RELEASE(self);
return (id)me;
}
if (_contents.u != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.u = (unichar*)&((GSUnicodeInlineString*)self)[1];
if (_count > 0)
memcpy(_contents.u, chars, length*sizeof(unichar));
_flags.wide = 1;
_flags.free = 1;
return self;
}
- (void) dealloc - (void) dealloc
{ {
NSDeallocateObject(self); NSDeallocateObject(self);
@ -3268,24 +3420,33 @@ agree, create a new GSUnicodeInlineString otherwise.
@implementation GSUnicodeSubString @implementation GSUnicodeSubString
- (id) initWithCharacters: (unichar *)chars length: (unsigned)length
fromParent: (GSUnicodeString *)parent
{
if (_contents.u != 0)
{
[NSException raise: NSInternalInconsistencyException
format: @"re-initialisation of string"];
}
_count = length;
_contents.u = chars;
_flags.wide = 1;
_flags.free = 1;
ASSIGN(_parent, parent);
return self;
}
/* /*
* Assume that a copy should be a new string, never just a retained substring. * Assume that a copy should be a new string, never just a retained substring.
*/ */
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
struct { NSString *obj;
@defs(GSUnicodeInlineString)
} *o;
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass, obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
_count * sizeof(unichar), z); _count*sizeof(unichar), z);
o->_contents.u = (unichar*)&o[1]; obj = [obj initWithCharacters: _contents.u length: _count];
o->_count = _count; return obj;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1;
o->_flags.free = 0;
return (id)o;
} }
- (void) dealloc - (void) dealloc
@ -3391,35 +3552,29 @@ agree, create a new GSUnicodeInlineString otherwise.
- (id) copyWithZone: (NSZone*)z - (id) copyWithZone: (NSZone*)z
{ {
GSMutableString *copy;
if (_flags.wide == 1) if (_flags.wide == 1)
{ {
struct { copy = (GSMutableString*)NSAllocateObject(GSUnicodeInlineStringClass,
@defs(GSUnicodeInlineString) _count*sizeof(unichar), z);
} *o; copy->_contents.u = (unichar*)&((GSUnicodeInlineString*)copy)[1];
copy->_count = _count;
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass, copy->_flags.wide = 1;
_count * sizeof(unichar), z); copy->_flags.free = 0;
o->_contents.u = (unichar*)&o[1]; memcpy(copy->_contents.u, _contents.u, _count * sizeof(unichar));
o->_count = _count;
memcpy(o->_contents.u, _contents.u, _count * sizeof(unichar));
o->_flags.wide = 1;
o->_flags.free = 0;
return (id)o;
} }
else else
{ {
struct { copy = (GSMutableString*)NSAllocateObject(GSCInlineStringClass,
@defs(GSCInlineString) _count, z);
} *o; copy->_contents.c = (unsigned char*)&((GSCInlineString*)copy)[1];
copy->_count = _count;
o = (typeof(o))NSAllocateObject(GSCInlineStringClass, _count, z); copy->_flags.wide = 0;
o->_contents.c = (unsigned char*)&o[1]; copy->_flags.free = 0;
o->_count = _count; memcpy(copy->_contents.c, _contents.c, _count);
memcpy(o->_contents.c, _contents.c, _count);
o->_flags.wide = 0;
o->_flags.free = 0;
return (id)o;
} }
return copy;
} }
- (const char *) cString - (const char *) cString
@ -3731,17 +3886,21 @@ agree, create a new GSUnicodeInlineString otherwise.
} }
} }
- (id) initWithBytesNoCopy: (void*)bytes - (id) initWithBytesNoCopy: (const void*)bytes
length: (unsigned int)length length: (unsigned int)length
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
/*
* We can't use a 'const void*' as our buffer because we are going to
* modify it ... so we do a copy anyway and free the original if needed.
*/
self = [self initWithBytes: bytes self = [self initWithBytes: bytes
length: length length: length
encoding: encoding]; encoding: encoding];
if (flag == YES && bytes != 0) if (flag == YES && bytes != 0)
{ {
NSZoneFree(NSZoneFromPointer(bytes), bytes); NSZoneFree(NSZoneFromPointer((void*)bytes), (void*)bytes);
} }
return self; return self;
} }
@ -3887,11 +4046,9 @@ agree, create a new GSUnicodeInlineString otherwise.
NSDefaultMallocZone()); NSDefaultMallocZone());
if (_flags.wide == 1) if (_flags.wide == 1)
obj = [obj initWithBytes: (void*)_contents.u obj = [obj initWithCharacters: _contents.u length: _count];
length: _count * sizeof(unichar)
encoding: NSUnicodeStringEncoding];
else else
obj = [obj initWithBytes: (void*)_contents.c obj = [obj initWithBytes: (char*)_contents.c
length: _count length: _count
encoding: internalEncoding]; encoding: internalEncoding];
return obj; return obj;
@ -3904,9 +4061,7 @@ agree, create a new GSUnicodeInlineString otherwise.
obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, z); obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, z);
if (_flags.wide == 1) if (_flags.wide == 1)
obj = [obj initWithBytes: (void*)_contents.u obj = [obj initWithCharacters: _contents.u length: _count];
length: _count * sizeof(unichar)
encoding: NSUnicodeStringEncoding];
else else
obj = [obj initWithBytes: (char*)_contents.c obj = [obj initWithBytes: (char*)_contents.c
length: _count length: _count
@ -4124,76 +4279,52 @@ agree, create a new GSUnicodeInlineString otherwise.
- (NSString*) substringFromRange: (NSRange)aRange - (NSString*) substringFromRange: (NSRange)aRange
{ {
NSString *sub;
GS_RANGE_CHECK(aRange, _count); GS_RANGE_CHECK(aRange, _count);
if (_flags.wide == 1) if (_flags.wide == 1)
{ {
struct { sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
@defs(GSUnicodeInlineString) _count*sizeof(unichar), NSDefaultMallocZone());
} *o; sub = [sub initWithCharacters: self->_contents.u + aRange.location
length: aRange.length];
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass,
aRange.length * sizeof(unichar), NSDefaultMallocZone());
o->_contents.u = (unichar*)&o[1];
o->_count = aRange.length;
memcpy(o->_contents.u, _contents.u + aRange.location,
aRange.length * sizeof(unichar));
o->_flags.wide = 1;
o->_flags.free = 0;
return AUTORELEASE((id)o);
} }
else else
{ {
struct { sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
@defs(GSCInlineString) _count, NSDefaultMallocZone());
} *o; sub = [sub initWithCString: (char*)self->_contents.c + aRange.location
length: aRange.length];
o = (typeof(o))NSAllocateObject(GSCInlineStringClass,
aRange.length, NSDefaultMallocZone());
o->_contents.c = (unsigned char*)&o[1];
o->_count = aRange.length;
memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length);
o->_flags.wide = 0;
o->_flags.free = 0;
return AUTORELEASE((id)o);
} }
AUTORELEASE(sub);
return sub;
} }
- (NSString*) substringWithRange: (NSRange)aRange - (NSString*) substringWithRange: (NSRange)aRange
{ {
NSString *sub;
GS_RANGE_CHECK(aRange, _count); GS_RANGE_CHECK(aRange, _count);
if (_flags.wide == 1) if (_flags.wide == 1)
{ {
struct { sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
@defs(GSUnicodeInlineString) (aRange.length)*sizeof(unichar),
} *o; NSDefaultMallocZone());
sub = [sub initWithCharacters: self->_contents.u + aRange.location
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass, length: aRange.length];
aRange.length * sizeof(unichar), NSDefaultMallocZone());
o->_contents.u = (unichar*)&o[1];
o->_count = aRange.length;
memcpy(o->_contents.u, _contents.u + aRange.location,
aRange.length * sizeof(unichar));
o->_flags.wide = 1;
o->_flags.free = 0;
return AUTORELEASE((id)o);
} }
else else
{ {
struct { sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
@defs(GSCInlineString) aRange.length,
} *o; NSDefaultMallocZone());
sub = [sub initWithCString: (char*)self->_contents.c + aRange.location
o = (typeof(o))NSAllocateObject(GSCInlineStringClass, length: aRange.length];
aRange.length, NSDefaultMallocZone());
o->_contents.c = (unsigned char*)&o[1];
o->_count = aRange.length;
memcpy(o->_contents.c, _contents.c + aRange.location, aRange.length);
o->_flags.wide = 0;
o->_flags.free = 0;
return AUTORELEASE((id)o);
} }
AUTORELEASE(sub);
return sub;
} }
// private method for Unicode level 3 implementation // private method for Unicode level 3 implementation
@ -4632,7 +4763,7 @@ agree, create a new GSUnicodeInlineString otherwise.
*/ */
#define _self ((GSStr)self) #define _self ((GSStr)self)
- (id) initWithBytes: (const void*)bytes - (id) initWithBytes: (void*)bytes
length: (unsigned int)length length: (unsigned int)length
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
{ {
@ -4842,6 +4973,134 @@ agree, create a new GSUnicodeInlineString otherwise.
@end @end
/*
* Some classes for backward compatibility with archives.
*/
@interface NSGCString : NSString
@end
@implementation NSGCString
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
RELEASE(self);
self = (id)NSAllocateObject(GSCBufferStringClass, 0, NSDefaultMallocZone());
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0)
{
unsigned char *chars;
chars = NSZoneMalloc(NSDefaultMallocZone(), count+1);
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
count: count
at: chars];
self = [self initWithCStringNoCopy: (char*)chars
length: count
freeWhenDone: YES];
}
else
{
self = [self initWithCStringNoCopy: (char*)0 length: 0 freeWhenDone: NO];
}
return self;
}
@end
@interface NSGMutableCString : NSMutableString
@end
@implementation NSGMutableCString
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
RELEASE(self);
self = (id)NSAllocateObject(GSMutableStringClass, 0, NSDefaultMallocZone());
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0)
{
unsigned char *chars;
chars = NSZoneMalloc(NSDefaultMallocZone(), count+1);
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
count: count
at: chars];
self = [self initWithCStringNoCopy: (char*)chars
length: count
freeWhenDone: YES];
}
else
{
self = [self initWithCStringNoCopy: (char*)0 length: 0 freeWhenDone: NO];
}
return self;
}
@end
@interface NSGString : NSString
@end
@implementation NSGString
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
RELEASE(self);
self = (id)NSAllocateObject(GSUnicodeBufferStringClass, 0, NSDefaultMallocZone());
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0)
{
unichar *chars;
chars = NSZoneMalloc(NSDefaultMallocZone(), count*sizeof(unichar));
[aCoder decodeArrayOfObjCType: @encode(unichar)
count: count
at: chars];
self = [self initWithCharactersNoCopy: chars
length: count
freeWhenDone: YES];
}
else
{
self = [self initWithCharactersNoCopy: 0 length: 0 freeWhenDone: NO];
}
return self;
}
@end
@interface NSGMutableString : NSMutableString
@end
@implementation NSGMutableString
- (id) initWithCoder: (NSCoder*)aCoder
{
unsigned count;
NSLog(@"Warning - decoding archive containing obsolete %@ object - please delete/replace this archive", NSStringFromClass([self class]));
RELEASE(self);
self = (id)NSAllocateObject(GSMutableStringClass, 0, NSDefaultMallocZone());
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0)
{
unichar *chars;
chars = NSZoneMalloc(NSDefaultMallocZone(), count*sizeof(unichar));
[aCoder decodeArrayOfObjCType: @encode(unichar)
count: count
at: chars];
self = [self initWithCharactersNoCopy: chars
length: count
freeWhenDone: YES];
}
else
{
self = [self initWithCharactersNoCopy: 0 length: 0 freeWhenDone: NO];
}
return self;
}
@end
/** /**
* Append characters to a string. * Append characters to a string.
*/ */