XML property list support completed.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10501 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-07-16 19:43:51 +00:00
parent 06ee1f7be5
commit d96a040986
10 changed files with 489 additions and 116 deletions

View file

@ -73,7 +73,22 @@ static BOOL MacOSXCompatiblePropertyLists = NO;
}
else
{
MacOSXCompatiblePropertyLists = MacOSXCompatible;
def = [defaults objectForKey: @"NSWriteOldStylePropertyLists"];
if (def != nil && [def isKindOfClass: sClass] == YES)
{
if ([def boolBalue] == YES)
{
MacOSXCompatiblePropertyLists = NO;
}
else
{
MacOSXCompatiblePropertyLists = YES;
}
}
else
{
MacOSXCompatiblePropertyLists = MacOSXCompatible;
}
}
}
@end
@ -109,8 +124,6 @@ BOOL GSMacOSXCompatibleGeometry()
BOOL GSMacOSXCompatiblePropertyLists()
{
/* HACK until xml propertylists fully working */
return NO;
if (setupDone == NO)
compatibilitySetup();
return MacOSXCompatiblePropertyLists;
@ -170,11 +183,30 @@ encodeBase64(NSData *source)
initWithCStringNoCopy: dBuf length: destlen-1 freeWhenDone: YES];
}
static NSCharacterSet *quotables = nil;
static void setupQuotables()
{
if (quotables == nil)
{
NSMutableCharacterSet *s;
s = [[NSCharacterSet characterSetWithCharactersInString:
@"&<>'\\\""] mutableCopy];
[s addCharactersInRange: NSMakeRange(0x0001, 0x001f)];
[s removeCharactersInRange: NSMakeRange(0x0009, 0x0002)];
[s removeCharactersInRange: NSMakeRange(0x000D, 0x0001)];
[s addCharactersInRange: NSMakeRange(0xD800, 0x07FF)];
[s addCharactersInRange: NSMakeRange(0xFFFE, 0x0002)];
quotables = [s copy];
RELEASE(s);
}
}
static NSString*
XMLString(NSString* obj)
{
static NSCharacterSet *quotables = nil;
static char *hexdigits = "0123456789ABCDEF";
static char *hexdigits = "0123456789ABCDEF";
unsigned end;
end = [obj length];
@ -185,7 +217,7 @@ XMLString(NSString* obj)
if (quotables == nil)
{
// setupQuotables();
setupQuotables();
}
if ([obj rangeOfCharacterFromSet: quotables].length > 0)
@ -213,7 +245,7 @@ XMLString(NSString* obj)
break;
case '\'':
case '"':
len += 5;
len += 6;
break;
case '\\':
len += 1;
@ -302,27 +334,27 @@ XMLString(NSString* obj)
else
{
map[wpos++] = '\\';
map[wpos++] = hexdigits[(c>>4) & 0xff];
map[wpos++] = hexdigits[c & 0xff];
map[wpos++] = '\\';
map[wpos++] = '0' + ((c / 64) & 7);
map[wpos++] = '0' + ((c / 8) & 7);
map[wpos++] = '0' + (c & 7);
}
}
else if (c > 0xD7FF && c < 0xE000)
{
map[wpos++] = '\\';
map[wpos++] = hexdigits[(c>>12) & 0xff];
map[wpos++] = hexdigits[(c>>8) & 0xff];
map[wpos++] = hexdigits[(c>>4) & 0xff];
map[wpos++] = hexdigits[c & 0xff];
map[wpos++] = '\\';
map[wpos++] = 'U';
map[wpos++] = hexdigits[(c>>12) & 0xf];
map[wpos++] = hexdigits[(c>>8) & 0xf];
map[wpos++] = hexdigits[(c>>4) & 0xf];
map[wpos++] = hexdigits[c & 0xf];
}
else if (c > 0xFFFD)
{
map[wpos++] = '\\';
map[wpos++] = hexdigits[(c>>12) & 0xff];
map[wpos++] = hexdigits[(c>>8) & 0xff];
map[wpos++] = hexdigits[(c>>4) & 0xff];
map[wpos++] = hexdigits[c & 0xff];
map[wpos++] = hexdigits[(c>>12) & 0xf];
map[wpos++] = hexdigits[(c>>8) & 0xf];
map[wpos++] = hexdigits[(c>>4) & 0xf];
map[wpos++] = hexdigits[c & 0xf];
map[wpos++] = '\\';
}
else

View file

@ -563,12 +563,24 @@ failure:
- (NSString*) description
{
NSString *str;
const char *src = [self bytes];
const char *src;
char *dest;
int length = [self length];
int i,j;
NSZone *z = [self zone];
int length;
int i;
int j;
NSZone *z;
extern BOOL GSMacOSXCompatiblePropertyLists();
if (GSMacOSXCompatiblePropertyLists() == YES)
{
extern NSString *GSXMLPlMake(id obj, NSDictionary *loc, unsigned lev);
return GSXMLPlMake(self, nil, 0);
}
src = [self bytes];
length = [self length];
z = [self zone];
#define num2char(num) ((num) < 0xa ? ((num)+'0') : ((num)+0x57))
/* we can just build a cString and convert it to an NSString */
@ -578,16 +590,20 @@ failure:
dest = (char*) NSZoneMalloc(z, 2*length+length/4+3);
#endif
if (dest == 0)
[NSException raise: NSMallocException
format: @"No memory for description of NSData object"];
{
[NSException raise: NSMallocException
format: @"No memory for description of NSData object"];
}
dest[0] = '<';
for (i=0,j=1; i<length; i++,j++)
for (i = 0, j = 1; i < length; i++, j++)
{
dest[j++] = num2char((src[i]>>4) & 0x0f);
dest[j] = num2char(src[i] & 0x0f);
if ((i&0x3) == 3 && i != length-1)
/* if we've just finished a 32-bit int, print a space */
dest[++j] = ' ';
{
/* if we've just finished a 32-bit int, print a space */
dest[++j] = ' ';
}
}
dest[j++] = '>';
dest[j] = '\0';

View file

@ -3154,8 +3154,17 @@ handle_printf_atsign (FILE *stream,
indent: (unsigned)level
to: (id<GNUDescriptionDestination>)output
{
extern BOOL GSMacOSXCompatiblePropertyLists();
unsigned length;
if (GSMacOSXCompatiblePropertyLists() == YES)
{
extern NSString *GSXMLPlMake(id obj, NSDictionary *loc, unsigned lev);
[output appendString: GSXMLPlMake(self, aLocale, level)];
return;
}
if ((length = [self length]) == 0)
{
[output appendString: @"\"\""];
@ -3790,9 +3799,7 @@ handle_printf_atsign (FILE *stream,
#if HAVE_LIBXML
#include <Foundation/GSXML.h>
#ifndef __XML_TREE_H__
static int XML_ELEMENT_NODE;
#endif
static void
decodeBase64Unit(const char* ptr, unsigned char *out)
@ -4332,12 +4339,115 @@ nodeToObject(GSXMLNode* node)
content = [children content];
children = elementNode(children);
if ([name isEqualToString: @"string"])
{
return content;
}
else if ([name isEqualToString: @"key"])
if ([name isEqualToString: @"string"]
|| [name isEqualToString: @"key"])
{
NSRange r;
r = [content rangeOfString: @"\\"];
if (r.length == 1)
{
unsigned len = [content length];
unichar buf[len];
unsigned pos = r.location;
[content getCharacters: buf];
while (pos < len)
{
if (++pos < len)
{
if (buf[pos] == '/')
{
len--;
memcpy(&buf[pos], &buf[pos+1],
(len - pos) * sizeof(unichar));
}
else if (buf[pos] == 'U')
{
unichar val = 0;
unsigned i;
if (len < pos + 4)
{
[NSException raise: NSInternalInconsistencyException
format: @"Short escape sequence"];
}
for (i = 1; i < 5; i++)
{
unichar c = buf[pos + i];
if (c >= '0' && c <= '9')
{
val = (val << 4) + c - '0';
}
else if (c >= 'A' && c <= 'F')
{
val = (val << 4) + c - 'A' + 10;
}
else if (c >= 'a' && c <= 'f')
{
val = (val << 4) + c - 'a' + 10;
}
else
{
[NSException raise:
NSInternalInconsistencyException
format: @"bad hex escape sequence"];
}
}
len -= 5;
memcpy(&buf[pos], &buf[pos+5],
(len - pos) * sizeof(unichar));
buf[pos - 1] = val;
}
else if (buf[pos] >= '0' && buf[pos] <= '7')
{
unichar val = 0;
unsigned i;
if (len < pos + 2)
{
[NSException raise: NSInternalInconsistencyException
format: @"Short escape sequence"];
}
for (i = 0; i < 3; i++)
{
unichar c = buf[pos + i];
if (c >= '0' && c <= '7')
{
val = (val << 3) + c - '0';
}
else
{
[NSException raise:
NSInternalInconsistencyException
format: @"bad octal escape sequence"];
}
}
len -= 3;
memcpy(&buf[pos], &buf[pos+3],
(len - pos) * sizeof(unichar));
buf[pos - 1] = val;
}
else
{
[NSException raise: NSInternalInconsistencyException
format: @"Short escape sequence"];
}
while (pos < len && buf[pos] != '\\')
{
pos++;
}
}
else
{
[NSException raise: NSInternalInconsistencyException
format: @"Short escape sequence"];
}
}
content = [NSString stringWithCharacters: buf length: len];
}
return content;
}
else if ([name isEqualToString: @"true"])
@ -4408,12 +4518,10 @@ static void
setupPl()
{
#if HAVE_LIBXML
#ifndef __XML_TREE_H__
/*
* Cache XML node information.
*/
XML_ELEMENT_NODE = [GSXMLNode typeFromDescription: @"XML_ELEMENT_NODE"];
#endif
#endif
plAlloc = (id (*)(id, SEL, NSZone*))
[NSStringClass methodForSelector: @selector(allocWithZone:)];
@ -4453,6 +4561,11 @@ GSPropertyList(NSString *string)
return nil;
}
if (plAlloc == 0)
{
setupPl();
}
#if HAVE_LIBXML
if (whitespaceBitmapRep == NULL)
{
@ -4502,10 +4615,6 @@ GSPropertyList(NSString *string)
_pld.end = length + 1;
_pld.err = nil;
_pld.lin = 1;
if (plAlloc == 0)
{
setupPl();
}
pl = AUTORELEASE(parsePlItem(pld));
if (pl == nil && _pld.err != nil)
{