ObjFW  Diff

Differences From Artifact [b097e022e5]:

To Artifact [dcfcc7e490]:


24
25
26
27
28
29
30

31
32
33
34
35
36
37

#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import "asprintf.h"


extern const uint16_t of_iso_8859_15[256];
extern const uint16_t of_windows_1252[256];

/* References for static linking */
void _references_to_categories_of_OFString()
{







>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import "asprintf.h"
#import "unicode.h"

extern const uint16_t of_iso_8859_15[256];
extern const uint16_t of_windows_1252[256];

/* References for static linking */
void _references_to_categories_of_OFString()
{
566
567
568
569
570
571
572



























573
574
575
576
577
578
579
580

581




582


583


584


585



586


587


588

589
590
591

592
593


594
595

596
597
598


599
600
601
602
603
604
605
{
	return [[OFMutableString alloc] initWithString: self];
}

- (of_comparison_result_t)compare: (OFString*)str
{
	int cmp;




























	if (![str isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if ([str length] == [self length]) {
		if (length != [str cStringLength]) {
			if (length > [str cStringLength])

				return OF_ORDERED_DESCENDING;




			else


				return OF_ORDERED_ASCENDING;


		}






		if ((cmp = memcmp(string, [str cString], length)) == 0)


			return OF_ORDERED_SAME;




		if (cmp > 0)
			return OF_ORDERED_DESCENDING;
		else

			return OF_ORDERED_ASCENDING;
	}



	if ([self length] > [str length])

		return OF_ORDERED_DESCENDING;
	else
		return OF_ORDERED_ASCENDING;


}

- (uint32_t)hash
{
	uint32_t hash;
	size_t i;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
|
|
>
|
>
>
>
>
|
>
>
|
>
>
|
>
>

>
>
>
|
>
>
|
>
>
|
>
|

<
>

|
>
>
|
|
>

|

>
>







567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637

638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
{
	return [[OFMutableString alloc] initWithString: self];
}

- (of_comparison_result_t)compare: (OFString*)str
{
	int cmp;
	size_t str_len, min_len;

	if (![str isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	str_len = [str cStringLength];
	min_len = (length > str_len ? str_len : length);

	if ((cmp = memcmp(string, [str cString], min_len)) == 0) {
		if (length > str_len)
			return OF_ORDERED_DESCENDING;
		if (length < str_len)
			return OF_ORDERED_ASCENDING;
		return OF_ORDERED_SAME;
	}

	if (cmp > 0)
		return OF_ORDERED_DESCENDING;
	else
		return OF_ORDERED_ASCENDING;
}

- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)str
{
	const char *str_cstr;
	size_t i, j, str_len;

	if (![str isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	str_cstr = [str cString];
	str_len = [str cStringLength];

	i = j = 0;

	while (i < length && j < str_len) {
		of_unichar_t c1, c2;
		size_t l1, l2;
		of_unichar_t tmp;

		l1 = of_string_utf8_to_unicode(string + i, length - i, &c1);
		l2 = of_string_utf8_to_unicode(str_cstr + j, str_len - j, &c2);

		if (l1 == 0 || l2 == 0 || c1 > 0x10FFFF || c2 > 0x10FFFF)
			@throw [OFInvalidEncodingException newWithClass: isa];

		if (c1 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
			tmp = of_unicode_casefolding_table[c1 >> 8][c1 & 0xFF];

			if (tmp != 0)
				c1 = tmp;
		}

		if (c2 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
			tmp = of_unicode_casefolding_table[c2 >> 8][c2 & 0xFF];

			if (tmp != 0)
				c2 = tmp;
		}

		if (c1 > c2)
			return OF_ORDERED_DESCENDING;

		if (c1 < c2)
			return OF_ORDERED_ASCENDING;

		i += l1;
		j += l2;
	}

	if (length - i > str_len - j)
		return OF_ORDERED_DESCENDING;
	else if (length - i < str_len - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;
}

- (uint32_t)hash
{
	uint32_t hash;
	size_t i;