git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7564 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-09-20 14:02:03 +00:00
parent a32e0002d9
commit f63a37bc73
4 changed files with 3336 additions and 2983 deletions

View file

@ -11,6 +11,8 @@
NSString class +initialize method may not have completed when this
is done - so NSString won't have cached its cocrete and abstract
classes.
* Source/GSCompatibility.m: Partial write of code to generate MacOS-X
compatible (XML) property-list text.
2000-09-19 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -2,7 +2,7 @@
Copyright (C) 2000 Free Software Foundation, Inc.
Written by: Richard frith-Macdonald <rfm@gnu.org>
Date: August 1994
Date: August 2000
This file is part of the GNUstep Base Library.
@ -106,3 +106,154 @@ BOOL GSMacOSXCompatiblePropertyLists()
return MacOSXCompatiblePropertyLists;
}
#include <math.h>
#include <Foundation/NSValue.h>
#include <Foundation/NSString.h>
#include <Foundation/NSGCString.h>
static char base64[]
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static NSString*
encodeBase64(NSData *source)
{
int length = [source length];
int enclen = length / 3;
int remlen = length - 3 * enclen;
int destlen = 4 * ((length - 1) / 3) + 5;
unsigned char *sBuf = (unsigned char*)[source bytes];
unsigned char *dBuf = NSZoneMalloc(NSDefaultMallocZone(), destlen);
int sIndex = 0;
int dIndex = 0;
dBuf[destlen - 1] = '\0';
for (sIndex = 0; sIndex < length - 2; sIndex += 3, dIndex += 4)
{
dBuf[dIndex] = base64[sBuf[sIndex] >> 2];
dBuf[dIndex + 1]
= base64[((sBuf[sIndex] << 4) | (sBuf[sIndex + 1] >> 4)) & 0x3f];
dBuf[dIndex + 2]
= base64[((sBuf[sIndex + 1] << 2) | (sBuf[sIndex + 2] >> 6)) & 0x3f];
dBuf[dIndex + 3] = base64[sBuf[sIndex + 2] & 0x3f];
}
if (remlen == 1)
{
dBuf[dIndex] = base64[sBuf[sIndex] >> 2];
dBuf[dIndex + 1] = (sBuf[sIndex] << 4) & 0x30;
dBuf[dIndex + 1] = base64[dBuf[dIndex + 1]];
dBuf[dIndex + 2] = '=';
dBuf[dIndex + 3] = '=';
}
else if (remlen == 2)
{
dBuf[dIndex] = base64[sBuf[sIndex] >> 2];
dBuf[dIndex + 1] = (sBuf[sIndex] << 4) & 0x30;
dBuf[dIndex + 1] |= sBuf[sIndex + 1] >> 4;
dBuf[dIndex + 1] = base64[dBuf[dIndex + 1]];
dBuf[dIndex + 2] = (sBuf[sIndex + 1] << 2) & 0x3c;
dBuf[dIndex + 2] = base64[dBuf[dIndex + 2]];
dBuf[dIndex + 3] = '=';
}
return [[NSGCString allocWithZone: NSDefaultMallocZone()]
initWithCStringNoCopy: dBuf
length: destlen-1
fromZone: NSDefaultMallocZone()];
}
static NSString*
XMLString(NSString* obj)
{
/* Should substitute in entities */
return obj;
}
static void
XMLPlObject(NSMutableString *dest, id obj)
{
if ([obj isKindOfClass: [NSString class]])
{
[dest appendString: @"<string>"];
[dest appendString: XMLString(obj)];
[dest appendString: @"</string>\n"];
}
else if ([obj isKindOfClass: [NSNumber class]])
{
double val = [obj doubleValue];
if (val == 1.0)
{
[dest appendString: @"<true/>\n"];
}
else if (val == 0.0)
{
[dest appendString: @"<false/>\n"];
}
else if (rint(val) == val)
{
[dest appendString: @"<integer>"];
[dest appendString: [obj stringValue]];
[dest appendString: @"</integer>\n"];
}
else
{
[dest appendString: @"<real>"];
[dest appendString: [obj stringValue]];
[dest appendString: @"</real>\n"];
}
}
else if ([obj isKindOfClass: [NSData class]])
{
[dest appendString: @"<data>"];
[dest appendString: encodeBase64(obj)];
[dest appendString: @"</data>\n"];
}
else if ([obj isKindOfClass: [NSDate class]])
{
[dest appendString: @"<date>"];
[dest appendString:
[obj descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S %z"]];
[dest appendString: @"</date>\n"];
}
else if ([obj isKindOfClass: [NSArray class]])
{
NSEnumerator *e;
[dest appendString: @"<array>\n"];
e = [obj objectEnumerator];
while ((obj = [e nextObject]))
{
XMLPlObject(dest, obj);
}
[dest appendString: @"</array>\n"];
}
else if ([obj isKindOfClass: [NSDictionary class]])
{
NSEnumerator *e;
id key;
[dest appendString: @"<dict>\n"];
e = [obj keyEnumerator];
while ((key = [e nextObject]))
{
id val;
val = [obj objectForKey: key];
[dest appendString: @"<key>"];
[dest appendString: XMLString(key)];
[dest appendString: @"</key>\n"];
XMLPlObject(dest, val);
}
[dest appendString: @"</dict>\n"];
}
else
{
NSLog(@"Non-property-list class encoded as string");
[dest appendString: @"<string>"];
[dest appendString: [obj description]];
[dest appendString: @"</string>\n"];
}
}

View file

@ -24,10 +24,6 @@
#if HAVE_LIBXML
#include <Foundation/GSXML.h>
static char base64[]
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void
decodeBase64Unit(const char* ptr, unsigned char *out)
{
@ -74,52 +70,6 @@ decodeBase64(const char *source)
return data;
}
static char*
encodeBase64(NSData *source)
{
int length = [source length];
int enclen = length / 3;
int remlen = length - 3 * enclen;
int destlen = 4 * ((length - 1) / 3) + 5;
unsigned char *sourceBuffer = malloc(length);
unsigned char *destBuffer = malloc(destlen);
int sourceIndex = 0, destIndex = 0;
[source getBytes:sourceBuffer];
destBuffer[destlen - 1] = '\0';
for (sourceIndex = 0; sourceIndex < length - 2; sourceIndex += 3, destIndex += 4)
{
destBuffer[destIndex] = base64[sourceBuffer[sourceIndex] >> 2];
destBuffer[destIndex + 1] = base64[((sourceBuffer[sourceIndex] << 4) | (sourceBuffer[sourceIndex + 1] >> 4)) & 0x3f];
destBuffer[destIndex + 2] = base64[((sourceBuffer[sourceIndex + 1] << 2) | (sourceBuffer[sourceIndex + 2] >> 6)) & 0x3f];
destBuffer[destIndex + 3] = base64[sourceBuffer[sourceIndex + 2] & 0x3f];
}
if (remlen == 1)
{
destBuffer[destIndex] = base64[sourceBuffer[sourceIndex] >> 2];
destBuffer[destIndex + 1] = (sourceBuffer[sourceIndex] << 4) & 0x30;
destBuffer[destIndex + 1] = base64[destBuffer[destIndex + 1]];
destBuffer[destIndex + 2] = '=';
destBuffer[destIndex + 3] = '=';
}
else if (remlen == 2)
{
destBuffer[destIndex] = base64[sourceBuffer[sourceIndex] >> 2];
destBuffer[destIndex + 1] = (sourceBuffer[sourceIndex] << 4) & 0x30;
destBuffer[destIndex + 1] |= sourceBuffer[sourceIndex + 1] >> 4;
destBuffer[destIndex + 1] = base64[destBuffer[destIndex + 1]];
destBuffer[destIndex + 2] = (sourceBuffer[sourceIndex + 1] << 2) & 0x3c;
destBuffer[destIndex + 2] = base64[destBuffer[destIndex + 2]];
destBuffer[destIndex + 3] = '=';
}
free(sourceBuffer);
return destBuffer;
}
#endif
/*
@ -715,7 +665,7 @@ nodeToObject(GSXMLNode* node)
else if ([name isEqualToString: @"date"])
{
return [NSCalendarDate dateWithString: content
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
calendarFormat: @"%Y-%m-%d %H:%M:%S %z"];
}
else if ([name isEqualToString: @"data"])
{

File diff suppressed because it is too large Load diff