ObjFW  Check-in [6b21acb1a9]

Overview
Comment:Let OFXMLElement take a stream instead of a file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6b21acb1a95438adc3729f2e683b11a98d50c0d0a33c48a42e06600cc25ef748
User & Date: js on 2020-12-29 13:11:55
Other Links: manifest | tags
Context
2020-12-29
13:53
generators/library: Restructure the code a little check-in: a9e0972112 user: js tags: trunk
13:11
Let OFXMLElement take a stream instead of a file check-in: 6b21acb1a9 user: js tags: trunk
2020-12-27
19:13
Don't use sfdc / cvinclude.pl anymore check-in: bb25f8b0fe user: js tags: trunk
Changes

Modified src/OFXMLElement.h from [817f97f00f] to [a8bd3c93ce].

19
20
21
22
23
24
25

26
27
28
29
30
31
32

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
@class OFMutableString;

@class OFString;
@class OFXMLAttribute;

/**
 * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h
 *
 * @brief A class which stores an XML element.







>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

OF_ASSUME_NONNULL_BEGIN

@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
 *
 * @brief A class which stores an XML element.
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 * @brief Parses the string and returns an OFXMLElement for it.
 *
 * @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.
 *
 * @param path The path to the file
 * @return A new autoreleased OFXMLElement with the contents of the specified
 *	   file
 */
+ (instancetype)elementWithFile: (OFString *)path;
#endif

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFXMLElement with the specified name.
 *
 * @param name The name for the element







<

|

|

|

|
<







137
138
139
140
141
142
143

144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
 * @brief Parses the string and returns an OFXMLElement for it.
 *
 * @param string The string to parse
 * @return A new autoreleased OFXMLElement with the contents of the string
 */
+ (instancetype)elementWithXMLString: (OFString *)string;


/**
 * @brief Parses the specified stream and returns an OFXMLElement for it.
 *
 * @param stream The stream to parse
 * @return A new autoreleased OFXMLElement with the contents of the specified
 *	   stream
 */
+ (instancetype)elementWithStream: (OFStream *)stream;


- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFXMLElement with the specified name.
 *
 * @param name The name for the element
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 *	  with it.
 *
 * @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
 *	  OFXMLElement with it.
 *
 * @param path The path to the file
 * @return An initialized OFXMLElement with the contents of the specified file
 */
- (instancetype)initWithFile: (OFString *)path;
#endif

- (instancetype)initWithSerialization: (OFXMLElement *)element;

/**
 * @brief Sets a prefix for a namespace.
 *
 * @param prefix The prefix for the namespace







<

|


|
|

|
<







213
214
215
216
217
218
219

220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
 *	  with it.
 *
 * @param string The string to parse
 * @return An initialized OFXMLElement with the contents of the string
 */
- (instancetype)initWithXMLString: (OFString *)string;


/**
 * @brief Parses the specified stream and initializes an already allocated
 *	  OFXMLElement with it.
 *
 * @param stream The stream to parse
 * @return An initialized OFXMLElement with the contents of the specified stream
 */
- (instancetype)initWithStream: (OFStream *)stream;


- (instancetype)initWithSerialization: (OFXMLElement *)element;

/**
 * @brief Sets a prefix for a namespace.
 *
 * @param prefix The prefix for the namespace

Modified src/OFXMLElement.m from [c47060e7f9] to [47bfb07248].

21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44

#include <stdlib.h>
#include <string.h>

#include <assert.h>

#import "OFXMLElement.h"
#import "OFXMLNode+Private.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFData.h"
#import "OFXMLAttribute.h"

#import "OFXMLCharacters.h"
#import "OFXMLCDATA.h"
#import "OFXMLParser.h"
#import "OFXMLElementBuilder.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFUnboundNamespaceException.h"

/* References for static linking */







|
|
|
|
|

>

|
|
|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include <stdlib.h>
#include <string.h>

#include <assert.h>

#import "OFXMLElement.h"
#import "OFArray.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFXMLAttribute.h"
#import "OFXMLCDATA.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"

/* References for static linking */
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
}

+ (instancetype)elementWithXMLString: (OFString *)string
{
	return [[[self alloc] initWithXMLString: string] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)elementWithFile: (OFString *)path
{
	return [[[self alloc] initWithFile: path] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithName: (OFString *)name







<
|

|

<







111
112
113
114
115
116
117

118
119
120
121

122
123
124
125
126
127
128
}

+ (instancetype)elementWithXMLString: (OFString *)string
{
	return [[[self alloc] initWithXMLString: string] autorelease];
}


+ (instancetype)elementWithStream: (OFStream *)stream
{
	return [[[self alloc] initWithStream: stream] autorelease];
}


- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithName: (OFString *)name
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithFile: (OFString *)path
{
	void *pool;
	OFXMLParser *parser;
	OFXMLElementBuilder *builder;
	OFXMLElementElementBuilderDelegate *delegate;

	[self release];

	pool = objc_autoreleasePoolPush();

	parser = [OFXMLParser parser];
	builder = [OFXMLElementBuilder elementBuilder];
	delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
	    autorelease];

	parser.delegate = builder;
	builder.delegate = delegate;

	[parser parseFile: path];

	if (!parser.hasFinishedParsing)
		@throw [OFMalformedXMLException exceptionWithParser: parser];

	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	self = [super of_init];

	@try {
		void *pool = objc_autoreleasePoolPush();







<
|


















|










<







229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);

	return self;
}


- (instancetype)initWithStream: (OFStream *)stream
{
	void *pool;
	OFXMLParser *parser;
	OFXMLElementBuilder *builder;
	OFXMLElementElementBuilderDelegate *delegate;

	[self release];

	pool = objc_autoreleasePoolPush();

	parser = [OFXMLParser parser];
	builder = [OFXMLElementBuilder elementBuilder];
	delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
	    autorelease];

	parser.delegate = builder;
	builder.delegate = delegate;

	[parser parseStream: stream];

	if (!parser.hasFinishedParsing)
		@throw [OFMalformedXMLException exceptionWithParser: parser];

	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);

	return self;
}


- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	self = [super of_init];

	@try {
		void *pool = objc_autoreleasePoolPush();

Modified src/OFXMLParser.h from [9632092363] to [6159c08e1a].

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

/**
 * @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







<
<
<
<
<
<
<
<
<



224
225
226
227
228
229
230









231
232
233

/**
 * @brief Parses the specified stream.
 *
 * @param stream The stream to parse
 */
- (void)parseStream: (OFStream *)stream;









@end

OF_ASSUME_NONNULL_END

Modified src/OFXMLParser.m from [a0e17680fe] to [495894cd91].

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
				   length: length];
		}
	} @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) {
			self->_state = OF_XMLPARSER_OUTSIDE_TAG;
			self->_i--;







<
<
<
<
<
<
<
<
<
<
<
<
<







289
290
291
292
293
294
295













296
297
298
299
300
301
302
				   length: length];
		}
	} @finally {
		free(buffer);
	}
}














static void
inByteOrderMarkState(OFXMLParser *self)
{
	if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) {
		if (self->_level == 0) {
			self->_state = OF_XMLPARSER_OUTSIDE_TAG;
			self->_i--;