Restore (fixed) previous reverted code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22953 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-05-20 14:52:38 +00:00
parent 21a64f7f01
commit 390661c762
3 changed files with 182 additions and 488 deletions

View file

@ -18,7 +18,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02111 USA.
<title>NSSerializer class reference</title>
$Date$ $Revision$
@ -52,17 +53,6 @@
@class GSMutableArray;
@interface GSMutableArray : NSObject // Help the compiler
@end
@class GSCString;
@interface GSCString : NSObject // Help the compiler
@end
@class GSCBufferString;
@interface GSCBufferString : NSObject // Help the compiler
@end
@class GSUnicodeString;
@class GSUnicodeBufferString;
@interface GSUnicodeBufferString : NSObject // Help the compiler
@end
@class GSMutableString;
/*
* Setup for inline operation of string map tables.
@ -123,8 +113,6 @@ static Class DataClass = 0;
static Class DateClass = 0;
static Class DictionaryClass = 0;
static Class MutableDictionaryClass = 0;
static Class CStringClass = 0;
static Class MStringClass = 0;
static Class StringClass = 0;
static Class NumberClass = 0;
@ -196,8 +184,7 @@ serializeToInfo(id object, _NSSerializerInfo* info)
}
c = GSObjCClass(object);
if ((GSObjCIsKindOf(c, CStringClass)
|| (c == MStringClass && ((ivars)object)->_flags.wide == 0))
if (GSObjCIsKindOf(c, StringClass)
/*
We can only save it as a c-string if it only contains ASCII characters.
Other characters might be decoded incorrectly when deserialized since
@ -381,8 +368,6 @@ static BOOL shouldBeCompact = NO;
DictionaryClass = [NSDictionary class];
MutableDictionaryClass = [NSMutableDictionary class];
StringClass = [NSString class];
CStringClass = [GSCString class];
MStringClass = [GSMutableString class];
}
}
@ -452,8 +437,6 @@ static BOOL uniquing = NO; /* Make incoming strings unique */
static Class MACls = 0; /* Mutable Array */
static Class DCls = 0; /* Data */
static Class MDCls = 0; /* Mutable Dictionary */
static Class USCls = 0; /* Unicode String */
static Class CSCls = 0; /* C String */
typedef struct {
NSData *data;
@ -467,15 +450,11 @@ typedef struct {
static SEL debSel;
static SEL deiSel;
static SEL csInitSel;
static SEL usInitSel;
static SEL dInitSel;
static SEL maInitSel;
static SEL mdInitSel;
static SEL maAddSel;
static SEL mdSetSel;
static IMP csInitImp;
static IMP usInitImp;
static IMP dInitImp;
static IMP maInitImp;
static IMP mdInitImp;
@ -564,15 +543,16 @@ deserializeFromInfo(_NSDeserializerInfo* info)
case ST_CSTRING:
{
GSCString *s;
NSString *s;
char *b;
size = (*info->deiImp)(info->data, deiSel, info->cursor);
b = NSZoneMalloc(NSDefaultMallocZone(), size);
(*info->debImp)(info->data, debSel, b, size, info->cursor);
s = (GSCString*)NSAllocateObject(CSCls, 0, NSDefaultMallocZone());
s = (*csInitImp)(s, csInitSel, b, size-1, YES);
s = [[StringClass alloc] initWithBytesNoCopy: b
length: size - 1
encoding: NSASCIIStringEncoding
freeWhenDone: YES];
/*
* If we are supposed to be doing uniquing of strings, handle it.
*/
@ -596,41 +576,15 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{
NSString *s;
unichar *b;
unsigned i;
size = (*info->deiImp)(info->data, deiSel, info->cursor);
b = NSZoneMalloc(NSDefaultMallocZone(), size*sizeof(unichar));
(*info->debImp)(info->data, debSel, b, size*sizeof(unichar),
info->cursor);
/*
* Check to see if this really IS unicode ... if not, use a cString
*/
for (i = 0; i < size; i++)
{
if (b[i] > 127)
{
break;
}
}
if (i == size)
{
char *p = (char*)b;
for (i = 0; i < size; i++)
{
p[i] = (char)b[i];
}
p = NSZoneRealloc(NSDefaultMallocZone(), b, size);
s = (NSString*)NSAllocateObject(CSCls, 0, NSDefaultMallocZone());
s = (*csInitImp)(s, csInitSel, p, size, YES);
}
else
{
s = (NSString*)NSAllocateObject(USCls, 0, NSDefaultMallocZone());
s = (*usInitImp)(s, usInitSel, b, size, YES);
}
s = [[StringClass alloc] initWithBytesNoCopy: b
length: size*sizeof(unichar)
encoding: NSUnicodeStringEncoding
freeWhenDone: YES];
/*
* If we are supposed to be doing uniquing of strings, handle it.
*/
@ -857,8 +811,6 @@ deserializeFromInfo(_NSDeserializerInfo* info)
{
debSel = @selector(deserializeBytes:length:atCursor:);
deiSel = @selector(deserializeIntAtCursor:);
csInitSel = @selector(initWithCStringNoCopy:length:freeWhenDone:);
usInitSel = @selector(initWithCharactersNoCopy:length:freeWhenDone:);
dInitSel = @selector(initWithBytesNoCopy:length:);
maInitSel = @selector(initWithCapacity:);
mdInitSel = @selector(initWithCapacity:);
@ -867,15 +819,12 @@ deserializeFromInfo(_NSDeserializerInfo* info)
MACls = [GSMutableArray class];
DCls = [NSDataMalloc class];
MDCls = [GSMutableDictionary class];
USCls = [GSUnicodeBufferString class];
CSCls = [GSCBufferString class];
csInitImp = [CSCls instanceMethodForSelector: csInitSel];
usInitImp = [USCls instanceMethodForSelector: usInitSel];
dInitImp = [DCls instanceMethodForSelector: dInitSel];
maInitImp = [MACls instanceMethodForSelector: maInitSel];
mdInitImp = [MDCls instanceMethodForSelector: mdInitSel];
maAddImp = [MACls instanceMethodForSelector: maAddSel];
mdSetImp = [MDCls instanceMethodForSelector: mdSetSel];
StringClass = [NSString class];
}
}