ObjFW  Check-in [1eedeefc72]

Overview
Comment:Get rid of appendCStringWithoutUTF8Checking:encoding:length:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1eedeefc721923b603919f25aea7f646fd2e934c5c95a8a571a2d9244c4e2235
User & Date: js on 2011-05-08 17:33:29
Other Links: manifest | tags
Context
2011-05-08
18:32
OFNumber: Explicitly use signed and improve documentation. check-in: eb2402a77a user: js tags: trunk
17:33
Get rid of appendCStringWithoutUTF8Checking:encoding:length:]. check-in: 1eedeefc72 user: js tags: trunk
17:19
More documentation improvements. check-in: 242b1ccd71 user: js tags: trunk
Changes

Modified src/OFMutableString.h from [02e4c6ad2f] to [a158f1d48a].

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
79
80
81
82
83
84
85
















86
87
88
89
90
91
92







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







 *
 * \param string A UTF-8 encoded C string to append
 * \param length The length of the UTF-8 encoded C string
 */
- (void)appendCStringWithoutUTF8Checking: (const char*)string
				  length: (size_t)length;

/**
 * Appends a C string with the specified encoding and length length to the
 * OFString without checking whether it is valid UTF-8 if the specified encoding
 * is UTF-8.
 *
 * Only use this if you are 100% sure the string you append is either ASCII or
 * UTF-8 if you specified UTF-8 as encoding!
 *
 * \param string A C string to append
 * \param encoding The encoding of the C string
 * \param length The length of the UTF-8 encoded C string
 */
- (void)appendCStringWithoutUTF8Checking: (const char*)string
				encoding: (of_string_encoding_t)encoding
				  length: (size_t)length;

/**
 * Appends another OFString to the OFMutableString.
 *
 * \param string An OFString to append
 */
- (void)appendString: (OFString*)string;

Modified src/OFMutableString.m from [0eff2f55bc] to [a73fb6b373].

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
244
245
246
247
248
249
250
















251
252
253
254
255
256
257







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	string = [self resizeMemory: string
			     toSize: length + length_ + 1];
	memcpy(string + length, string_, length_);
	length += length_;
	string[length] = 0;
}

- (void)appendCStringWithoutUTF8Checking: (const char*)string_
				encoding: (of_string_encoding_t)encoding
				  length: (size_t)length_
{
	if (encoding == OF_STRING_ENCODING_UTF_8)
		[self appendCStringWithoutUTF8Checking: string_
						length: length_];
	else {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		[self appendString: [OFString stringWithCString: string_
						       encoding: encoding
							 length: length_]];
		[pool release];
	}
}

- (void)appendString: (OFString*)string_
{
	if (string_ == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	[self appendCString: [string_ cString]];

Modified src/OFXMLParser.m from [b060def371] to [c68cb5d129].

35
36
37
38
39
40
41
















42
43
44
45
46
47
48
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#import "OFUnboundNamespaceException.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 lookupTable[OF_XMLPARSER_NUM_STATES];

static void
cache_append(OFMutableString *cache, const char *string,
    of_string_encoding_t encoding, size_t length)
{
	if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8))
		[cache appendCStringWithoutUTF8Checking: string
						 length: length];
	else {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		[cache appendString: [OFString stringWithCString: string
							encoding: encoding
							  length: length]];
		[pool release];
	}
}

static OFString*
transform_string(OFMutableString *cache, size_t cut, BOOL unescape,
    OFObject <OFStringXMLUnescapingDelegate> *delegate)
{
	[cache replaceOccurrencesOfString: @"\r\n"
			       withString: @"\n"];
212
213
214
215
216
217
218
219

220
221
222
223
224
225
226
227

228
229
230
231
232

233

234
235
236

237
238
239
240
241
242
243

244
245
246
247
248
249
250
228
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







-
+







-
+





+
-
+


-
+




-
-
-
+







}

- (void)setDelegate: (id <OFXMLParserDelegate>)delegate_
{
	OF_SETTER(delegate, delegate_, YES, NO)
}

- (void)parseBuffer: (const char*)buf
- (void)parseBuffer: (const char*)buffer
	 withLength: (size_t)length
{
	size_t i, last = 0;

	for (i = 0; i < length; i++) {
		size_t j = i;

		lookupTable[state](self, selectors[state], buf, &i, &last);
		lookupTable[state](self, selectors[state], buffer, &i, &last);

		/* Ensure we don't count this character twice */
		if (i != j)
			continue;

		if (buffer[i] == '\r' || (buffer[i] == '\n' &&
		if (buf[i] == '\r' || (buf[i] == '\n' && !lastCarriageReturn))
		    !lastCarriageReturn))
			lineNumber++;

		lastCarriageReturn = (buf[i] == '\r');
		lastCarriageReturn = (buffer[i] == '\r');
	}

	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (length - last > 0 && state != OF_XMLPARSER_IN_TAG)
		[cache appendCStringWithoutUTF8Checking: buf + last
					       encoding: encoding
						 length: length - last];
		cache_append(cache, buffer + last, encoding, length - last);
}

- (void)parseString: (OFString*)string
{
	[self parseBuffer: [string cString]
	       withLength: [string cStringLength]];
}
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
312
313
314
315
316
317
318

319


320
321
322
323
324
325
326







-
+
-
-







		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	if (buffer[*i] != '<')
		return;

	if ((length = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, length);
					       encoding: encoding
						 length: length];

	if ([cache cStringLength] > 0) {
		OFString *characters;
		OFAutoreleasePool *pool;

		pool = [[OFAutoreleasePool alloc] init];
		characters = transform_string(cache, 0, YES, self);
465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480
481
478
479
480
481
482
483
484

485


486
487
488
489
490
491
492







-
+
-
-







{
	if (buffer[*i] == '?')
		level = 1;
	else if (level == 1 && buffer[*i] == '>') {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
		OFString *pi;

		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, *i - *last);
					       encoding: encoding
						 length: *i - *last];
		pi = transform_string(cache, 1, NO, nil);

		if ([pi isEqual: @"xml"] || [pi hasPrefix: @"xml "] ||
		    [pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] ||
		    [pi hasPrefix: @"xml\n"])
			if (![self _parseXMLProcessingInstructions: pi])
				@throw [OFMalformedXMLException
504
505
506
507
508
509
510
511

512
513
514
515
516
517
518
519
520
515
516
517
518
519
520
521

522


523
524
525
526
527
528
529







-
+
-
-







	size_t length, cacheLength;

	if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' &&
	    buffer[*i] != '\r' && buffer[*i] != '>' && buffer[*i] != '/')
		return;

	if ((length = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, length);
					       encoding: encoding
						 length: length];

	cacheCString = [cache cString];
	cacheLength = [cache cStringLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
		name = [[OFString alloc] initWithCString: tmp + 1
						  length: cacheLength -
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
608
609
610
611
612
613
614

615


616
617
618
619
620
621
622







-
+
-
-







	OFString *ns;

	if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' &&
	    buffer[*i] != '\r' && buffer[*i] != '>')
		return;

	if ((length = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, length);
					       encoding: encoding
						 length: length];

	cacheCString = [cache cString];
	cacheLength = [cache cStringLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
		name = [[OFString alloc] initWithCString: tmp + 1
						  length: cacheLength -
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
766
767
758
759
760
761
762
763
764

765


766
767
768
769
770
771
772







-
+
-
-







	const char *cacheCString, *tmp;
	size_t length, cacheLength;

	if (buffer[*i] != '=')
		return;

	if ((length = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, length);
					       encoding: encoding
						 length: length];

	[cache deleteLeadingAndTrailingWhitespaces];

	cacheCString = [cache cString];
	cacheLength = [cache cStringLength];

	if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) {
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825
826
815
816
817
818
819
820
821

822


823
824
825
826
827
828
829







-
+
-
-







	OFString *attributeValue;
	size_t length;

	if (buffer[*i] != delimiter)
		return;

	if ((length = *i - *last) > 0)
		[cache appendCStringWithoutUTF8Checking: buffer + *last
		cache_append(cache, buffer + *last, encoding, length);
					       encoding: encoding
						 length: length];

	pool = [[OFAutoreleasePool alloc] init];
	attributeValue = transform_string(cache, 0, YES, self);

	if (attributePrefix == nil && [attributeName isEqual: @"xmlns"])
		[[namespaces lastObject] setObject: attributeValue
					    forKey: @""];
940
941
942
943
944
945
946
947

948
949
950
951
952
953
954
955
956
943
944
945
946
947
948
949

950


951
952
953
954
955
956
957







-
+
-
-







		level = (buffer[*i] == ']' ? 1 : 0);

		return;
	}

	pool = [[OFAutoreleasePool alloc] init];

	[cache appendCStringWithoutUTF8Checking: buffer + *last
	cache_append(cache, buffer + *last, encoding, *i - *last);
				       encoding: encoding
					 length: *i - *last];
	CDATA = transform_string(cache, 2, NO, nil);

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (CDATAHandler != NULL)
		CDATAHandler(self, CDATA);
	else
#endif
1001
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011
1012
1013
1014
1015
1016
1017
1002
1003
1004
1005
1006
1007
1008

1009


1010
1011
1012
1013
1014
1015
1016







-
+
-
-








	if (buffer[*i] != '>')
		@throw [OFMalformedXMLException newWithClass: isa
						      parser: self];

	pool = [[OFAutoreleasePool alloc] init];

	[cache appendCStringWithoutUTF8Checking: buffer + *last
	cache_append(cache, buffer + *last, encoding, *i - *last);
				       encoding: encoding
					 length: *i - *last];
	comment = transform_string(cache, 2, NO, nil);

#if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
	if (commentHandler != NULL)
		commentHandler(self, comment);
	else
#endif