@@ -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!