Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -264,9 +264,23 @@ * \param buf The buffer to parse * \param size The size of the buffer */ - (void)parseBuffer: (const char*)buf withSize: (size_t)size; + +/** + * Parses the specified string. + * + * \param str The string to parse + */ +- (void)parseString: (OFString*)str; + +/** + * Parses the specified file. + * + * \param path The path to the file to parse +*/ +- (void)parseFile: (OFString*)path; @end @interface OFObject (OFXMLParserDelegate) @end Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -17,10 +17,11 @@ #import "OFXMLParser.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFXMLAttribute.h" +#import "OFFile.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*); @@ -267,10 +268,41 @@ /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (size - last > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last length: size - last]; } + +- (void)parseString: (OFString*)str +{ + [self parseBuffer: [str cString] + withSize: [str cStringLength]]; +} + +- (void)parseFile: (OFString*)path +{ + OFFile *file = [[OFFile alloc] initWithPath: path + mode: @"rb"]; + + @try { + char *buf = [self allocMemoryWithSize: of_pagesize]; + + @try { + while (![file isAtEndOfStream]) { + size_t size; + + size = [file readNBytes: of_pagesize + intoBuffer: buf]; + [self parseBuffer: buf + withSize: size]; + } + } @finally { + [self freeMemory: buf]; + } + } @finally { + [file release]; + } +} /* * The following methods handle the different states of the parser. They are * lookup up in +[initialize] and put in a lookup table to speed things up. * One dispatch for every character would be way too slow!