ObjFW  Check-in [43c60ede3c]

Overview
Comment:Adjust OFString and OFDataArray to OFComparing protocol.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 43c60ede3c061c5ab3e4c6c8df7ff350340ddab55ea6d05dfcfaff9799360d50
User & Date: js on 2010-12-25 13:20:08
Other Links: manifest | tags
Context
2010-12-25
14:48
Fix broken snprintf test.
This was broken by 60aa070105ac.
check-in: 5ebb07a3e4 user: js tags: trunk
13:20
Adjust OFString and OFDataArray to OFComparing protocol. check-in: 43c60ede3c user: js tags: trunk
13:14
Add OFComparing protocol. check-in: 6b45991a6a user: js tags: trunk
Changes

Modified src/OFDataArray.m from [de22667a5c] to [4435fad97c].

246
247
248
249
250
251
252
253

254
255
256
257
258

259
260
261

262
263
264
265

266
267

268

269
270
271
272
273
274
275
246
247
248
249
250
251
252

253
254
255
256
257

258
259
260

261
262
263
264

265
266
267
268

269
270
271
272
273
274
275
276







-
+




-
+


-
+



-
+


+
-
+







		return NO;
	if (memcmp([(OFDataArray*)obj cArray], data, count * itemSize))
		return NO;

	return YES;
}

- (of_comparison_result_t)compare: (OFDataArray*)ary
- (of_comparison_result_t)compare: (id)obj
{
	int cmp;
	size_t ary_count, min_count;

	if (![ary isKindOfClass: [OFDataArray class]])
	if (![obj isKindOfClass: [OFDataArray class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
	if ([ary itemSize] != itemSize)
	if ([(OFDataArray*)obj itemSize] != itemSize)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	ary_count = [ary count];
	ary_count = [(OFDataArray*)obj count];
	min_count = (count > ary_count ? ary_count : count);

	if ((cmp = memcmp(data, [(OFDataArray*)obj cArray],
	if ((cmp = memcmp(data, [ary cArray], min_count * itemSize)) == 0) {
	    min_count * itemSize)) == 0) {
		if (count > ary_count)
			return OF_ORDERED_DESCENDING;
		if (count < ary_count)
			return OF_ORDERED_ASCENDING;
		return OF_ORDERED_SAME;
	}

Modified src/OFString.m from [e36cd47ab5] to [633e178038].

690
691
692
693
694
695
696
697

698
699
700
701
702

703
704
705
706

707
708
709

710
711
712
713
714
715
716
690
691
692
693
694
695
696

697
698
699
700
701

702
703
704
705

706
707
708

709
710
711
712
713
714
715
716







-
+




-
+



-
+


-
+







}

- mutableCopy
{
	return [[OFMutableString alloc] initWithString: self];
}

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

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

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

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