ObjFW  Diff

Differences From Artifact [ac798fd712]:

To Artifact [706b49d04b]:


20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42







-
+







-
+







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

#include <math.h>

#include <assert.h>

#import "OFString+JSONValue.h"
#import "OFString+JSONParsing.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFNull.h"

#import "OFInvalidJSONException.h"

int _OFString_JSONValue_reference;
int _OFString_JSONParsing_reference;

static id nextObject(const char **pointer, const char *stop, size_t *line,
    size_t depthLimit);

static void
skipWhitespaces(const char **pointer, const char *stop, size_t *line)
{
524
525
526
527
528
529
530
531

532
533
534
535
536
537
538
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538







-
+








	return dictionary;
}

static inline OFNumber *
parseNumber(const char **pointer, const char *stop, size_t *line)
{
	bool isHex = (*pointer + 1 < stop && (*pointer)[1] == 'x');
	bool isNegative = (*pointer < stop && (*pointer)[0] == '-');
	bool hasDecimal = false;
	size_t i;
	OFString *string;
	OFNumber *number;

	for (i = 0; *pointer + i < stop; i++) {
		if ((*pointer)[i] == '.')
553
554
555
556
557
558
559
560
561
562
563
564
565
566



567
568
569


570
571
572
573
574
575
576
553
554
555
556
557
558
559



560
561
562
563
564
565
566
567


568
569
570
571
572
573
574
575
576







-
-
-




+
+
+

-
-
+
+







					       length: i];
	*pointer += i;

	@try {
		if (hasDecimal)
			number = [OFNumber numberWithDouble:
			    string.doubleValue];
		else if (isHex)
			number = [OFNumber numberWithIntMax:
			    string.hexadecimalValue];
		else if ([string isEqual: @"Infinity"])
			number = [OFNumber numberWithDouble: INFINITY];
		else if ([string isEqual: @"-Infinity"])
			number = [OFNumber numberWithDouble: -INFINITY];
		else if (isNegative)
			number = [OFNumber numberWithLongLong:
			    [string longLongValueWithBase: 0]];
		else
			number = [OFNumber numberWithIntMax:
			    string.decimalValue];
			number = [OFNumber numberWithUnsignedLongLong:
			    [string unsignedLongLongValueWithBase: 0]];
	} @finally {
		[string release];
	}

	return number;
}

637
638
639
640
641
642
643
644
645


646
647

648
649
650

651
652
653
654
655
656
657
637
638
639
640
641
642
643


644
645
646

647
648
649

650
651
652
653
654
655
656
657







-
-
+
+

-
+


-
+







	case 'I':
		return parseNumber(pointer, stop, line);
	default:
		return nil;
	}
}

@implementation OFString (JSONValue)
- (id)JSONValue
@implementation OFString (JSONParsing)
- (id)objectByParsingJSON
{
	return [self JSONValueWithDepthLimit: 32];
	return [self objectByParsingJSONWithDepthLimit: 32];
}

- (id)JSONValueWithDepthLimit: (size_t)depthLimit
- (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit
{
	void *pool = objc_autoreleasePoolPush();
	const char *pointer = self.UTF8String;
	const char *stop = pointer + self.UTF8StringLength;
	id object;
	size_t line = 1;