ObjFW  Diff

Differences From Artifact [77195aa3b1]:

To Artifact [68a16bb73e]:


2342
2343
2344
2345
2346
2347
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




2395
2396
2397
2398
2399
2400































2401
2402
2403
2404
2405
2406
2407
2342
2343
2344
2345
2346
2347
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
2395
2396
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
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483







-
-
+
+

+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
-
+

-
-
+


-
+
+

+
+
-
-
-
+
+
+
+
+
+

-
-
+
+

+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	return [self longLongValueWithBase: 10];
}

- (long long)longLongValueWithBase: (int)base
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = self.UTF8String;
	char *endPointer = NULL;
	long long value;
	bool negative = false;
	long long value = 0;

	while (of_ascii_isspace(*UTF8String))
		UTF8String++;
	errno = 0;
	value = strtoll(UTF8String, &endPointer, base);

	if ((value == LLONG_MIN || value == LLONG_MAX) && errno == ERANGE)
		@throw [OFOutOfRangeException exception];

	switch (*UTF8String) {
	case '-':
		negative = true;
	case '+':
		UTF8String++;
	}

	if (UTF8String[0] == '0') {
		if (UTF8String[1] == 'x') {
			if (base == 0)
				base = 16;

			if (base != 16 || UTF8String[2] == '\0')
				@throw [OFInvalidFormatException exception];

			UTF8String += 2;
		} else {
			if (base == 0)
				base = 8;
	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
		for (; *endPointer != '\0'; endPointer++)
			/* Use isspace since strtoll uses the same. */
			if (!isspace((unsigned char)*endPointer))
				@throw [OFInvalidFormatException exception];

			UTF8String++;
		}
	}

	while (*UTF8String != '\0') {
		unsigned char c = of_ascii_toupper(*UTF8String++);

		if (c >= '0' && c <= '9')
			c -= '0';
		else if (c >= 'A' && c <= 'Z')
			c -= ('A' - 10);
		else if (of_ascii_isspace(c)) {
			while (*UTF8String != '\0')
				if (!of_ascii_isspace(*UTF8String++))
					@throw [OFInvalidFormatException
					    exception];

			break;
		} else
			@throw [OFInvalidFormatException exception];

		if (c >= base)
			@throw [OFInvalidFormatException exception];

		if (LLONG_MAX / base < value || LLONG_MAX - (value * base) < c)
			@throw [OFOutOfRangeException exception];

		value = (value * base) + c;
	}

	if (negative)
		value *= -1;

	objc_autoreleasePoolPop(pool);

	return value;
}

- (unsigned long long)unsignedLongLongValue
{
	return [self unsignedLongLongValueWithBase: 10];
}

- (unsigned long long)unsignedLongLongValueWithBase: (int)base
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = self.UTF8String;
	char *endPointer = NULL;
	unsigned long long value;
	unsigned long long value = 0;

	/* Use isspace since strtoull uses the same. */
	while (isspace((unsigned char)*UTF8String))
	while (of_ascii_isspace(*UTF8String))
		UTF8String++;

	if (*UTF8String == '-')
	switch (*UTF8String) {
	case '-':
		@throw [OFInvalidFormatException exception];
	case '+':
		UTF8String++;

	errno = 0;
	value = strtoull(UTF8String, &endPointer, base);
	}

	if (UTF8String[0] == '0') {
		if (UTF8String[1] == 'x') {
			if (base == 0)
				base = 16;

	if (value == ULLONG_MAX && errno == ERANGE)
		@throw [OFOutOfRangeException exception];
			if (base != 16 || UTF8String[2] == '\0')
				@throw [OFInvalidFormatException exception];

			UTF8String += 2;
		} else {
			if (base == 0)
				base = 8;
	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
		for (; *endPointer != '\0'; endPointer++)
			/* Use isspace since strtoull uses the same. */
			if (!isspace((unsigned char)*endPointer))
				@throw [OFInvalidFormatException exception];

			UTF8String++;
		}
	}

	while (*UTF8String != '\0') {
		unsigned char c = of_ascii_toupper(*UTF8String++);

		if (c >= '0' && c <= '9')
			c -= '0';
		else if (c >= 'A' && c <= 'Z')
			c -= ('A' - 10);
		else if (of_ascii_isspace(c)) {
			while (*UTF8String != '\0')
				if (!of_ascii_isspace(*UTF8String++))
					@throw [OFInvalidFormatException
					    exception];

			break;
		} else
			@throw [OFInvalidFormatException exception];

		if (c >= base)
			@throw [OFInvalidFormatException exception];

		if (ULLONG_MAX / base < value ||
		    ULLONG_MAX - (value * base) < c)
			@throw [OFOutOfRangeException exception];

		value = (value * base) + c;
	}

	objc_autoreleasePoolPop(pool);

	return value;
}

- (float)floatValue