ObjFW  Diff

Differences From Artifact [51b9feaad9]:

To Artifact [b7816611b8]:


2348
2349
2350
2351
2352
2353
2354
2355

2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375




2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387

2388
2389
2390
2391
2392
2393
2394
2348
2349
2350
2351
2352
2353
2354

2355


2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369




2370
2371
2372
2373

2374
2375
2376
2377
2378
2379
2380
2381



2382
2383
2384
2385
2386
2387
2388
2389







-
+
-
-














-
-
-
-
+
+
+
+
-








-
-
-
+







{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = [self characters];
	size_t i = 0, length = [self length];
	intmax_t value = 0;
	bool expectWhitespace = false;

	while (length > 0 && (*characters == ' ' || *characters == '\t' ||
	while (length > 0 && of_ascii_isspace(*characters)) {
	    *characters == '\n' || *characters == '\r' ||
	    *characters == '\f')) {
		characters++;
		length--;
	}

	if (length == 0) {
		objc_autoreleasePoolPop(pool);
		return 0;
	}

	if (characters[0] == '-' || characters[0] == '+')
		i++;

	for (; i < length; i++) {
		if (expectWhitespace) {
			if (characters[i] != ' ' && characters[i] != '\t' &&
			    characters[i] != '\n' && characters[i] != '\r' &&
			    characters[i] != '\f')
				@throw [OFInvalidFormatException exception];
			if (of_ascii_isspace(characters[i]))
				continue;

			@throw [OFInvalidFormatException exception];
			continue;
		}

		if (characters[i] >= '0' && characters[i] <= '9') {
			if (INTMAX_MAX / 10 < value ||
			    INTMAX_MAX - value * 10 < characters[i] - '0')
				@throw [OFOutOfRangeException exception];

			value = (value * 10) + (characters[i] - '0');
		} else if (characters[i] == ' ' || characters[i] == '\t' ||
		    characters[i] == '\n' || characters[i] == '\r' ||
		    characters[i] == '\f')
		} else if (of_ascii_isspace(characters[i]))
			expectWhitespace = true;
		else
			@throw [OFInvalidFormatException exception];
	}

	if (characters[0] == '-')
		value *= -1;
2402
2403
2404
2405
2406
2407
2408
2409

2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433




2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447


2448
2449
2450
2451
2452
2453
2454
2455
2397
2398
2399
2400
2401
2402
2403

2404


2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422




2423
2424
2425
2426

2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437


2438
2439

2440
2441
2442
2443
2444
2445
2446







-
+
-
-


















-
-
-
-
+
+
+
+
-











-
-
+
+
-







{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = [self characters];
	size_t i = 0, length = [self length];
	uintmax_t value = 0;
	bool expectWhitespace = false, foundValue = false;

	while (length > 0 && (*characters == ' ' || *characters == '\t' ||
	while (length > 0 && of_ascii_isspace(*characters)) {
	    *characters == '\n' || *characters == '\r' ||
	    *characters == '\f')) {
		characters++;
		length--;
	}

	if (length == 0) {
		objc_autoreleasePoolPop(pool);
		return 0;
	}

	if (length >= 2 && characters[0] == '0' && characters[1] == 'x')
		i = 2;
	else if (length >= 1 && (characters[0] == 'x' || characters[0] == '$'))
		i = 1;

	for (; i < length; i++) {
		uintmax_t newValue;

		if (expectWhitespace) {
			if (characters[i] != ' ' && characters[i] != '\t' &&
			    characters[i] != '\n' && characters[i] != '\r' &&
			    characters[i] != '\f')
				@throw [OFInvalidFormatException exception];
			if (of_ascii_isspace(characters[i]))
				continue;

			@throw [OFInvalidFormatException exception];
			continue;
		}

		if (characters[i] >= '0' && characters[i] <= '9') {
			newValue = (value << 4) | (characters[i] - '0');
			foundValue = true;
		} else if (characters[i] >= 'A' && characters[i] <= 'F') {
			newValue = (value << 4) | (characters[i] - 'A' + 10);
			foundValue = true;
		} else if (characters[i] >= 'a' && characters[i] <= 'f') {
			newValue = (value << 4) | (characters[i] - 'a' + 10);
			foundValue = true;
		} else if (characters[i] == 'h' || characters[i] == ' ' ||
		    characters[i] == '\t' || characters[i] == '\n' ||
		} else if (characters[i] == 'h' ||
		    of_ascii_isspace(characters[i])) {
		    characters[i] == '\r' || characters[i] == '\f') {
			expectWhitespace = true;
			continue;
		} else
			@throw [OFInvalidFormatException exception];

		if (newValue < value)
			@throw [OFOutOfRangeException exception];
2469
2470
2471
2472
2473
2474
2475
2476

2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495




2496
2497
2498
2499
2500
2501
2502
2503

2504
2505
2506
2507
2508
2509
2510
2460
2461
2462
2463
2464
2465
2466

2467


2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480




2481
2482
2483
2484

2485
2486
2487
2488



2489
2490
2491
2492
2493
2494
2495
2496







-
+
-
-













-
-
-
-
+
+
+
+
-




-
-
-
+







{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *characters = [self characters];
	size_t i = 0, length = [self length];
	uintmax_t value = 0;
	bool expectWhitespace = false;

	while (length > 0 && (*characters == ' ' || *characters == '\t' ||
	while (length > 0 && of_ascii_isspace(*characters)) {
	    *characters == '\n' || *characters == '\r' ||
	    *characters == '\f')) {
		characters++;
		length--;
	}

	if (length == 0) {
		objc_autoreleasePoolPop(pool);
		return 0;
	}

	for (; i < length; i++) {
		uintmax_t newValue;

		if (expectWhitespace) {
			if (characters[i] != ' ' && characters[i] != '\t' &&
			    characters[i] != '\n' && characters[i] != '\r' &&
			    characters[i] != '\f')
				@throw [OFInvalidFormatException exception];
			if (of_ascii_isspace(characters[i]))
				continue;

			@throw [OFInvalidFormatException exception];
			continue;
		}

		if (characters[i] >= '0' && characters[i] <= '7')
			newValue = (value << 3) | (characters[i] - '0');
		else if (characters[i] == ' ' || characters[i] == '\t' ||
		    characters[i] == '\n' || characters[i] == '\r' ||
		    characters[i] == '\f') {
		else if (of_ascii_isspace(characters[i])) {
			expectWhitespace = true;
			continue;
		} else
			@throw [OFInvalidFormatException exception];

		if (newValue < value)
			@throw [OFOutOfRangeException exception];
2543
2544
2545
2546
2547
2548
2549
2550

2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565

2566
2567
2568
2569
2570
2571
2572
2529
2530
2531
2532
2533
2534
2535

2536

2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547



2548
2549
2550
2551
2552
2553
2554
2555







-
+
-











-
-
-
+







	const char *UTF8String = [[self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint] UTF8String];
#endif
	char *endPointer = NULL;
	float value;

	while (*UTF8String == ' ' || *UTF8String == '\t' ||
	while (of_ascii_isspace(*UTF8String))
	    *UTF8String == '\n' || *UTF8String == '\r' || *UTF8String == '\f')
		UTF8String++;

#ifdef HAVE_STRTOF_L
	value = strtof_l(UTF8String, &endPointer, cLocale);
#else
	value = strtof(UTF8String, &endPointer);
#endif

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
		for (; *endPointer != '\0'; endPointer++)
			if (*endPointer != ' ' && *endPointer != '\t' &&
			    *endPointer != '\n' && *endPointer != '\r' &&
			    *endPointer != '\f')
			if (!of_ascii_isspace(*endPointer))
				@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);

	return value;
}

2596
2597
2598
2599
2600
2601
2602
2603

2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618

2619
2620
2621
2622
2623
2624
2625
2579
2580
2581
2582
2583
2584
2585

2586

2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597



2598
2599
2600
2601
2602
2603
2604
2605







-
+
-











-
-
-
+







	const char *UTF8String = [[self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint] UTF8String];
#endif
	char *endPointer = NULL;
	double value;

	while (*UTF8String == ' ' || *UTF8String == '\t' ||
	while (of_ascii_isspace(*UTF8String))
	    *UTF8String == '\n' || *UTF8String == '\r' || *UTF8String == '\f')
		UTF8String++;

#ifdef HAVE_STRTOD_L
	value = strtod_l(UTF8String, &endPointer, cLocale);
#else
	value = strtod(UTF8String, &endPointer);
#endif

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
		for (; *endPointer != '\0'; endPointer++)
			if (*endPointer != ' ' && *endPointer != '\t' &&
			    *endPointer != '\n' && *endPointer != '\r' &&
			    *endPointer != '\f')
			if (!of_ascii_isspace(*endPointer))
				@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);

	return value;
}