ObjFW  Diff

Differences From Artifact [e26bece34a]:

To Artifact [bcc7e9f4bd]:


15
16
17
18
19
20
21

22
23
24
25
26
27
28
#include <unistd.h>

#import "OFXMLParser.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFXMLAttribute.h"

#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "macros.h"

typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*);
static SEL selectors[OF_XMLPARSER_NUM_STATES];
static state_function lookup_table[OF_XMLPARSER_NUM_STATES];







>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <unistd.h>

#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*);
static SEL selectors[OF_XMLPARSER_NUM_STATES];
static state_function lookup_table[OF_XMLPARSER_NUM_STATES];
265
266
267
268
269
270
271































272
273
274
275
276
277
278
		lookup_table[state](self, selectors[state], buf, &i, &last);

	/* 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];
}
































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








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
		lookup_table[state](self, selectors[state], buf, &i, &last);

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