Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -21,10 +21,11 @@ @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableString; +@class OFStream; @class OFString; @class OFXMLAttribute; /** * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h @@ -138,20 +139,18 @@ * @param string The string to parse * @return A new autoreleased OFXMLElement with the contents of the string */ + (instancetype)elementWithXMLString: (OFString *)string; -#ifdef OF_HAVE_FILES /** - * @brief Parses the specified file and returns an OFXMLElement for it. + * @brief Parses the specified stream and returns an OFXMLElement for it. * - * @param path The path to the file + * @param stream The stream to parse * @return A new autoreleased OFXMLElement with the contents of the specified - * file + * stream */ -+ (instancetype)elementWithFile: (OFString *)path; -#endif ++ (instancetype)elementWithStream: (OFStream *)stream; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFXMLElement with the specified name. @@ -216,20 +215,18 @@ * @param string The string to parse * @return An initialized OFXMLElement with the contents of the string */ - (instancetype)initWithXMLString: (OFString *)string; -#ifdef OF_HAVE_FILES /** - * @brief Parses the specified file and initializes an already allocated + * @brief Parses the specified stream and initializes an already allocated * OFXMLElement with it. * - * @param path The path to the file - * @return An initialized OFXMLElement with the contents of the specified file + * @param stream The stream to parse + * @return An initialized OFXMLElement with the contents of the specified stream */ -- (instancetype)initWithFile: (OFString *)path; -#endif +- (instancetype)initWithStream: (OFStream *)stream; - (instancetype)initWithSerialization: (OFXMLElement *)element; /** * @brief Sets a prefix for a namespace. Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -23,20 +23,21 @@ #include #include #import "OFXMLElement.h" -#import "OFXMLNode+Private.h" -#import "OFString.h" #import "OFArray.h" -#import "OFDictionary.h" #import "OFData.h" +#import "OFDictionary.h" +#import "OFStream.h" +#import "OFString.h" #import "OFXMLAttribute.h" -#import "OFXMLCharacters.h" #import "OFXMLCDATA.h" -#import "OFXMLParser.h" +#import "OFXMLCharacters.h" #import "OFXMLElementBuilder.h" +#import "OFXMLNode+Private.h" +#import "OFXMLParser.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" @@ -112,16 +113,14 @@ + (instancetype)elementWithXMLString: (OFString *)string { return [[[self alloc] initWithXMLString: string] autorelease]; } -#ifdef OF_HAVE_FILES -+ (instancetype)elementWithFile: (OFString *)path ++ (instancetype)elementWithStream: (OFStream *)stream { - return [[[self alloc] initWithFile: path] autorelease]; + return [[[self alloc] initWithStream: stream] autorelease]; } -#endif - (instancetype)init { OF_INVALID_INIT_METHOD } @@ -232,12 +231,11 @@ objc_autoreleasePoolPop(pool); return self; } -#ifdef OF_HAVE_FILES -- (instancetype)initWithFile: (OFString *)path +- (instancetype)initWithStream: (OFStream *)stream { void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElementElementBuilderDelegate *delegate; @@ -252,11 +250,11 @@ autorelease]; parser.delegate = builder; builder.delegate = delegate; - [parser parseFile: path]; + [parser parseStream: stream]; if (!parser.hasFinishedParsing) @throw [OFMalformedXMLException exceptionWithParser: parser]; self = [delegate->_element retain]; @@ -263,11 +261,10 @@ objc_autoreleasePoolPop(pool); return self; } -#endif - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [super of_init]; Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -226,17 +226,8 @@ * @brief Parses the specified stream. * * @param stream The stream to parse */ - (void)parseStream: (OFStream *)stream; - -#ifdef OF_HAVE_FILES -/** - * @brief Parses the specified file. - * - * @param path The path to the file to parse -*/ -- (void)parseFile: (OFString *)path; -#endif @end OF_ASSUME_NONNULL_END Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -291,23 +291,10 @@ } @finally { free(buffer); } } -#ifdef OF_HAVE_FILES -- (void)parseFile: (OFString *)path -{ - OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"r"]; - @try { - [self parseStream: file]; - } @finally { - [file release]; - } -} -#endif - static void inByteOrderMarkState(OFXMLParser *self) { if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) { if (self->_level == 0) {