ObjFW  Diff

Differences From Artifact [5f77e1f7f1]:

To Artifact [12e5560901]:


38
39
40
41
42
43
44





















































45
46
47
48
49
50
51
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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







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







static void
skipWhitespaces(const char *restrict *pointer, const char *stop)
{
	while (*pointer < stop && (**pointer == ' ' || **pointer == '\t' ||
	    **pointer == '\r' || **pointer == '\n'))
		(*pointer)++;
}

static void
skipComment(const char *restrict *pointer, const char *stop)
{
	if (**pointer != '/')
		return;

	if (*pointer + 1 >= stop)
		return;

	(*pointer)++;

	if (**pointer == '*') {
		BOOL lastIsAsterisk = NO;

		(*pointer)++;

		while (*pointer < stop) {
			if (lastIsAsterisk && **pointer == '/') {
				(*pointer)++;
				return;
			}

			lastIsAsterisk = (**pointer == '*');

			(*pointer)++;
		}
	} else {
		(*pointer)++;

		while (*pointer < stop) {
			if (**pointer == '\r' || **pointer == '\n') {
				(*pointer)++;
				return;
			}

			(*pointer)++;
		}
	}
}

static void
skipWhitespacesAndComments(const char *restrict *pointer, const char *stop)
{
	const char *old = NULL;

	while (old != *pointer) {
		old = *pointer;

		skipWhitespaces(pointer, stop);
		skipComment(pointer, stop);
	}
}

static OF_INLINE uint16_t
parseUnicodeEscape(const char *pointer, const char *stop)
{
	uint16_t ret = 0;
	char i;

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







-
+











-
+





-
+








	if (++(*pointer) >= stop)
		return nil;

	while (**pointer != ']') {
		id object;

		skipWhitespaces(pointer, stop);
		skipWhitespacesAndComments(pointer, stop);
		if (*pointer >= stop)
			return nil;

		if (**pointer == ']')
			break;

		if ((object = nextObject(pointer, stop)) == nil)
			return nil;

		[array addObject: object];

		skipWhitespaces(pointer, stop);
		skipWhitespacesAndComments(pointer, stop);
		if (*pointer >= stop)
			return nil;

		if (**pointer == ',') {
			(*pointer)++;
			skipWhitespaces(pointer, stop);
			skipWhitespacesAndComments(pointer, stop);

			if (*pointer >= stop)
				return nil;
		} else if (**pointer != ']')
			return nil;
	}

257
258
259
260
261
262
263
264

265
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
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335
336
337
338

339
340
341
342
343
344

345
346
347
348
349
350
351
352







-
+









-
+











-
+





-
+








	if (++(*pointer) >= stop)
		return nil;

	while (**pointer != '}') {
		id key, object;

		skipWhitespaces(pointer, stop);
		skipWhitespacesAndComments(pointer, stop);
		if (*pointer >= stop)
			return nil;

		if (**pointer == '}')
			break;

		if ((key = nextObject(pointer, stop)) == nil)
			return nil;

		skipWhitespaces(pointer, stop);
		skipWhitespacesAndComments(pointer, stop);
		if (*pointer + 1 >= stop || **pointer != ':')
			return nil;

		(*pointer)++;

		if ((object = nextObject(pointer, stop)) == nil)
			return nil;

		[dictionary setObject: object
			       forKey: key];

		skipWhitespaces(pointer, stop);
		skipWhitespacesAndComments(pointer, stop);
		if (*pointer >= stop)
			return nil;

		if (**pointer == ',') {
			(*pointer)++;
			skipWhitespaces(pointer, stop);
			skipWhitespacesAndComments(pointer, stop);

			if (*pointer >= stop)
				return nil;
		} else if (**pointer != '}')
			return nil;
	}

340
341
342
343
344
345
346
347

348
349
350
351
352
353
354
393
394
395
396
397
398
399

400
401
402
403
404
405
406
407







-
+








	return number;
}

static id
nextObject(const char *restrict *pointer, const char *stop)
{
	skipWhitespaces(pointer, stop);
	skipWhitespacesAndComments(pointer, stop);

	if (*pointer >= stop)
		return nil;

	switch (**pointer) {
	case '"':
		return parseString(pointer, stop);
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
460
461
462
463
464
465
466

467
468
469
470
471
472
473
474







-
+







- (id)JSONValue
{
	const char *pointer = [self UTF8String];
	const char *stop = pointer + [self UTF8StringLength];
	id object;

	object = nextObject(&pointer, stop);
	skipWhitespaces(&pointer, stop);
	skipWhitespacesAndComments(&pointer, stop);

	if (pointer < stop || object == nil)
		@throw [OFInvalidEncodingException exceptionWithClass: isa];

	return object;
}
@end