ObjFW  Diff

Differences From Artifact [32973681cc]:

To Artifact [539d29c205]:

  • File src/OFString_UTF8.m — part of check-in [b7b33247d6] at 2016-08-29 00:05:29 on branch trunk — configure: Add --disable-unicode-tables option

    This is only useful for size-constrained systems and changes the
    behavior as follows:

    * Case-insensitive comparisons only work as expected for ASCII
    characters. This means that while a and A compare equal, ä and Ä do
    not.

    * -[OFMutableString {upper,lower}] and
    -[OFString {upper,lower}caseString] only work on ASCII characters;
    all other characters are left as they are. This means that the upper
    version of a is A, but the upper version of ä is still ä (and vice
    versa for lower). (user: js, size: 28512) [annotate] [blame] [check-ins using]


42
43
44
45
46
47
48
49
50







51
52
53
54
55
56
57
58
59
60
extern const of_char16_t of_windows_1252[128];
extern const of_char16_t of_codepage_437[128];

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		if (tolower((unsigned char)first[i]) >
		    tolower((unsigned char)second[i]))







			return OF_ORDERED_DESCENDING;
		if (tolower((unsigned char)first[i]) <
		    tolower((unsigned char)second[i]))
			return OF_ORDERED_ASCENDING;
	}

	return OF_ORDERED_SAME;
}

int







|
|
>
>
>
>
>
>
>

|
<







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
extern const of_char16_t of_windows_1252[128];
extern const of_char16_t of_codepage_437[128];

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		unsigned char f = first[i];
		unsigned char s = second[i];

		if (f <= 0x7F)
			f = toupper(f);
		if (s <= 0x7F)
			s = toupper(s);

		if (f > s)
			return OF_ORDERED_DESCENDING;
		if (f < s)

			return OF_ORDERED_ASCENDING;
	}

	return OF_ORDERED_SAME;
}

int
783
784
785
786
787
788
789

790

791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806

807
808
809
810
811
812
813

	if (![otherString isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException exception];

	otherCString = [otherString UTF8String];
	otherCStringLength = [otherString UTF8StringLength];


	if (!_s->isUTF8) {

		minimumCStringLength = (_s->cStringLength > otherCStringLength
		    ? otherCStringLength : _s->cStringLength);

		if ((compare = memcasecmp(_s->cString, otherCString,
		    minimumCStringLength)) == 0) {
			if (_s->cStringLength > otherCStringLength)
				return OF_ORDERED_DESCENDING;
			if (_s->cStringLength < otherCStringLength)
				return OF_ORDERED_ASCENDING;
			return OF_ORDERED_SAME;
		}

		if (compare > 0)
			return OF_ORDERED_DESCENDING;
		else
			return OF_ORDERED_ASCENDING;

	}

	i = j = 0;

	while (i < _s->cStringLength && j < otherCStringLength) {
		of_unichar_t c1, c2;
		ssize_t l1, l2;







>

>
















>







789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

	if (![otherString isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException exception];

	otherCString = [otherString UTF8String];
	otherCStringLength = [otherString UTF8StringLength];

#ifdef OF_HAVE_UNICODE_TABLES
	if (!_s->isUTF8) {
#endif
		minimumCStringLength = (_s->cStringLength > otherCStringLength
		    ? otherCStringLength : _s->cStringLength);

		if ((compare = memcasecmp(_s->cString, otherCString,
		    minimumCStringLength)) == 0) {
			if (_s->cStringLength > otherCStringLength)
				return OF_ORDERED_DESCENDING;
			if (_s->cStringLength < otherCStringLength)
				return OF_ORDERED_ASCENDING;
			return OF_ORDERED_SAME;
		}

		if (compare > 0)
			return OF_ORDERED_DESCENDING;
		else
			return OF_ORDERED_ASCENDING;
#ifdef OF_HAVE_UNICODE_TABLES
	}

	i = j = 0;

	while (i < _s->cStringLength && j < otherCStringLength) {
		of_unichar_t c1, c2;
		ssize_t l1, l2;
840
841
842
843
844
845
846

847
848
849
850
851
852
853
			return OF_ORDERED_DESCENDING;
		if (c1 < c2)
			return OF_ORDERED_ASCENDING;

		i += l1;
		j += l2;
	}


	if (_s->cStringLength - i > otherCStringLength - j)
		return OF_ORDERED_DESCENDING;
	else if (_s->cStringLength - i < otherCStringLength - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;







>







849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
			return OF_ORDERED_DESCENDING;
		if (c1 < c2)
			return OF_ORDERED_ASCENDING;

		i += l1;
		j += l2;
	}
#endif

	if (_s->cStringLength - i > otherCStringLength - j)
		return OF_ORDERED_DESCENDING;
	else if (_s->cStringLength - i < otherCStringLength - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;