1995-04-03 01:38:23 +00:00
|
|
|
|
/* Implementation for GNUStep of NSStrings with C-string backing
|
1998-10-15 05:03:16 +00:00
|
|
|
|
Copyright (C) 1993,1994, 1996, 1997, 1998 Free Software Foundation, Inc.
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-04-03 01:38:23 +00:00
|
|
|
|
Date: March 1995
|
1998-10-15 05:03:16 +00:00
|
|
|
|
Optimised by: Richard frith-Macdoanld <richard@brainstorm.co.uk>
|
|
|
|
|
Date: October 1998
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-08-25 14:47:19 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1995-04-03 01:38:23 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/preface.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1998-10-15 05:03:16 +00:00
|
|
|
|
#include <Foundation/NSCoder.h>
|
1999-05-06 12:21:58 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
|
#include <Foundation/NSCharacterSet.h>
|
1999-06-21 08:30:26 +00:00
|
|
|
|
#include <Foundation/NSRange.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/NSGString.h>
|
|
|
|
|
#include <base/NSGCString.h>
|
|
|
|
|
#include <base/IndexedCollection.h>
|
|
|
|
|
#include <base/IndexedCollectionPrivate.h>
|
1996-02-22 16:05:47 +00:00
|
|
|
|
#include <Foundation/NSValue.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/behavior.h>
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/Unicode.h>
|
|
|
|
|
#include <base/fast.x>
|
1997-05-03 18:05:21 +00:00
|
|
|
|
|
1999-05-20 09:20:46 +00:00
|
|
|
|
/*
|
|
|
|
|
* Include sequence handling code with instructions to generate search
|
|
|
|
|
* and compare functions for NSString objects.
|
|
|
|
|
*/
|
|
|
|
|
#define GSEQ_STRCOMP strCompCsNs
|
|
|
|
|
#define GSEQ_STRRANGE strRangeCsNs
|
|
|
|
|
#define GSEQ_O GSEQ_NS
|
|
|
|
|
#define GSEQ_S GSEQ_CS
|
|
|
|
|
#include <GSeq.h>
|
|
|
|
|
|
|
|
|
|
#define GSEQ_STRCOMP strCompCsUs
|
|
|
|
|
#define GSEQ_STRRANGE strRangeCsUs
|
|
|
|
|
#define GSEQ_O GSEQ_US
|
|
|
|
|
#define GSEQ_S GSEQ_CS
|
|
|
|
|
#include <GSeq.h>
|
|
|
|
|
|
|
|
|
|
#define GSEQ_STRCOMP strCompCsCs
|
|
|
|
|
#define GSEQ_STRRANGE strRangeCsCs
|
|
|
|
|
#define GSEQ_O GSEQ_CS
|
|
|
|
|
#define GSEQ_S GSEQ_CS
|
|
|
|
|
#include <GSeq.h>
|
|
|
|
|
|
1999-05-06 12:21:58 +00:00
|
|
|
|
/*
|
|
|
|
|
* Include property-list parsing code configured for ascii characters.
|
|
|
|
|
*/
|
|
|
|
|
#define GSPLUNI 0
|
|
|
|
|
#include "propList.h"
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
static SEL csInitSel = @selector(initWithCStringNoCopy: length: fromZone:);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
static SEL msInitSel = @selector(initWithCapacity:);
|
|
|
|
|
static IMP csInitImp; /* designated initialiser for cString */
|
|
|
|
|
static IMP msInitImp; /* designated initialiser for mutable */
|
|
|
|
|
|
1999-05-26 17:09:21 +00:00
|
|
|
|
@interface NSGMutableCString (GNUDescription)
|
1999-07-26 20:21:04 +00:00
|
|
|
|
- (unsigned char*) _extendBy: (unsigned)len;
|
1999-05-26 17:09:21 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1995-08-09 15:45:46 +00:00
|
|
|
|
@implementation NSGCString
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1998-10-26 08:15:20 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
static int done = 0;
|
|
|
|
|
if (!done)
|
|
|
|
|
{
|
|
|
|
|
done = 1;
|
|
|
|
|
csInitImp = [NSGCString instanceMethodForSelector: csInitSel];
|
|
|
|
|
msInitImp = [NSGMutableCString instanceMethodForSelector: msInitSel];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
1998-10-25 07:56:22 +00:00
|
|
|
|
{
|
1999-07-02 13:26:37 +00:00
|
|
|
|
return NSAllocateObject(self, 0, z);
|
1998-10-25 07:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
+ (id) alloc
|
1998-10-25 08:31:37 +00:00
|
|
|
|
{
|
1999-07-02 13:26:37 +00:00
|
|
|
|
return NSAllocateObject(self, 0, NSDefaultMallocZone());
|
1998-10-25 08:31:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void)dealloc
|
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
if (_zone)
|
|
|
|
|
{
|
|
|
|
|
NSZoneFree(_zone, (void*)_contents_chars);
|
|
|
|
|
_zone = 0;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
[super dealloc];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-03 15:31:33 +00:00
|
|
|
|
- (unsigned) hash
|
|
|
|
|
{
|
|
|
|
|
if (_hash == 0)
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
_hash = _fastImp._NSString_hash(self, @selector(hash));
|
|
|
|
|
}
|
1998-08-03 15:31:33 +00:00
|
|
|
|
return _hash;
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-26 08:15:20 +00:00
|
|
|
|
/*
|
|
|
|
|
* This is the GNUstep designated initializer for this class.
|
|
|
|
|
* NB. this does NOT change the '_hash' instance variable, so the copy
|
|
|
|
|
* methods can safely allocate a new object, copy the _hash into place,
|
|
|
|
|
* and then invoke this method to complete the copy operation.
|
|
|
|
|
*/
|
1995-04-03 01:38:23 +00:00
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
1998-10-15 05:03:16 +00:00
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
fromZone: (NSZone*)zone
|
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_count = length;
|
1999-07-26 20:21:04 +00:00
|
|
|
|
_contents_chars = (unsigned char*)byteString;
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_zone = byteString ? GSAtomicMallocZone() : 0;
|
|
|
|
|
#else
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_zone = byteString ? zone : 0;
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#endif
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return self;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is the OpenStep designated initializer for this class. */
|
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
freeWhenDone: (BOOL)flag
|
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSZone *z;
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (flag && byteString)
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
z = NSZoneFromPointer(byteString);
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
z = 0;
|
|
|
|
|
}
|
|
|
|
|
return (*csInitImp)(self, csInitSel, byteString, length, z);
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
fromZone: (NSZone*)zone
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSZone *z = zone ? zone : fastZone(self);
|
|
|
|
|
id a = [[NSGString allocWithZone: z] initWithCharactersNoCopy: chars
|
|
|
|
|
length: length
|
|
|
|
|
fromZone: z];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return a;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
1998-10-26 08:15:20 +00:00
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
freeWhenDone: (BOOL)flag
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSZone *z = fastZone(self);
|
|
|
|
|
id a = [[NSGString allocWithZone: z] initWithCharactersNoCopy: chars
|
|
|
|
|
length: length
|
|
|
|
|
freeWhenDone: flag];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return a;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-12-08 20:04:16 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
|
return [self initWithCStringNoCopy: 0 length: 0 fromZone: 0];
|
1997-12-08 20:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 16:05:47 +00:00
|
|
|
|
- (void) _collectionReleaseContents
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) _collectionDealloc
|
1995-10-18 16:47:59 +00:00
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
if (_zone)
|
|
|
|
|
{
|
|
|
|
|
NSZoneFree(_zone, (void*)_contents_chars);
|
|
|
|
|
_zone = 0;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &_count];
|
1998-10-26 18:06:51 +00:00
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
|
|
|
|
|
count: _count
|
|
|
|
|
at: _contents_chars];
|
1998-10-26 18:06:51 +00:00
|
|
|
|
}
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
|
|
|
|
at: &_count];
|
1998-10-26 08:15:20 +00:00
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_zone = GSAtomicMallocZone();
|
|
|
|
|
#else
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_zone = fastZone(self);
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#endif
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_contents_chars = NSZoneMalloc(_zone, _count);
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
|
|
|
|
|
count: _count
|
|
|
|
|
at: _contents_chars];
|
1998-10-26 08:15:20 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) copy
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
NSZone *z = NSDefaultMallocZone();
|
|
|
|
|
|
|
|
|
|
if (NSShouldRetainWithZone(self, z) == NO)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *obj;
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *tmp;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
|
|
|
|
|
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (_count)
|
|
|
|
|
{
|
|
|
|
|
tmp = NSZoneMalloc(z, _count);
|
|
|
|
|
memcpy(tmp, _contents_chars, _count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp = 0;
|
|
|
|
|
z = 0;
|
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
|
|
|
|
|
if (_hash && obj)
|
|
|
|
|
{
|
|
|
|
|
obj->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
return RETAIN(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)z
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (NSShouldRetainWithZone(self, z) == NO)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *obj;
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *tmp;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
|
|
|
|
|
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (_count)
|
|
|
|
|
{
|
|
|
|
|
tmp = NSZoneMalloc(z, _count);
|
|
|
|
|
memcpy(tmp, _contents_chars, _count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp = 0;
|
|
|
|
|
z = 0;
|
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
|
|
|
|
|
if (_hash && obj)
|
|
|
|
|
{
|
|
|
|
|
obj->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
return RETAIN(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) mutableCopy
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString,
|
|
|
|
|
0, NSDefaultMallocZone());
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *tmp = (NSGCString*)obj; // Same ivar layout!
|
|
|
|
|
|
|
|
|
|
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
|
|
|
|
tmp->_count = _count;
|
|
|
|
|
tmp->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)z
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString, 0, z);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *tmp = (NSGCString*)obj; // Same ivar layout!
|
|
|
|
|
|
|
|
|
|
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
|
|
|
|
tmp->_count = _count;
|
|
|
|
|
tmp->_hash = _hash;
|
|
|
|
|
}
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return obj;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const char *) cString
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *r = (unsigned char*)_fastMallocBuffer(_count+1);
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
|
|
|
|
memcpy(r, _contents_chars, _count);
|
|
|
|
|
r[_count] = '\0';
|
1999-07-26 20:21:04 +00:00
|
|
|
|
return (const char*)r;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-08-25 14:47:19 +00:00
|
|
|
|
- (const char *) lossyCString
|
|
|
|
|
{
|
|
|
|
|
unsigned char *r = (unsigned char*)_fastMallocBuffer(_count+1);
|
|
|
|
|
|
|
|
|
|
memcpy(r, _contents_chars, _count);
|
|
|
|
|
r[_count] = '\0';
|
|
|
|
|
return (const char*)r;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-03 15:31:33 +00:00
|
|
|
|
- (void) getCString: (char*)buffer
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1998-08-03 15:31:33 +00:00
|
|
|
|
memcpy(buffer, _contents_chars, _count);
|
|
|
|
|
buffer[_count] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) getCString: (char*)buffer
|
1998-10-15 05:03:16 +00:00
|
|
|
|
maxLength: (unsigned int)maxLength
|
1998-08-03 15:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (maxLength > _count)
|
|
|
|
|
maxLength = _count;
|
|
|
|
|
memcpy(buffer, _contents_chars, maxLength);
|
|
|
|
|
buffer[maxLength] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) getCString: (char*)buffer
|
1998-10-26 08:15:20 +00:00
|
|
|
|
maxLength: (unsigned int)maxLength
|
|
|
|
|
range: (NSRange)aRange
|
|
|
|
|
remainingRange: (NSRange*)leftoverRange
|
1998-08-03 15:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, _count);
|
1998-08-03 15:31:33 +00:00
|
|
|
|
if (maxLength < aRange.length)
|
|
|
|
|
{
|
|
|
|
|
len = maxLength;
|
|
|
|
|
if (leftoverRange)
|
|
|
|
|
{
|
|
|
|
|
leftoverRange->location = 0;
|
|
|
|
|
leftoverRange->length = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
len = aRange.length;
|
|
|
|
|
if (leftoverRange)
|
|
|
|
|
{
|
|
|
|
|
leftoverRange->location = aRange.location + maxLength;
|
|
|
|
|
leftoverRange->length = aRange.length - maxLength;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(buffer, &_contents_chars[aRange.location], len);
|
|
|
|
|
buffer[len] = '\0';
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned int) cStringLength
|
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
|
- (unsigned int) length
|
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
- (unichar) characterAtIndex: (unsigned int)index
|
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
1997-05-03 18:05:21 +00:00
|
|
|
|
return chartouni(_contents_chars[index]);
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-03 15:31:33 +00:00
|
|
|
|
- (void) getCharacters: (unichar*)buffer
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned i;
|
1998-08-03 15:31:33 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
buffer[i] = chartouni(((unsigned char *)_contents_chars)[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) getCharacters: (unichar*)buffer range: (NSRange)aRange
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned e, i;
|
1998-08-03 15:31:33 +00:00
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, _count);
|
1998-08-03 15:31:33 +00:00
|
|
|
|
e = aRange.location + aRange.length;
|
|
|
|
|
for (i = aRange.location; i < e; i++)
|
|
|
|
|
*buffer++ = chartouni(((unsigned char *)_contents_chars)[i]);
|
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
|
|
1996-09-07 17:47:24 +00:00
|
|
|
|
- (NSString*) substringFromRange: (NSRange)aRange
|
|
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, _count);
|
1996-09-07 17:54:08 +00:00
|
|
|
|
return [[self class] stringWithCString: _contents_chars + aRange.location
|
|
|
|
|
length: aRange.length];
|
1996-09-07 17:47:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (NSStringEncoding) fastestEncoding
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
if (([NSString defaultCStringEncoding] == NSASCIIStringEncoding)
|
|
|
|
|
|| ([NSString defaultCStringEncoding] == NSISOLatin1StringEncoding))
|
1997-09-01 21:59:51 +00:00
|
|
|
|
return [NSString defaultCStringEncoding];
|
|
|
|
|
else
|
|
|
|
|
return NSUnicodeStringEncoding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSStringEncoding) smallestEncoding
|
|
|
|
|
{
|
|
|
|
|
return [NSString defaultCStringEncoding];
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-01 05:22:47 +00:00
|
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
Class c;
|
|
|
|
|
if (anObject == self)
|
|
|
|
|
return YES;
|
1998-10-07 20:17:16 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
return NO;
|
1998-10-06 15:11:27 +00:00
|
|
|
|
c = fastClassOfInstance(anObject);
|
1998-10-03 21:23:04 +00:00
|
|
|
|
|
1999-08-25 14:47:19 +00:00
|
|
|
|
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
1998-10-01 05:22:47 +00:00
|
|
|
|
{
|
|
|
|
|
NSGCString *other = (NSGCString*)anObject;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
|
|
|
|
if (_hash == 0)
|
1998-10-09 04:24:56 +00:00
|
|
|
|
_hash = _fastImp._NSString_hash(self, @selector(hash));
|
1998-10-06 15:11:27 +00:00
|
|
|
|
if (other->_hash == 0)
|
1998-10-09 04:24:56 +00:00
|
|
|
|
other->_hash = _fastImp._NSString_hash(other, @selector(hash));
|
1998-10-01 05:22:47 +00:00
|
|
|
|
if (_hash != other->_hash)
|
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
1999-08-25 14:47:19 +00:00
|
|
|
|
else if (c == _fastCls._NXConstantString)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *other = (NSGCString*)anObject;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
1999-05-20 09:20:46 +00:00
|
|
|
|
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
{
|
|
|
|
|
if (strCompCsUs(self, anObject, 0, (NSRange){0,_count}) == NSOrderedSame)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1998-10-09 04:24:56 +00:00
|
|
|
|
else if (c == nil)
|
|
|
|
|
return NO;
|
|
|
|
|
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
|
|
|
|
return _fastImp._NSString_isEqualToString_(self,
|
|
|
|
|
@selector(isEqualToString:), anObject);
|
1998-10-01 05:22:47 +00:00
|
|
|
|
else
|
1998-10-09 04:24:56 +00:00
|
|
|
|
return NO;
|
1998-10-01 05:22:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (BOOL) isEqualToString: (NSString*)aString
|
|
|
|
|
{
|
1998-10-01 05:22:47 +00:00
|
|
|
|
Class c;
|
|
|
|
|
|
1998-10-07 20:17:16 +00:00
|
|
|
|
if (aString == self)
|
|
|
|
|
return YES;
|
|
|
|
|
if (aString == nil)
|
|
|
|
|
return NO;
|
1998-10-06 15:11:27 +00:00
|
|
|
|
c = fastClassOfInstance(aString);
|
1999-08-25 14:47:19 +00:00
|
|
|
|
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
1998-08-03 15:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
NSGCString *other = (NSGCString*)aString;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
1998-10-06 15:11:27 +00:00
|
|
|
|
if (_hash == 0)
|
1998-10-09 04:24:56 +00:00
|
|
|
|
_hash = _fastImp._NSString_hash(self, @selector(hash));
|
1998-10-06 15:11:27 +00:00
|
|
|
|
if (other->_hash == 0)
|
1998-10-09 04:24:56 +00:00
|
|
|
|
other->_hash = _fastImp._NSString_hash(other, @selector(hash));
|
1998-10-01 05:22:47 +00:00
|
|
|
|
if (_hash != other->_hash)
|
1998-08-03 15:31:33 +00:00
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
1999-08-25 14:47:19 +00:00
|
|
|
|
else if (c == _fastCls._NXConstantString)
|
|
|
|
|
{
|
|
|
|
|
NSGCString *other = (NSGCString*)aString;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
1999-05-20 09:20:46 +00:00
|
|
|
|
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
{
|
|
|
|
|
if (strCompCsUs(self, aString, 0, (NSRange){0,_count}) == NSOrderedSame)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1998-10-09 04:24:56 +00:00
|
|
|
|
else if (c == nil)
|
|
|
|
|
return NO;
|
|
|
|
|
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
|
|
|
|
return _fastImp._NSString_isEqualToString_(self,
|
|
|
|
|
@selector(isEqualToString:), aString);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
else
|
1998-10-09 04:24:56 +00:00
|
|
|
|
return NO;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1997-05-03 18:05:21 +00:00
|
|
|
|
|
1998-08-03 15:31:33 +00:00
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
// FOR IndexedCollection SUPPORT;
|
|
|
|
|
|
1996-02-22 16:05:47 +00:00
|
|
|
|
- objectAtIndex: (unsigned)index
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
1996-02-22 16:05:47 +00:00
|
|
|
|
return [NSNumber numberWithChar: _contents_chars[index]];
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-03 18:05:21 +00:00
|
|
|
|
- (int) _baseLength
|
|
|
|
|
{
|
|
|
|
|
return _count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithString: (NSString*)string
|
|
|
|
|
{
|
1999-07-02 13:26:37 +00:00
|
|
|
|
unsigned length = [string cStringLength];
|
|
|
|
|
NSZone *z;
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *buf;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (length > 0)
|
|
|
|
|
{
|
|
|
|
|
z = fastZone(self);
|
|
|
|
|
buf = NSZoneMalloc(z, length+1); // getCString appends a nul.
|
|
|
|
|
[string getCString: buf];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
z = 0;
|
|
|
|
|
buf = 0;
|
|
|
|
|
}
|
|
|
|
|
return [self initWithCStringNoCopy: buf length: length fromZone: z];
|
1997-05-03 18:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-12-18 17:15:49 +00:00
|
|
|
|
- (void) descriptionTo: (id<GNUDescriptionDestination>)output
|
1998-10-09 08:36:37 +00:00
|
|
|
|
{
|
1999-05-26 17:09:21 +00:00
|
|
|
|
if (output == nil)
|
|
|
|
|
return;
|
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (_count == 0)
|
|
|
|
|
{
|
|
|
|
|
[output appendString: @"\"\""];
|
1998-10-09 08:36:37 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
unsigned length = _count;
|
|
|
|
|
BOOL needQuote = NO;
|
1998-10-09 08:36:37 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char val = _contents_chars[i];
|
1998-10-09 08:36:37 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (isalnum(val))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
1998-10-23 04:34:46 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
switch (val)
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
case '\a':
|
|
|
|
|
case '\b':
|
|
|
|
|
case '\t':
|
|
|
|
|
case '\r':
|
|
|
|
|
case '\n':
|
|
|
|
|
case '\v':
|
|
|
|
|
case '\f':
|
|
|
|
|
case '\\':
|
|
|
|
|
case '"' :
|
1998-12-18 17:05:44 +00:00
|
|
|
|
length += 1;
|
|
|
|
|
break;
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
default:
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (val == ' ' || isprint(val))
|
|
|
|
|
{
|
|
|
|
|
needQuote = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-08-25 16:50:16 +00:00
|
|
|
|
length += 4;
|
1998-12-18 17:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
1998-10-09 08:36:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (needQuote || length != _count)
|
|
|
|
|
{
|
1999-05-26 17:09:21 +00:00
|
|
|
|
Class c = fastClass(output);
|
|
|
|
|
NSZone *z = NSDefaultMallocZone();
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *buf;
|
|
|
|
|
unsigned char *ptr;
|
1998-12-18 17:05:44 +00:00
|
|
|
|
|
1999-05-26 17:09:21 +00:00
|
|
|
|
length += 2;
|
|
|
|
|
if (c == _fastCls._NSGMutableCString)
|
|
|
|
|
{
|
|
|
|
|
buf = [(NSGMutableCString*)output _extendBy: length];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buf = NSZoneMalloc(z, length+1);
|
|
|
|
|
}
|
|
|
|
|
ptr = buf;
|
1998-12-18 17:05:44 +00:00
|
|
|
|
*ptr++ = '"';
|
|
|
|
|
for (i = 0; i < _count; i++)
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char val = _contents_chars[i];
|
1998-12-18 17:05:44 +00:00
|
|
|
|
|
|
|
|
|
switch (val)
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
case '\a': *ptr++ = '\\'; *ptr++ = 'a'; break;
|
|
|
|
|
case '\b': *ptr++ = '\\'; *ptr++ = 'b'; break;
|
|
|
|
|
case '\t': *ptr++ = '\\'; *ptr++ = 't'; break;
|
|
|
|
|
case '\r': *ptr++ = '\\'; *ptr++ = 'r'; break;
|
|
|
|
|
case '\n': *ptr++ = '\\'; *ptr++ = 'n'; break;
|
|
|
|
|
case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break;
|
|
|
|
|
case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break;
|
|
|
|
|
case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break;
|
|
|
|
|
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
|
|
|
|
|
|
|
|
|
|
default:
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (isprint(val) || val == ' ')
|
|
|
|
|
{
|
|
|
|
|
*ptr++ = val;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*ptr++ = '\\';
|
|
|
|
|
*ptr++ = '0';
|
|
|
|
|
*ptr++ = ((val&0700)>>6)+'0';
|
|
|
|
|
*ptr++ = ((val&070)>>3)+'0';
|
|
|
|
|
*ptr++ = (val&07)+'0';
|
|
|
|
|
}
|
|
|
|
|
break;
|
1998-10-09 08:36:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
*ptr++ = '"';
|
|
|
|
|
*ptr = '\0';
|
1999-05-26 17:09:21 +00:00
|
|
|
|
if (c != _fastCls._NSGMutableCString)
|
|
|
|
|
{
|
|
|
|
|
NSString *result;
|
|
|
|
|
|
|
|
|
|
result = [[_fastCls._NSGCString allocWithZone: z]
|
|
|
|
|
initWithCStringNoCopy: buf length: length fromZone: z];
|
|
|
|
|
[output appendString: result];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(result);
|
1999-05-26 17:09:21 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[output appendString: self];
|
1998-10-09 08:36:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-05-06 12:21:58 +00:00
|
|
|
|
|
|
|
|
|
- (id) propertyList
|
|
|
|
|
{
|
|
|
|
|
id result;
|
|
|
|
|
pldata data;
|
|
|
|
|
|
|
|
|
|
data.ptr = _contents_chars;
|
|
|
|
|
data.pos = 0;
|
|
|
|
|
data.end = _count;
|
|
|
|
|
data.lin = 1;
|
|
|
|
|
data.err = nil;
|
|
|
|
|
|
|
|
|
|
if (plInit == 0)
|
|
|
|
|
setupPl([NSGCString class]);
|
|
|
|
|
|
|
|
|
|
result = parsePlItem(&data);
|
|
|
|
|
|
|
|
|
|
if (result == nil && data.err != nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"%@ at line %u", data.err, data.lin];
|
|
|
|
|
}
|
1999-08-25 14:47:19 +00:00
|
|
|
|
return AUTORELEASE(result);
|
1999-05-06 12:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSDictionary*) propertyListFromStringsFileFormat
|
|
|
|
|
{
|
|
|
|
|
id result;
|
|
|
|
|
pldata data;
|
|
|
|
|
|
|
|
|
|
data.ptr = _contents_chars;
|
|
|
|
|
data.pos = 0;
|
|
|
|
|
data.end = _count;
|
|
|
|
|
data.lin = 1;
|
|
|
|
|
data.err = nil;
|
|
|
|
|
|
|
|
|
|
if (plInit == 0)
|
|
|
|
|
setupPl([NSGCString class]);
|
|
|
|
|
|
|
|
|
|
result = parseSfItem(&data);
|
|
|
|
|
if (result == nil && data.err != nil)
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"%@ at line %u", data.err, data.lin];
|
|
|
|
|
}
|
1999-08-25 14:47:19 +00:00
|
|
|
|
return AUTORELEASE(result);
|
1999-05-06 12:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-05-10 06:35:41 +00:00
|
|
|
|
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned)anIndex
|
|
|
|
|
{
|
|
|
|
|
if (anIndex >= _count)
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[NSException raise: NSRangeException format: @"Invalid location."];
|
1999-05-10 06:35:41 +00:00
|
|
|
|
return NSMakeRange(anIndex, 1);
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-20 09:20:46 +00:00
|
|
|
|
- (NSComparisonResult) compare: (NSString*)aString
|
|
|
|
|
options: (unsigned int)mask
|
|
|
|
|
range: (NSRange)aRange
|
|
|
|
|
{
|
1999-05-25 14:27:42 +00:00
|
|
|
|
Class c;
|
1999-05-20 09:20:46 +00:00
|
|
|
|
|
1999-05-25 14:27:42 +00:00
|
|
|
|
if (aString == nil)
|
|
|
|
|
[NSException raise: NSInvalidArgumentException format: @"compare with nil"];
|
|
|
|
|
c = fastClass(aString);
|
1999-05-20 09:20:46 +00:00
|
|
|
|
if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
return strCompCsUs(self, aString, mask, aRange);
|
|
|
|
|
else if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
|
|
|
|
|| c == _fastCls._NXConstantString)
|
|
|
|
|
return strCompCsCs(self, aString, mask, aRange);
|
|
|
|
|
else
|
|
|
|
|
return strCompCsNs(self, aString, mask, aRange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSRange) rangeOfString: (NSString *) aString
|
|
|
|
|
options: (unsigned int) mask
|
|
|
|
|
range: (NSRange) aRange
|
|
|
|
|
{
|
1999-05-25 14:27:42 +00:00
|
|
|
|
Class c;
|
1999-05-20 09:20:46 +00:00
|
|
|
|
|
1999-05-25 14:27:42 +00:00
|
|
|
|
if (aString == nil)
|
|
|
|
|
[NSException raise: NSInvalidArgumentException format: @"range of nil"];
|
|
|
|
|
c = fastClass(aString);
|
1999-05-20 09:20:46 +00:00
|
|
|
|
if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
return strRangeCsUs(self, aString, mask, aRange);
|
|
|
|
|
else if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
|
|
|
|
|| c == _fastCls._NXConstantString)
|
|
|
|
|
return strRangeCsCs(self, aString, mask, aRange);
|
|
|
|
|
else
|
|
|
|
|
return strRangeCsNs(self, aString, mask, aRange);
|
|
|
|
|
}
|
1999-05-10 06:35:41 +00:00
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
1995-08-09 15:46:35 +00:00
|
|
|
|
@implementation NSGMutableCString
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
1998-10-25 07:56:22 +00:00
|
|
|
|
{
|
1999-07-02 13:26:37 +00:00
|
|
|
|
return NSAllocateObject(self, 0, z);
|
1998-10-25 07:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
+ (id) alloc
|
1998-10-25 08:31:37 +00:00
|
|
|
|
{
|
1999-07-02 13:26:37 +00:00
|
|
|
|
return NSAllocateObject(self, 0, NSDefaultMallocZone());
|
1998-10-25 08:31:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
1995-04-05 20:25:08 +00:00
|
|
|
|
static int done = 0;
|
|
|
|
|
if (!done)
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1995-04-05 20:25:08 +00:00
|
|
|
|
done = 1;
|
1995-08-09 15:45:46 +00:00
|
|
|
|
class_add_behavior(self, [NSGCString class]);
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
1995-08-09 15:46:35 +00:00
|
|
|
|
@defs(NSGMutableCString)
|
|
|
|
|
} NSGMutableCStringStruct;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
1999-05-26 17:09:21 +00:00
|
|
|
|
static inline void
|
1999-05-28 13:07:44 +00:00
|
|
|
|
stringGrowBy(NSGMutableCStringStruct *self, unsigned want)
|
1999-05-26 17:09:21 +00:00
|
|
|
|
{
|
1999-05-28 13:07:44 +00:00
|
|
|
|
want += self->_count + 1;
|
|
|
|
|
if (want > self->_capacity)
|
|
|
|
|
self->_capacity += self->_capacity/2;
|
|
|
|
|
if (want > self->_capacity)
|
|
|
|
|
self->_capacity = want;
|
1999-05-26 17:09:21 +00:00
|
|
|
|
self->_contents_chars
|
|
|
|
|
= NSZoneRealloc(self->_zone, self->_contents_chars, self->_capacity);
|
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
static inline void
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringIncrementCountAndMakeHoleAt(NSGMutableCStringStruct *self,
|
1995-04-03 02:04:48 +00:00
|
|
|
|
int index, int size)
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
#ifndef STABLE_MEMCPY
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned i = self->_count;
|
|
|
|
|
|
|
|
|
|
while (i-- > index)
|
1995-04-03 01:38:23 +00:00
|
|
|
|
self->_contents_chars[i+size] = self->_contents_chars[i];
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
memcpy(self->_contents_chars + index,
|
|
|
|
|
self->_contents_chars + index + size,
|
|
|
|
|
self->_count - index);
|
|
|
|
|
#endif /* STABLE_MEMCPY */
|
|
|
|
|
(self->_count) += size;
|
1998-08-03 15:31:33 +00:00
|
|
|
|
(self->_hash) = 0;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringDecrementCountAndFillHoleAt(NSGMutableCStringStruct *self,
|
1995-04-03 02:04:48 +00:00
|
|
|
|
int index, int size)
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
(self->_count) -= size;
|
|
|
|
|
#ifndef STABLE_MEMCPY
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = index; i <= self->_count; i++)
|
|
|
|
|
self->_contents_chars[i] = self->_contents_chars[i+size];
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
memcpy(self->_contents_chars + index + size,
|
|
|
|
|
self->_contents_chars + index,
|
|
|
|
|
self->_count - index);
|
|
|
|
|
#endif /* STABLE_MEMCPY */
|
1998-08-03 15:31:33 +00:00
|
|
|
|
(self->_hash) = 0;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This is the designated initializer for this class */
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) initWithCapacity: (unsigned)capacity
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
_count = 0;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_capacity = capacity;
|
|
|
|
|
if (capacity)
|
|
|
|
|
{
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_zone = GSAtomicMallocZone();
|
|
|
|
|
#else
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_zone = fastZone(self);
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#endif
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_contents_chars = NSZoneMalloc(_zone, _capacity);
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
fromZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
self = (*msInitImp)(self, msInitSel, 0);
|
|
|
|
|
if (self)
|
|
|
|
|
{
|
|
|
|
|
_count = length;
|
|
|
|
|
_capacity = length;
|
1999-07-26 20:21:04 +00:00
|
|
|
|
_contents_chars = (unsigned char*)byteString;
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#if GS_WITH_GC
|
|
|
|
|
_zone = byteString ? GSAtomicMallocZone() : 0;
|
|
|
|
|
#else
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_zone = byteString ? zone : 0;
|
1999-09-29 20:15:17 +00:00
|
|
|
|
#endif
|
1998-10-26 08:15:20 +00:00
|
|
|
|
}
|
1995-04-03 01:38:23 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
fromZone: (NSZone*)zone
|
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSZone *z = zone ? zone : fastZone(self);
|
|
|
|
|
id a = [[NSGMutableString allocWithZone: z] initWithCharactersNoCopy: chars
|
|
|
|
|
length: length
|
|
|
|
|
fromZone: z];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return a;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCharactersNoCopy: (unichar*)chars
|
1998-10-26 08:15:20 +00:00
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
freeWhenDone: (BOOL)flag
|
1998-10-15 05:03:16 +00:00
|
|
|
|
{
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSZone *z = fastZone(self);
|
|
|
|
|
id a = [[NSGMutableString allocWithZone: z] initWithCharactersNoCopy: chars
|
1998-10-15 05:03:16 +00:00
|
|
|
|
length: length
|
|
|
|
|
freeWhenDone: flag];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(self);
|
1998-10-26 08:15:20 +00:00
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) copy
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *tmp;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSGCString *obj;
|
|
|
|
|
NSZone *z = NSDefaultMallocZone();
|
|
|
|
|
|
|
|
|
|
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (_count)
|
|
|
|
|
{
|
|
|
|
|
tmp = NSZoneMalloc(z, _count);
|
|
|
|
|
memcpy(tmp, _contents_chars, _count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp = 0;
|
|
|
|
|
z = 0;
|
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
|
|
|
|
|
if (_hash && obj)
|
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout
|
|
|
|
|
|
|
|
|
|
tmp->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)z
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *tmp;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
NSGCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGCString*)NSAllocateObject(_fastCls._NSGCString, 0, z);
|
1999-07-02 13:26:37 +00:00
|
|
|
|
if (_count)
|
|
|
|
|
{
|
|
|
|
|
tmp = NSZoneMalloc(z, _count);
|
|
|
|
|
memcpy(tmp, _contents_chars, _count);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp = 0;
|
|
|
|
|
z = 0;
|
|
|
|
|
}
|
1998-10-26 08:15:20 +00:00
|
|
|
|
obj = (*csInitImp)(obj, csInitSel, tmp, _count, z);
|
|
|
|
|
if (_hash && obj)
|
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *tmp = (NSGMutableCString*)obj; // Same ivar layout
|
|
|
|
|
|
|
|
|
|
tmp->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) mutableCopy
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString,
|
|
|
|
|
0, NSDefaultMallocZone());
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
memcpy(obj->_contents_chars, _contents_chars, _count);
|
|
|
|
|
obj->_count = _count;
|
|
|
|
|
obj->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)z
|
1998-10-26 08:15:20 +00:00
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString, 0, z);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
memcpy(obj->_contents_chars, _contents_chars, _count);
|
|
|
|
|
obj->_count = _count;
|
|
|
|
|
obj->_hash = _hash;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-06-24 19:30:29 +00:00
|
|
|
|
return obj;
|
1998-10-15 05:03:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-04-03 01:38:23 +00:00
|
|
|
|
- (void) deleteCharactersInRange: (NSRange)range
|
|
|
|
|
{
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringDecrementCountAndFillHoleAt((NSGMutableCStringStruct*)self,
|
1995-04-03 01:38:23 +00:00
|
|
|
|
range.location, range.length);
|
|
|
|
|
}
|
|
|
|
|
|
1997-12-08 20:04:16 +00:00
|
|
|
|
// xxx This should be primitive method
|
|
|
|
|
- (void) replaceCharactersInRange: (NSRange)range
|
1999-07-02 13:26:37 +00:00
|
|
|
|
withString: (NSString*)aString
|
1997-12-08 20:04:16 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[self deleteCharactersInRange: range];
|
|
|
|
|
[self insertString: aString atIndex: range.location];
|
1997-12-08 20:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
- (void) insertString: (NSString*)aString atIndex: (unsigned)index
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned c = [aString cStringLength];
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char save;
|
|
|
|
|
|
1998-10-15 05:03:16 +00:00
|
|
|
|
if (_count + c >= _capacity)
|
1999-05-26 17:09:21 +00:00
|
|
|
|
stringGrowBy((NSGMutableCStringStruct *)self, c);
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, c);
|
1998-10-15 05:03:16 +00:00
|
|
|
|
save = _contents_chars[index+c]; // getCString will put a nul here.
|
1998-09-30 07:42:38 +00:00
|
|
|
|
[aString getCString: _contents_chars + index];
|
1998-10-15 05:03:16 +00:00
|
|
|
|
_contents_chars[index+c] = save;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-03 17:05:57 +00:00
|
|
|
|
- (void) appendString: (NSString*)aString
|
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
|
Class c;
|
|
|
|
|
|
|
|
|
|
if (aString == nil || (c = fastClassOfInstance(aString)) == nil)
|
|
|
|
|
return;
|
|
|
|
|
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString)
|
1997-05-03 17:05:57 +00:00
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
|
NSGMutableCString *other = (NSGMutableCString*)aString;
|
|
|
|
|
unsigned l = other->_count;
|
|
|
|
|
|
|
|
|
|
if (_count + l > _capacity)
|
1999-05-26 17:09:21 +00:00
|
|
|
|
stringGrowBy((NSGMutableCStringStruct *)self, l);
|
1998-10-15 05:03:16 +00:00
|
|
|
|
memcpy(_contents_chars + _count, other->_contents_chars, l);
|
|
|
|
|
_count += l;
|
|
|
|
|
_hash = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unsigned l = [aString cStringLength];
|
|
|
|
|
if (_count + l >= _capacity)
|
1999-05-26 17:09:21 +00:00
|
|
|
|
stringGrowBy((NSGMutableCStringStruct *)self, l);
|
1998-10-15 05:03:16 +00:00
|
|
|
|
[aString getCString: _contents_chars + _count];
|
|
|
|
|
_count += l;
|
|
|
|
|
_hash = 0;
|
1997-05-03 17:05:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) setString: (NSString*)aString
|
|
|
|
|
{
|
1998-09-30 07:42:38 +00:00
|
|
|
|
unsigned length = [aString cStringLength];
|
1998-10-15 05:03:16 +00:00
|
|
|
|
if (_capacity <= length)
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
|
_capacity = length+1;
|
|
|
|
|
_contents_chars =
|
1999-05-28 13:07:44 +00:00
|
|
|
|
NSZoneRealloc(_zone, _contents_chars, _capacity);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1998-09-30 07:42:38 +00:00
|
|
|
|
[aString getCString: _contents_chars];
|
1995-04-03 01:38:23 +00:00
|
|
|
|
_count = length;
|
1998-08-03 15:31:33 +00:00
|
|
|
|
_hash = 0;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-12-08 20:04:16 +00:00
|
|
|
|
- (id) init
|
|
|
|
|
{
|
1998-10-15 05:03:16 +00:00
|
|
|
|
return [self initWithCStringNoCopy: 0 length: 0 fromZone: 0];
|
1998-10-26 08:15:20 +00:00
|
|
|
|
}
|
1995-04-03 01:38:23 +00:00
|
|
|
|
|
|
|
|
|
/* For IndexedCollecting Protocol and other GNU libobjects conformity. */
|
|
|
|
|
|
|
|
|
|
/* xxx This should be made to return void, but we need to change
|
|
|
|
|
IndexedCollecting and its conformers */
|
1996-02-22 16:05:47 +00:00
|
|
|
|
- (void) removeRange: (IndexRange)range
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringDecrementCountAndFillHoleAt((NSGMutableCStringStruct*)self,
|
1995-04-03 01:38:23 +00:00
|
|
|
|
range.location, range.length);
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-02 13:26:37 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned cap;
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &cap];
|
|
|
|
|
[self initWithCapacity: cap];
|
1998-10-15 05:03:16 +00:00
|
|
|
|
_count = cap;
|
1998-10-26 18:06:51 +00:00
|
|
|
|
if (_count > 0)
|
|
|
|
|
{
|
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
|
|
|
|
|
count: _count
|
|
|
|
|
at: _contents_chars];
|
|
|
|
|
}
|
1995-04-09 01:53:53 +00:00
|
|
|
|
return self;
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For IndexedCollecting protocol */
|
|
|
|
|
|
|
|
|
|
- (char) charAtIndex: (unsigned)index
|
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
|
|
|
|
return _contents_chars[index];
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 16:05:47 +00:00
|
|
|
|
|
|
|
|
|
// FOR IndexedCollection and OrderedCollection SUPPORT;
|
|
|
|
|
|
|
|
|
|
- (void) insertObject: newObject atIndex: (unsigned)index
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count+1);
|
|
|
|
|
// one for the next char, one for the '\0';
|
1998-02-03 14:20:00 +00:00
|
|
|
|
if (_count >= _capacity)
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
_capacity *= 2;
|
1998-10-26 08:15:20 +00:00
|
|
|
|
_contents_chars =
|
1999-05-28 13:07:44 +00:00
|
|
|
|
NSZoneRealloc(_zone, _contents_chars, _capacity);
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringIncrementCountAndMakeHoleAt((NSGMutableCStringStruct*)self, index, 1);
|
1996-02-22 16:05:47 +00:00
|
|
|
|
_contents_chars[index] = [newObject charValue];
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-22 16:05:47 +00:00
|
|
|
|
- (void) removeObjectAtIndex: (unsigned)index
|
1995-04-03 01:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
1995-08-09 15:46:35 +00:00
|
|
|
|
stringDecrementCountAndFillHoleAt((NSGMutableCStringStruct*)self, index, 1);
|
1995-04-03 01:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
- (unsigned char*) _extendBy: (unsigned)len
|
1999-05-26 17:09:21 +00:00
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
unsigned char *ptr;
|
1999-05-26 17:09:21 +00:00
|
|
|
|
|
1999-05-28 13:07:44 +00:00
|
|
|
|
if (len > 0)
|
|
|
|
|
stringGrowBy((NSGMutableCStringStruct *)self, len);
|
|
|
|
|
ptr = &_contents_chars[_count];
|
1999-05-26 17:09:21 +00:00
|
|
|
|
_count += len;
|
|
|
|
|
_hash = 0;
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
1995-04-03 01:38:23 +00:00
|
|
|
|
@end
|
1998-10-03 21:23:04 +00:00
|
|
|
|
|
|
|
|
|
@implementation NXConstantString
|
|
|
|
|
|
1999-08-25 14:47:19 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to allocate an NXConstantString"];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCStringNoCopy: (char*)byteString
|
|
|
|
|
length: (unsigned int)length
|
|
|
|
|
fromZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"Attempt to init an NXConstantString"];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-03 21:23:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* NXConstantString overrides [-dealloc] so that it is never deallocated.
|
1998-10-20 08:50:52 +00:00
|
|
|
|
* If we pass an NXConstantString to another process or record it in an
|
|
|
|
|
* archive and readi it back, the new copy will never be deallocated -
|
|
|
|
|
* causing a memory leak. So we tell the system to use the super class.
|
1998-10-03 21:23:04 +00:00
|
|
|
|
*/
|
1999-06-21 19:54:43 +00:00
|
|
|
|
- (Class) classForArchiver
|
1998-10-23 15:47:07 +00:00
|
|
|
|
{
|
|
|
|
|
return [self superclass];
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-21 19:54:43 +00:00
|
|
|
|
- (Class) classForCoder
|
1998-10-03 21:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
return [self superclass];
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-21 19:54:43 +00:00
|
|
|
|
- (Class) classForPortCoder
|
1998-10-23 15:47:07 +00:00
|
|
|
|
{
|
|
|
|
|
return [self superclass];
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-21 19:54:43 +00:00
|
|
|
|
- (void) dealloc
|
1998-10-03 21:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const char*) cString
|
|
|
|
|
{
|
1999-07-26 20:21:04 +00:00
|
|
|
|
return (const char*) _contents_chars;
|
1998-10-03 21:23:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-03 19:59:44 +00:00
|
|
|
|
- (id) retain
|
1998-10-03 21:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (oneway void) release
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-03 19:59:44 +00:00
|
|
|
|
- (id) autorelease
|
1998-10-03 21:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
- (id) copy
|
1999-06-21 19:54:43 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-26 20:21:04 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)z
|
1998-10-03 21:23:04 +00:00
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSZone*) zone
|
|
|
|
|
{
|
|
|
|
|
return NSDefaultMallocZone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSStringEncoding) fastestEncoding
|
|
|
|
|
{
|
|
|
|
|
return NSASCIIStringEncoding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSStringEncoding) smallestEncoding
|
|
|
|
|
{
|
|
|
|
|
return NSASCIIStringEncoding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unichar) characterAtIndex: (unsigned int)index
|
|
|
|
|
{
|
|
|
|
|
CHECK_INDEX_RANGE_ERROR(index, _count);
|
|
|
|
|
return (unichar)_contents_chars[index];
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-25 14:47:19 +00:00
|
|
|
|
- (unsigned) hash
|
|
|
|
|
{
|
|
|
|
|
return _fastImp._NSString_hash(self, @selector(hash));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEqual: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
Class c;
|
|
|
|
|
if (anObject == self)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
c = fastClassOfInstance(anObject);
|
|
|
|
|
|
|
|
|
|
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
|
|
|
|
|| c == _fastCls._NXConstantString)
|
|
|
|
|
{
|
|
|
|
|
NXConstantString *other = (NXConstantString*)anObject;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
{
|
|
|
|
|
if (strCompCsUs(self, anObject, 0, (NSRange){0,_count}) == NSOrderedSame)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
else if (c == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
|
|
|
|
{
|
|
|
|
|
return _fastImp._NSString_isEqualToString_(self,
|
|
|
|
|
@selector(isEqualToString:), anObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEqualToString: (NSString*)aString
|
|
|
|
|
{
|
|
|
|
|
Class c;
|
|
|
|
|
|
|
|
|
|
if (aString == self)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
if (aString == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
c = fastClassOfInstance(aString);
|
|
|
|
|
if (c == _fastCls._NSGCString || c == _fastCls._NSGMutableCString
|
|
|
|
|
|| c == _fastCls._NXConstantString)
|
|
|
|
|
{
|
|
|
|
|
NXConstantString *other = (NXConstantString*)aString;
|
|
|
|
|
|
|
|
|
|
if (_count != other->_count)
|
|
|
|
|
return NO;
|
|
|
|
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else if (c == _fastCls._NSGString || c == _fastCls._NSGMutableString)
|
|
|
|
|
{
|
|
|
|
|
if (strCompCsUs(self, aString, 0, (NSRange){0,_count}) == NSOrderedSame)
|
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
else if (c == nil)
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
else if (fastClassIsKindOfClass(c, _fastCls._NSString))
|
|
|
|
|
{
|
|
|
|
|
return _fastImp._NSString_isEqualToString_(self,
|
|
|
|
|
@selector(isEqualToString:), aString);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) mutableCopy
|
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString,
|
|
|
|
|
0, NSDefaultMallocZone());
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
NXConstantString *tmp = (NXConstantString*)obj;
|
|
|
|
|
|
|
|
|
|
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
|
|
|
|
tmp->_count = _count;
|
|
|
|
|
tmp->_hash = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)z
|
|
|
|
|
{
|
|
|
|
|
NSGMutableCString *obj;
|
|
|
|
|
|
|
|
|
|
obj = (NSGMutableCString*)NSAllocateObject(_fastCls._NSGMutableCString, 0, z);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
obj = (*msInitImp)(obj, msInitSel, _count);
|
|
|
|
|
if (obj)
|
|
|
|
|
{
|
|
|
|
|
NXConstantString *tmp = (NXConstantString*)obj;
|
|
|
|
|
|
|
|
|
|
memcpy(tmp->_contents_chars, _contents_chars, _count);
|
|
|
|
|
tmp->_count = _count;
|
|
|
|
|
tmp->_hash = 0; // No hash available yet.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
1998-10-03 21:23:04 +00:00
|
|
|
|
@end
|