Tweak to allow leading and trailing whitespace in an xml property list.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30454 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-05-25 11:46:38 +00:00
parent fbfc255123
commit 5d036eee5e
3 changed files with 29 additions and 13 deletions

View file

@ -1,8 +1,9 @@
2010-05-25 Richard Frith-Macdonald <rfm@gnu.org> 2010-05-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSPropertyList.m: ([-parser;foundChartacters:]) don't trim * Source/NSPropertyList.m: ([-parser:foundCharacters:]) don't trim
the supplied string ... we need to retain whitespace around entities the supplied string ... we need to retain whitespace around entities
in value test. in value test. If inside a <string> element, treat ignorable
whitespace as normal whitespace.
* Source/NSXMLParser.m: Add support for ignorable whitespace so that * Source/NSXMLParser.m: Add support for ignorable whitespace so that
it doesn't get handed to the delegate as normal characters. it doesn't get handed to the delegate as normal characters.

View file

@ -87,6 +87,7 @@ extern BOOL GSScanDouble(unichar*, unsigned, double*);
NSString *key; NSString *key;
BOOL inArray; BOOL inArray;
BOOL inDictionary; BOOL inDictionary;
BOOL inString;
BOOL parsed; BOOL parsed;
BOOL success; BOOL success;
id plist; id plist;
@ -144,6 +145,15 @@ foundCharacters: (NSString *)string
[value appendString: string]; [value appendString: string];
} }
- (void) parser: (NSXMLParser *)parser
foundIgnorableWhitespace: (NSString *)string
{
if (YES == inString)
{
[value appendString: string];
}
}
- (void) parser: (NSXMLParser *)parser - (void) parser: (NSXMLParser *)parser
didStartElement: (NSString *)elementName didStartElement: (NSString *)elementName
namespaceURI: (NSString *)namespaceURI namespaceURI: (NSString *)namespaceURI
@ -182,6 +192,10 @@ foundCharacters: (NSString *)string
inArray = YES; inArray = YES;
inDictionary = NO; inDictionary = NO;
} }
else if ([elementName isEqualToString: @"string"] == YES)
{
inString = YES;
}
} }
- (void) parser: (NSXMLParser *)parser - (void) parser: (NSXMLParser *)parser
@ -191,11 +205,12 @@ foundCharacters: (NSString *)string
{ {
BOOL inContainer = NO; BOOL inContainer = NO;
inString = NO;
if ([elementName isEqualToString: @"dict"] == YES) if ([elementName isEqualToString: @"dict"] == YES)
{ {
inContainer = YES; inContainer = YES;
} }
if ([elementName isEqualToString: @"array"] == YES) else if ([elementName isEqualToString: @"array"] == YES)
{ {
inContainer = YES; inContainer = YES;
} }

View file

@ -1314,25 +1314,25 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes);
p--; p--;
} }
} }
if (p < this->cp - 1 && this->foundIgnorable != 0)
{
/* Process data as ignorable whitespace
*/
s = NewUTF8STR(p, this->cp - p - 1);
(*this->foundIgnorable)(_del,
foundIgnorableSel, self, s);
[s release];
}
} }
if (p - vp > 0 && this->foundCharacters != 0) if (p - vp > 0 && this->foundCharacters != 0)
{ {
/* Process remaining data as characters /* Process initial data as characters
*/ */
s = NewUTF8STR(vp, p - vp); s = NewUTF8STR(vp, p - vp);
(*this->foundCharacters)(_del, (*this->foundCharacters)(_del,
foundCharactersSel, self, s); foundCharactersSel, self, s);
[s release]; [s release];
} }
if (p < this->cp - 1 && this->foundIgnorable != 0)
{
/* Process data as ignorable whitespace
*/
s = NewUTF8STR(p, this->cp - p - 1);
(*this->foundIgnorable)(_del,
foundIgnorableSel, self, s);
[s release];
}
vp = this->cp; vp = this->cp;
} }
} }