mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
reduce dependecy on libxml2
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28263 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d9e6e84591
commit
e5394a531c
5 changed files with 25 additions and 267 deletions
|
@ -2901,6 +2901,7 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
|
||||||
{
|
{
|
||||||
unsigned diff = input - lineEnd;
|
unsigned diff = input - lineEnd;
|
||||||
|
|
||||||
|
bytes[input] = ' ';
|
||||||
memmove(&bytes[lineStart + diff], &bytes[lineStart], length);
|
memmove(&bytes[lineStart + diff], &bytes[lineStart], length);
|
||||||
lineStart += diff;
|
lineStart += diff;
|
||||||
lineEnd += diff;
|
lineEnd += diff;
|
||||||
|
@ -3347,7 +3348,7 @@ appendBytes(NSMutableData *m, unsigned offset, unsigned fold,
|
||||||
* If we already have space at the end of the line,
|
* If we already have space at the end of the line,
|
||||||
* we remove it because the wrapping counts as a space.
|
* we remove it because the wrapping counts as a space.
|
||||||
*/
|
*/
|
||||||
if (len > 0 && ((unsigned char*)[m bytes])[len - 1] == ' ')
|
if (len > 0 && isspace(((unsigned char*)[m bytes])[len - 1]))
|
||||||
{
|
{
|
||||||
[m setLength: --len];
|
[m setLength: --len];
|
||||||
}
|
}
|
||||||
|
|
|
@ -867,6 +867,20 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks =
|
||||||
return node->key.obj;
|
return node->key.obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) containsObject: (id)anObject
|
||||||
|
{
|
||||||
|
if (anObject != nil)
|
||||||
|
{
|
||||||
|
GSIMapNode node = GSIMapNodeForKey(self, (GSIMapKey)anObject);
|
||||||
|
|
||||||
|
if (node)
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)aZone
|
- (id) copyWithZone: (NSZone*)aZone
|
||||||
{
|
{
|
||||||
return NSCopyHashTableWithZone(self, aZone);
|
return NSCopyHashTableWithZone(self, aZone);
|
||||||
|
|
|
@ -129,7 +129,7 @@ static Class concreteClass = 0;
|
||||||
|
|
||||||
- (BOOL) containsObject: (id)anObject
|
- (BOOL) containsObject: (id)anObject
|
||||||
{
|
{
|
||||||
return (BOOL)(uintptr_t)[self subclassResponsibility: _cmd];
|
return [self member: anObject] ? YES : NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)aZone
|
- (id) copyWithZone: (NSZone*)aZone
|
||||||
|
@ -178,7 +178,7 @@ static Class concreteClass = 0;
|
||||||
enumerator = [self objectEnumerator];
|
enumerator = [self objectEnumerator];
|
||||||
while ((object = [enumerator nextObject]) != nil)
|
while ((object = [enumerator nextObject]) != nil)
|
||||||
{
|
{
|
||||||
if ([other member: object] != nil)
|
if ([other member: object] == nil)
|
||||||
{
|
{
|
||||||
[array addObject: object];
|
[array addObject: object];
|
||||||
}
|
}
|
||||||
|
|
|
@ -780,13 +780,6 @@ static NSMapTable *globalClassMap = 0;
|
||||||
errorDescription: &error];
|
errorDescription: &error];
|
||||||
if (_archive == nil)
|
if (_archive == nil)
|
||||||
{
|
{
|
||||||
#ifndef HAVE_LIBXML
|
|
||||||
if (format == NSPropertyListXMLFormat_v1_0)
|
|
||||||
{
|
|
||||||
NSLog(@"Unable to parse XML archive as the base "
|
|
||||||
@"library was not configured with libxml2 support.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
DESTROY(self);
|
DESTROY(self);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -521,11 +521,6 @@ static void setupQuotables(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBXML
|
|
||||||
#import "GNUstepBase/GSXML.h"
|
|
||||||
static int XML_ELEMENT_NODE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define inrange(ch,min,max) ((ch)>=(min) && (ch)<=(max))
|
#define inrange(ch,min,max) ((ch)>=(min) && (ch)<=(max))
|
||||||
#define char2num(ch) \
|
#define char2num(ch) \
|
||||||
inrange(ch,'0','9') \
|
inrange(ch,'0','9') \
|
||||||
|
@ -1179,216 +1174,6 @@ static id parsePlItem(pldata* pld)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBXML
|
|
||||||
static GSXMLNode*
|
|
||||||
elementNode(GSXMLNode* node)
|
|
||||||
{
|
|
||||||
while (node != nil)
|
|
||||||
{
|
|
||||||
if ([node type] == XML_ELEMENT_NODE)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
node = [node next];
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
static id
|
|
||||||
nodeToObject(GSXMLNode* node, NSPropertyListMutabilityOptions o, NSString **e)
|
|
||||||
{
|
|
||||||
CREATE_AUTORELEASE_POOL(arp);
|
|
||||||
id result = nil;
|
|
||||||
|
|
||||||
node = elementNode(node);
|
|
||||||
if (node != nil)
|
|
||||||
{
|
|
||||||
NSString *name;
|
|
||||||
NSString *content;
|
|
||||||
GSXMLNode *children;
|
|
||||||
BOOL isKey = NO;
|
|
||||||
|
|
||||||
name = [node name];
|
|
||||||
children = [node firstChild];
|
|
||||||
content = [children content];
|
|
||||||
children = elementNode(children);
|
|
||||||
|
|
||||||
isKey = [name isEqualToString: @"key"];
|
|
||||||
if (isKey == YES || [name isEqualToString: @"string"] == YES)
|
|
||||||
{
|
|
||||||
if (content == nil)
|
|
||||||
{
|
|
||||||
content = @"";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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] == 'u' || buf[pos] == 'U')
|
|
||||||
&& (len >= pos + 4))
|
|
||||||
{
|
|
||||||
unichar val = 0;
|
|
||||||
unsigned i;
|
|
||||||
BOOL ok = YES;
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
ok = NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ok == YES)
|
|
||||||
{
|
|
||||||
len -= 5;
|
|
||||||
memcpy(&buf[pos], &buf[pos+5],
|
|
||||||
(len - pos) * sizeof(unichar));
|
|
||||||
buf[pos - 1] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (pos < len && buf[pos] != '\\')
|
|
||||||
{
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isKey == NO
|
|
||||||
&& o == NSPropertyListMutableContainersAndLeaves)
|
|
||||||
{
|
|
||||||
content = [NSMutableString stringWithCharacters: buf
|
|
||||||
length: len];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
content = [NSString stringWithCharacters: buf
|
|
||||||
length: len];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = content;
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"true"])
|
|
||||||
{
|
|
||||||
result = [NSNumber numberWithBool: YES];
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"false"])
|
|
||||||
{
|
|
||||||
result = [NSNumber numberWithBool: NO];
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"integer"])
|
|
||||||
{
|
|
||||||
if (content == nil)
|
|
||||||
{
|
|
||||||
content = @"0";
|
|
||||||
}
|
|
||||||
result = [NSNumber numberWithInt: [content intValue]];
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"real"])
|
|
||||||
{
|
|
||||||
if (content == nil)
|
|
||||||
{
|
|
||||||
content = @"0.0";
|
|
||||||
}
|
|
||||||
result = [NSNumber numberWithDouble: [content doubleValue]];
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"date"])
|
|
||||||
{
|
|
||||||
if (content == nil)
|
|
||||||
{
|
|
||||||
content = @"";
|
|
||||||
}
|
|
||||||
if ([content hasSuffix: @"Z"] == YES && [content length] == 20)
|
|
||||||
{
|
|
||||||
result = [NSCalendarDate dateWithString: content
|
|
||||||
calendarFormat: @"%Y-%m-%dT%H:%M:%SZ"];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = [NSCalendarDate dateWithString: content
|
|
||||||
calendarFormat: @"%Y-%m-%d %H:%M:%S %z"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"data"])
|
|
||||||
{
|
|
||||||
result = [GSMimeDocument decodeBase64:
|
|
||||||
[content dataUsingEncoding: NSASCIIStringEncoding]];
|
|
||||||
if (o == NSPropertyListMutableContainersAndLeaves)
|
|
||||||
{
|
|
||||||
result = AUTORELEASE([result mutableCopy]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// container class
|
|
||||||
else if ([name isEqualToString: @"array"])
|
|
||||||
{
|
|
||||||
NSMutableArray *container = [plArray array];
|
|
||||||
|
|
||||||
while (children != nil)
|
|
||||||
{
|
|
||||||
id val;
|
|
||||||
|
|
||||||
val = nodeToObject(children, o, e);
|
|
||||||
[container addObject: val];
|
|
||||||
children = [children nextElement];
|
|
||||||
}
|
|
||||||
result = container;
|
|
||||||
if (o == NSPropertyListImmutable)
|
|
||||||
{
|
|
||||||
[result makeImmutableCopyOnFail: NO];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ([name isEqualToString: @"dict"])
|
|
||||||
{
|
|
||||||
NSMutableDictionary *container = [plDictionary dictionary];
|
|
||||||
|
|
||||||
while (children != nil)
|
|
||||||
{
|
|
||||||
NSString *key;
|
|
||||||
id val;
|
|
||||||
|
|
||||||
key = nodeToObject(children, o, e);
|
|
||||||
children = [children nextElement];
|
|
||||||
val = nodeToObject(children, o, e);
|
|
||||||
children = [children nextElement];
|
|
||||||
[container setObject: val forKey: key];
|
|
||||||
}
|
|
||||||
result = container;
|
|
||||||
if (o == NSPropertyListImmutable)
|
|
||||||
{
|
|
||||||
[result makeImmutableCopyOnFail: NO];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IF_NO_GC([result retain]; [arp release];)
|
|
||||||
return AUTORELEASE(result);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
id
|
id
|
||||||
GSPropertyListFromStringsFormat(NSString *string)
|
GSPropertyListFromStringsFormat(NSString *string)
|
||||||
{
|
{
|
||||||
|
@ -2415,13 +2200,6 @@ static BOOL classInitialized = NO;
|
||||||
{
|
{
|
||||||
classInitialized = YES;
|
classInitialized = YES;
|
||||||
|
|
||||||
#if HAVE_LIBXML
|
|
||||||
/*
|
|
||||||
* Cache XML node information.
|
|
||||||
*/
|
|
||||||
XML_ELEMENT_NODE = [GSXMLNode typeFromDescription: @"XML_ELEMENT_NODE"];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NSStringClass = [NSString class];
|
NSStringClass = [NSString class];
|
||||||
NSMutableStringClass = [NSMutableString class];
|
NSMutableStringClass = [NSMutableString class];
|
||||||
NSDataClass = [NSData class];
|
NSDataClass = [NSData class];
|
||||||
|
@ -2639,47 +2417,19 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||||
{
|
{
|
||||||
case NSPropertyListXMLFormat_v1_0:
|
case NSPropertyListXMLFormat_v1_0:
|
||||||
{
|
{
|
||||||
#if HAVE_LIBXML
|
GSXMLPListParser *parser;
|
||||||
GSXMLParser *parser;
|
|
||||||
GSXMLNode *node;
|
|
||||||
|
|
||||||
parser = [GSXMLParser parser];
|
parser = [GSXMLPListParser alloc];
|
||||||
[parser substituteEntities: YES];
|
parser = AUTORELEASE([parser initWithData: data
|
||||||
[parser doValidityChecking: YES];
|
mutability: anOption]);
|
||||||
[parser saveMessages: YES];
|
if ([parser parse] == YES)
|
||||||
if ([parser parse: data] == NO || [parser parse: nil] == NO)
|
|
||||||
{
|
{
|
||||||
error = @"failed to parse as valid XML matching DTD";
|
result = AUTORELEASE(RETAIN([parser result]));
|
||||||
}
|
}
|
||||||
node = [[parser document] root];
|
else if (error == nil)
|
||||||
if (error == nil && [[node name] isEqualToString: @"plist"] == NO)
|
|
||||||
{
|
{
|
||||||
error = @"failed to parse as XML property list";
|
error = @"failed to parse as XML property list";
|
||||||
}
|
}
|
||||||
if (error == nil)
|
|
||||||
{
|
|
||||||
result = nodeToObject([node firstChild], anOption, &error);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/* The libxml based parser is stricter than the fallback
|
|
||||||
* parser, so if parsing failed using that, we can try again.
|
|
||||||
*/
|
|
||||||
if (result == nil)
|
|
||||||
{
|
|
||||||
GSXMLPListParser *parser;
|
|
||||||
|
|
||||||
parser = [GSXMLPListParser alloc];
|
|
||||||
parser = AUTORELEASE([parser initWithData: data
|
|
||||||
mutability: anOption]);
|
|
||||||
if ([parser parse] == YES)
|
|
||||||
{
|
|
||||||
result = AUTORELEASE(RETAIN([parser result]));
|
|
||||||
}
|
|
||||||
else if (error == nil)
|
|
||||||
{
|
|
||||||
error = @"failed to parse as XML property list";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue