ObjFW  Diff

Differences From Artifact [9224bd11b0]:

To Artifact [77cf5c9b5c]:


271
272
273
274
275
276
277
278

279
280

281
282
283

284
285
286

287
288
289
290

291
292

293
294

295
296

297
298
299
300


301
302
303


304
305
306
307
308
309
310
271
272
273
274
275
276
277

278
279

280
281
282

283
284
285

286
287
288
289

290
291

292
293

294
295

296
297
298


299
300
301


302
303
304
305
306
307
308
309
310







-
+

-
+


-
+


-
+



-
+

-
+

-
+

-
+


-
-
+
+

-
-
+
+








@implementation OFString
+ string
{
	return [[[self alloc] init] autorelease];
}

+ stringWithCString: (const char*)string
+ stringWithCString: (const char*)cString
{
	return [[[self alloc] initWithCString: string] autorelease];
	return [[[self alloc] initWithCString: cString] autorelease];
}

+ stringWithCString: (const char*)string
+ stringWithCString: (const char*)cString
	   encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithCString: string
	return [[[self alloc] initWithCString: cString
				     encoding: encoding] autorelease];
}

+ stringWithCString: (const char*)string
+ stringWithCString: (const char*)cString
	   encoding: (of_string_encoding_t)encoding
	     length: (size_t)length
	     length: (size_t)cStringLength
{
	return [[[self alloc] initWithCString: string
	return [[[self alloc] initWithCString: cString
				     encoding: encoding
				       length: length] autorelease];
				       length: cStringLength] autorelease];
}

+ stringWithCString: (const char*)string
	     length: (size_t)length
+ stringWithCString: (const char*)cString
	     length: (size_t)cStringLength
{
	return [[[self alloc] initWithCString: string
				       length: length] autorelease];
	return [[[self alloc] initWithCString: cString
				       length: cStringLength] autorelease];
}

+ stringWithString: (OFString*)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

418
419
420
421
422
423
424
425
426


427
428
429
430
431
432
433
434
435

436
437

438
439

440
441
442

443
444
445

446
447

448
449
450

451
452

453
454
455
456
457
458
459
460
461
462
463



464
465
466
467
468
469
470


471
472
473

474
475
476
477
478
479
480
481
482
483


484
485
486
487
488
489

490
491
492
493
494


495
496
497
498
499
500

501
502
503
504
505
506
507
508




509
510

511
512
513
514

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

531
532
533
534
535
536


537
538
539
540

541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556



557
558

559
560
561
562

563
564
565
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
606

607
608

609
610
611
612
613
614
615
418
419
420
421
422
423
424


425
426
427
428
429
430
431
432
433
434

435
436

437
438

439
440
441

442
443
444

445
446

447
448
449

450
451

452
453
454
455
456
457
458
459
460



461
462
463
464
465
466
467
468


469
470
471
472

473
474
475
476
477
478
479
480
481


482
483
484
485
486
487
488

489
490
491
492


493
494
495
496
497
498
499

500
501
502
503
504
505



506
507
508
509
510

511
512
513
514

515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

531
532
533
534
535


536
537
538
539
540

541
542
543
544
545
546
547
548
549
550
551
552
553
554



555
556
557
558

559
560
561
562

563
564
565
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
606

607
608

609
610
611
612
613
614
615
616







-
-
+
+








-
+

-
+

-
+


-
+


-
+

-
+


-
+

-
+








-
-
-
+
+
+





-
-
+
+


-
+








-
-
+
+





-
+



-
-
+
+





-
+





-
-
-
+
+
+
+

-
+



-
+















-
+




-
-
+
+



-
+













-
-
-
+
+
+

-
+



-
+








-
-
+
+

-
+

-
+













-
+

-
+







-
+


-
+


-
+

-
+







{
	self = [super init];

	@try {
		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		s->string = [self allocMemoryWithSize: 1];
		s->string[0] = '\0';
		s->cString = [self allocMemoryWithSize: 1];
		s->cString[0] = '\0';
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithCString: (const char*)string
- initWithCString: (const char*)cString
{
	return [self initWithCString: string
	return [self initWithCString: cString
			    encoding: OF_STRING_ENCODING_UTF_8
			      length: strlen(string)];
			      length: strlen(cString)];
}

- initWithCString: (const char*)string
- initWithCString: (const char*)cString
	 encoding: (of_string_encoding_t)encoding
{
	return [self initWithCString: string
	return [self initWithCString: cString
			    encoding: encoding
			      length: strlen(string)];
			      length: strlen(cString)];
}

- initWithCString: (const char*)string
- initWithCString: (const char*)cString
	 encoding: (of_string_encoding_t)encoding
	   length: (size_t)length
	   length: (size_t)cStringLength
{
	self = [super init];

	@try {
		size_t i, j;
		const uint16_t *table;

		if (encoding == OF_STRING_ENCODING_UTF_8 &&
		    length >= 3 && !memcmp(string, "\xEF\xBB\xBF", 3)) {
			string += 3;
			length -= 3;
		    cStringLength >= 3 && !memcmp(cString, "\xEF\xBB\xBF", 3)) {
			cString += 3;
			cStringLength -= 3;
		}

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		s->string = [self allocMemoryWithSize: length + 1];
		s->length = length;
		s->cString = [self allocMemoryWithSize: cStringLength + 1];
		s->cStringLength = cStringLength;

		if (encoding == OF_STRING_ENCODING_UTF_8) {
			switch (of_string_check_utf8(string, length)) {
			switch (of_string_check_utf8(cString, cStringLength)) {
			case 1:
				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			memcpy(s->string, string, length);
			s->string[length] = 0;
			memcpy(s->cString, cString, cStringLength);
			s->cString[cStringLength] = 0;

			return self;
		}

		if (encoding == OF_STRING_ENCODING_ISO_8859_1) {
			for (i = j = 0; i < length; i++) {
			for (i = j = 0; i < cStringLength; i++) {
				char buffer[4];
				size_t bytes;

				if (!(string[i] & 0x80)) {
					s->string[j++] = string[i];
				if (!(cString[i] & 0x80)) {
					s->cString[j++] = cString[i];
					continue;
				}

				s->isUTF8 = YES;
				bytes = of_string_unicode_to_utf8(
				    (uint8_t)string[i], buffer);
				    (uint8_t)cString[i], buffer);

				if (bytes == 0)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				s->length += bytes - 1;
				s->string = [self resizeMemory: s->string
							toSize: s->length + 1];
				s->cStringLength += bytes - 1;
				s->cString = [self
				    resizeMemory: s->cString
					  toSize: s->cStringLength + 1];

				memcpy(s->string + j, buffer, bytes);
				memcpy(s->cString + j, buffer, bytes);
				j += bytes;
			}

			s->string[s->length] = 0;
			s->cString[s->cStringLength] = 0;

			return self;
		}

		switch (encoding) {
		case OF_STRING_ENCODING_ISO_8859_15:
			table = of_iso_8859_15;
			break;
		case OF_STRING_ENCODING_WINDOWS_1252:
			table = of_windows_1252;
			break;
		default:
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		for (i = j = 0; i < length; i++) {
		for (i = j = 0; i < cStringLength; i++) {
			char buffer[4];
			of_unichar_t character;
			size_t characterBytes;

			if (!(string[i] & 0x80)) {
				s->string[j++] = string[i];
			if (!(cString[i] & 0x80)) {
				s->cString[j++] = cString[i];
				continue;
			}

			character = table[(uint8_t)string[i]];
			character = table[(uint8_t)cString[i]];

			if (character == 0xFFFD)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

			s->isUTF8 = YES;
			characterBytes = of_string_unicode_to_utf8(character,
			    buffer);

			if (characterBytes == 0)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

			s->length += characterBytes - 1;
			s->string = [self resizeMemory: s->string
						toSize: s->length + 1];
			s->cStringLength += characterBytes - 1;
			s->cString = [self resizeMemory: s->cString
						 toSize: s->cStringLength + 1];

			memcpy(s->string + j, buffer, characterBytes);
			memcpy(s->cString + j, buffer, characterBytes);
			j += characterBytes;
		}

		s->string[s->length] = 0;
		s->cString[s->cStringLength] = 0;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithCString: (const char*)string
	   length: (size_t)length
- initWithCString: (const char*)cString
	   length: (size_t)cStringLength
{
	return [self initWithCString: string
	return [self initWithCString: cString
			    encoding: OF_STRING_ENCODING_UTF_8
			      length: length];
			      length: cStringLength];
}

- initWithString: (OFString*)string
{
	self = [super init];

	@try {
		const char *cString;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		cString = [string cString];
		s->length = [string cStringLength];
		s->cStringLength = [string cStringLength];

		switch (of_string_check_utf8(cString, s->length)) {
		switch (of_string_check_utf8(cString, s->cStringLength)) {
		case 1:
			s->isUTF8 = YES;
			break;
		case -1:;
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		if ((s->string = strdup(cString)) == NULL)
		if ((s->cString = strdup(cString)) == NULL)
			@throw [OFOutOfMemoryException
			     newWithClass: isa
			    requestedSize: s->length + 1];
			    requestedSize: s->cStringLength + 1];

		@try {
			[self addMemoryToPool: s->string];
			[self addMemoryToPool: s->cString];
		} @catch (id e) {
			free(s->string);
			free(s->cString);
			@throw e;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

658
659
660
661
662
663
664
665
666


667
668
669
670
671
672
673
674
675
676

677
678
679
680

681
682

683
684
685
686
687
688

689
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
717
718
719
659
660
661
662
663
664
665


666
667
668
669
670
671
672
673
674
675
676

677
678
679
680

681
682

683
684
685
686
687
688

689
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
717
718
719
720







-
-
+
+









-
+



-
+

-
+





-
+

-
+





-
+

-
+









-
+


-
-
+
+







			length--;
		} else if (byteOrder != OF_ENDIANESS_NATIVE)
			swap = YES;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		s->length = length;
		s->string = [self allocMemoryWithSize: (length * 4) + 1];
		s->cStringLength = length;
		s->cString = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length; i++) {
			char buffer[4];
			size_t characterLen = of_string_unicode_to_utf8(
			    (swap ? of_bswap32(string[i]) : string[i]),
			    buffer);

			switch (characterLen) {
			case 1:
				s->string[j++] = buffer[0];
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->isUTF8 = YES;
				s->length++;
				s->cStringLength++;

				memcpy(s->string + j, buffer, 2);
				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->isUTF8 = YES;
				s->length += 2;
				s->cStringLength += 2;

				memcpy(s->string + j, buffer, 3);
				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->isUTF8 = YES;
				s->length += 3;
				s->cStringLength += 3;

				memcpy(s->string + j, buffer, 4);
				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}
		}

		s->string[j] = '\0';
		s->cString[j] = '\0';

		@try {
			s->string = [self resizeMemory: s->string
						toSize: s->length + 1];
			s->cString = [self resizeMemory: s->cString
						 toSize: s->cStringLength + 1];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only tried to make it smaller */
			[e release];
		}
	} @catch (id e) {
		[self release];
		@throw e;
764
765
766
767
768
769
770
771
772


773
774
775
776
777
778
779
765
766
767
768
769
770
771


772
773
774
775
776
777
778
779
780







-
-
+
+







			length--;
		} else if (byteOrder != OF_ENDIANESS_NATIVE)
			swap = YES;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		s->length = length;
		s->string = [self allocMemoryWithSize: (length * 4) + 1];
		s->cStringLength = length;
		s->cString = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length; i++) {
			char buffer[4];
			of_unichar_t character =
			    (swap ? of_bswap16(string[i]) : string[i]);
			size_t characterLen;

799
800
801
802
803
804
805
806

807
808
809
810

811
812

813
814
815
816
817
818

819
820

821
822
823
824
825
826

827
828

829
830
831
832
833
834
835
836
837
838

839
840
841
842


843
844
845
846
847
848
849
800
801
802
803
804
805
806

807
808
809
810

811
812

813
814
815
816
817
818

819
820

821
822
823
824
825
826

827
828

829
830
831
832
833
834
835
836
837
838

839
840
841


842
843
844
845
846
847
848
849
850







-
+



-
+

-
+





-
+

-
+





-
+

-
+









-
+


-
-
+
+







			}

			characterLen = of_string_unicode_to_utf8(
			    character, buffer);

			switch (characterLen) {
			case 1:
				s->string[j++] = buffer[0];
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->isUTF8 = YES;
				s->length++;
				s->cStringLength++;

				memcpy(s->string + j, buffer, 2);
				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->isUTF8 = YES;
				s->length += 2;
				s->cStringLength += 2;

				memcpy(s->string + j, buffer, 3);
				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->isUTF8 = YES;
				s->length += 3;
				s->cStringLength += 3;

				memcpy(s->string + j, buffer, 4);
				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}
		}

		s->string[j] = '\0';
		s->cString[j] = '\0';

		@try {
			s->string = [self resizeMemory: s->string
						toSize: s->length + 1];
			s->cString = [self resizeMemory: s->cString
						 toSize: s->cStringLength + 1];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only tried to make it smaller */
			[e release];
		}
	} @catch (id e) {
		[self release];
		@throw e;
867
868
869
870
871
872
873
874

875
876
877
878
879
880
881
882
883

884
885
886
887

888
889
890


891
892
893
894
895
896
897
898
899

900
901

902
903
904
905
906
907
908
868
869
870
871
872
873
874

875
876
877
878
879
880
881
882
883

884
885
886
887

888
889
890

891
892
893
894
895
896
897
898
899
900

901
902

903
904
905
906
907
908
909
910







-
+








-
+



-
+


-
+
+








-
+

-
+








- initWithFormat: (OFConstantString*)format
       arguments: (va_list)arguments
{
	self = [super init];

	@try {
		int length;
		int cStringLength;

		if (format == nil)
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		if ((length = of_vasprintf(&s->string, [format cString],
		if ((cStringLength = of_vasprintf(&s->cString, [format cString],
		    arguments)) == -1)
			@throw [OFInvalidFormatException newWithClass: isa];

		s->length = length;
		s->cStringLength = cStringLength;

		@try {
			switch (of_string_check_utf8(s->string, length)) {
			switch (of_string_check_utf8(s->cString,
			    cStringLength)) {
			case 1:
				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			[self addMemoryToPool: s->string];
			[self addMemoryToPool: s->cString];
		} @catch (id e) {
			free(s->string);
			free(s->cString);
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
924
925
926
927
928
929
930
931

932
933
934
935
936
937

938
939
940

941
942
943
944
945
946
947
948
949
950
951
952


953
954
955

956
957
958
959
960
961
962
963
964
965

966
967
968
969



970
971
972
973
974
975





976
977
978

979
980
981
982
983
984
985
926
927
928
929
930
931
932

933
934
935
936
937
938

939
940
941

942
943
944
945
946
947
948
949
950
951
952


953
954
955
956

957
958
959
960
961
962
963
964
965
966

967
968



969
970
971
972
973




974
975
976
977
978
979
980

981
982
983
984
985
986
987
988







-
+





-
+


-
+










-
-
+
+


-
+









-
+

-
-
-
+
+
+


-
-
-
-
+
+
+
+
+


-
+







- initWithPath: (OFString*)firstComponent
     arguments: (va_list)arguments
{
	self = [super init];

	@try {
		OFString *component;
		size_t i, length;
		size_t i, cStringLength;
		va_list argumentsCopy;

		s = [self allocMemoryWithSize: sizeof(*s)];
		memset(s, 0, sizeof(*s));

		s->length = [firstComponent cStringLength];
		s->cStringLength = [firstComponent cStringLength];

		switch (of_string_check_utf8([firstComponent cString],
		    s->length)) {
		    s->cStringLength)) {
		case 1:
			s->isUTF8 = YES;
			break;
		case -1:
			@throw [OFInvalidEncodingException newWithClass: isa];
		}

		/* Calculate length */
		va_copy(argumentsCopy, arguments);
		while ((component = va_arg(argumentsCopy, OFString*)) != nil) {
			length = [component cStringLength];
			s->length += 1 + length;
			cStringLength = [component cStringLength];
			s->cStringLength += 1 + cStringLength;

			switch (of_string_check_utf8([component cString],
			    length)) {
			    cStringLength)) {
			case 1:
				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}
		}

		s->string = [self allocMemoryWithSize: s->length + 1];
		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];

		length = [firstComponent cStringLength];
		memcpy(s->string, [firstComponent cString], length);
		i = length;
		cStringLength = [firstComponent cStringLength];
		memcpy(s->cString, [firstComponent cString], cStringLength);
		i = cStringLength;

		while ((component = va_arg(arguments, OFString*)) != nil) {
			length = [component cStringLength];
			s->string[i] = OF_PATH_DELIM;
			memcpy(s->string + i + 1, [component cString], length);
			i += 1 + length;
			cStringLength = [component cStringLength];
			s->cString[i] = OF_PATH_DELIM;
			memcpy(s->cString + i + 1, [component cString],
			    cStringLength);
			i += 1 + cStringLength;
		}

		s->string[i] = '\0';
		s->cString[i] = '\0';
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
1115
1116
1117
1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130

1131
1132

1133
1134
1135
1136
1137

1138
1139
1140
1141
1142
1143
1144
1145

1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165


1166
1167
1168
1169
1170
1171
1172
1173



1174
1175
1176



1177
1178

1179
1180
1181
1182
1183

1184
1185
1186
1187
1188
1189
1190
1191
1192
1193


1194
1195
1196
1197
1198
1199
1200

1201
1202

1203

1204
1205
1206



1207
1208

1209
1210
1211
1212
1213

1214
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227
1228




1229
1230
1231
1232
1233
1234
1235
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132

1133
1134

1135
1136
1137
1138
1139

1140
1141
1142
1143
1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166


1167
1168
1169
1170
1171
1172
1173
1174


1175
1176
1177
1178


1179
1180
1181
1182

1183
1184
1185
1186
1187

1188
1189
1190
1191
1192
1193
1194
1195
1196


1197
1198
1199
1200
1201
1202
1203
1204

1205
1206
1207
1208

1209
1210


1211
1212
1213
1214

1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227

1228
1229
1230
1231




1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242







-
+







-
+

-
+




-
+







-
+


















-
-
+
+






-
-
+
+
+

-
-
+
+
+

-
+




-
+








-
-
+
+






-
+


+
-
+

-
-
+
+
+

-
+




-
+







-
+



-
-
-
-
+
+
+
+







	}

	return self;
}

- (const char*)cString
{
	return s->string;
	return s->cString;
}

- (size_t)length
{
	/* FIXME: Maybe cache this in an ivar? */

	if (!s->isUTF8)
		return s->length;
		return s->cStringLength;

	return of_string_position_to_index(s->string, s->length);
	return of_string_position_to_index(s->cString, s->cStringLength);
}

- (size_t)cStringLength
{
	return s->length;
	return s->cStringLength;
}

- (BOOL)isEqual: (id)object
{
	if (![object isKindOfClass: [OFString class]])
		return NO;

	if (strcmp(s->string, [object cString]))
	if (strcmp(s->cString, [object cString]))
		return NO;

	return YES;
}

- copy
{
	return [self retain];
}

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

- (of_comparison_result_t)compare: (id)object
{
	OFString *otherString;
	size_t otherLen, minLen;
	int cmp;
	size_t otherCStringLength, minimumCStringLength;
	int compare;

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

	otherString = object;
	otherLen = [otherString cStringLength];
	minLen = (s->length > otherLen ? otherLen : s->length);
	otherCStringLength = [otherString cStringLength];
	minimumCStringLength = (s->cStringLength > otherCStringLength
	    ? otherCStringLength : s->cStringLength);

	if ((cmp = memcmp(s->string, [otherString cString], minLen)) == 0) {
		if (s->length > otherLen)
	if ((compare = memcmp(s->cString, [otherString cString],
	    minimumCStringLength)) == 0) {
		if (s->cStringLength > otherCStringLength)
			return OF_ORDERED_DESCENDING;
		if (s->length < otherLen)
		if (s->cStringLength < otherCStringLength)
			return OF_ORDERED_ASCENDING;
		return OF_ORDERED_SAME;
	}

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

- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString
{
	const char *otherCString;
	size_t i, j, otherLen, minLen;
	int cmp;
	size_t i, j, otherCStringLength, minimumCStringLength;
	int compare;

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

	otherCString = [otherString cString];
	otherLen = [otherString cStringLength];
	otherCStringLength = [otherString cStringLength];

	if (!s->isUTF8) {
		minimumCStringLength = (s->cStringLength > otherCStringLength
		minLen = (s->length > otherLen ? otherLen : s->length);
		    ? otherCStringLength : s->cStringLength);

		if ((cmp = memcasecmp(s->string, otherCString, minLen)) == 0) {
			if (s->length > otherLen)
		if ((compare = memcasecmp(s->cString, otherCString,
		    minimumCStringLength)) == 0) {
			if (s->cStringLength > otherCStringLength)
				return OF_ORDERED_DESCENDING;
			if (s->length < otherLen)
			if (s->cStringLength < otherCStringLength)
				return OF_ORDERED_ASCENDING;
			return OF_ORDERED_SAME;
		}

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

	i = j = 0;

	while (i < s->length && j < otherLen) {
	while (i < s->cStringLength && j < otherCStringLength) {
		of_unichar_t c1, c2;
		size_t l1, l2;

		l1 = of_string_utf8_to_unicode(s->string + i, s->length - i,
		    &c1);
		l2 = of_string_utf8_to_unicode(otherCString + j, otherLen - j,
		    &c2);
		l1 = of_string_utf8_to_unicode(s->cString + i,
		    s->cStringLength - i, &c1);
		l2 = of_string_utf8_to_unicode(otherCString + j,
		    otherCStringLength - j, &c2);

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

		if (c1 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
			of_unichar_t tc =
			    of_unicode_casefolding_table[c1 >> 8][c1 & 0xFF];
1251
1252
1253
1254
1255
1256
1257
1258

1259
1260

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273


1274
1275
1276
1277
1278
1279
1280
1258
1259
1260
1261
1262
1263
1264

1265
1266

1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278


1279
1280
1281
1282
1283
1284
1285
1286
1287







-
+

-
+











-
-
+
+







		if (c1 < c2)
			return OF_ORDERED_ASCENDING;

		i += l1;
		j += l2;
	}

	if (s->length - i > otherLen - j)
	if (s->cStringLength - i > otherCStringLength - j)
		return OF_ORDERED_DESCENDING;
	else if (s->length - i < otherLen - j)
	else if (s->cStringLength - i < otherCStringLength - j)
		return OF_ORDERED_ASCENDING;

	return OF_ORDERED_SAME;
}

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

	OF_HASH_INIT(hash);
	for (i = 0; i < s->length; i++)
		OF_HASH_ADD(hash, s->string[i]);
	for (i = 0; i < s->cStringLength; i++)
		OF_HASH_ADD(hash, s->cString[i]);
	OF_HASH_FINALIZE(hash);

	return hash;
}

- (OFString*)description
{
1304
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314

1315
1316
1317

1318
1319
1320


1321
1322

1323
1324
1325
1326


1327
1328
1329

1330
1331
1332
1333
1334
1335

1336
1337
1338

1339
1340
1341

1342
1343
1344
1345
1346



1347
1348
1349
1350
1351
1352
1353
1354

1355
1356
1357
1358



1359
1360

1361
1362
1363
1364
1365



1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379

1380
1381
1382

1383
1384
1385
1386


1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398




1399
1400
1401
1402
1403
1404
1405

1406
1407
1408

1409
1410
1411
1412
1413
1414
1415
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320

1321
1322
1323

1324
1325
1326

1327
1328
1329

1330
1331
1332


1333
1334
1335
1336

1337
1338
1339
1340
1341
1342

1343

1344

1345
1346
1347

1348
1349
1350



1351
1352
1353
1354
1355
1356
1357
1358
1359
1360

1361

1362


1363
1364
1365
1366

1367
1368
1369



1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382

1383

1384

1385
1386
1387

1388
1389
1390


1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401



1402
1403
1404
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414

1415
1416
1417
1418
1419
1420
1421
1422







-
+


-
+


-
+


-
+
+

-
+


-
-
+
+


-
+





-
+
-

-
+


-
+


-
-
-
+
+
+







-
+
-

-
-
+
+
+

-
+


-
-
-
+
+
+










-
+
-

-
+


-
+


-
-
+
+









-
-
-
+
+
+
+






-
+


-
+







	}

	return element;
}

- (of_unichar_t)characterAtIndex: (size_t)index
{
	of_unichar_t c;
	of_unichar_t character;

	if (!s->isUTF8) {
		if (index >= s->length)
		if (index >= s->cStringLength)
			@throw [OFOutOfRangeException newWithClass: isa];

		return s->string[index];
		return s->cString[index];
	}

	index = of_string_index_to_position(s->string, index, s->length);
	index = of_string_index_to_position(s->cString, index,
	    s->cStringLength);

	if (index >= s->length)
	if (index >= s->cStringLength)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (!of_string_utf8_to_unicode(s->string + index, s->length - index,
	    &c))
	if (!of_string_utf8_to_unicode(s->cString + index,
	    s->cStringLength - index, &character))
		@throw [OFInvalidEncodingException newWithClass: isa];

	return c;
	return character;
}

- (size_t)indexOfFirstOccurrenceOfString: (OFString*)string
{
	const char *cString = [string cString];
	size_t stringLen = [string cStringLength];
	size_t i, cStringLength = [string cStringLength];
	size_t i;

	if (stringLen == 0)
	if (cStringLength == 0)
		return 0;

	if (stringLen > s->length)
	if (cStringLength > s->cStringLength)
		return OF_INVALID_INDEX;

	for (i = 0; i <= s->length - stringLen; i++)
		if (!memcmp(s->string + i, cString, stringLen))
			return of_string_position_to_index(s->string, i);
	for (i = 0; i <= s->cStringLength - cStringLength; i++)
		if (!memcmp(s->cString + i, cString, cStringLength))
			return of_string_position_to_index(s->cString, i);

	return OF_INVALID_INDEX;
}

- (size_t)indexOfLastOccurrenceOfString: (OFString*)string
{
	const char *cString = [string cString];
	size_t stringLen = [string cStringLength];
	size_t i, cStringLength = [string cStringLength];
	size_t i;

	if (stringLen == 0)
		return of_string_position_to_index(s->string, s->length);
	if (cStringLength == 0)
		return of_string_position_to_index(s->cString,
		    s->cStringLength);

	if (stringLen > s->length)
	if (cStringLength > s->cStringLength)
		return OF_INVALID_INDEX;

	for (i = s->length - stringLen;; i--) {
		if (!memcmp(s->string + i, cString, stringLen))
			return of_string_position_to_index(s->string, i);
	for (i = s->cStringLength - cStringLength;; i--) {
		if (!memcmp(s->cString + i, cString, cStringLength))
			return of_string_position_to_index(s->cString, i);

		/* Did not match and we're at the last char */
		if (i == 0)
			return OF_INVALID_INDEX;
	}
}

- (BOOL)containsString: (OFString*)string
{
	const char *cString = [string cString];
	size_t stringLen = [string cStringLength];
	size_t i, cStringLength = [string cStringLength];
	size_t i;

	if (stringLen == 0)
	if (cStringLength == 0)
		return YES;

	if (stringLen > s->length)
	if (cStringLength > s->cStringLength)
		return NO;

	for (i = 0; i <= s->length - stringLen; i++)
		if (!memcmp(s->string + i, cString, stringLen))
	for (i = 0; i <= s->cStringLength - cStringLength; i++)
		if (!memcmp(s->cString + i, cString, cStringLength))
			return YES;

	return NO;
}

- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{
	if (s->isUTF8) {
		start = of_string_index_to_position(s->string, start,
		    s->length);
		end = of_string_index_to_position(s->string, end, s->length);
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if (end > s->length)
	if (end > s->cStringLength)
		@throw [OFOutOfRangeException newWithClass: isa];

	return [OFString stringWithCString: s->string + start
	return [OFString stringWithCString: s->cString + start
				    length: end - start];
}

- (OFString*)substringWithRange: (of_range_t)range
{
	return [self substringFromIndex: range.start
				toIndex: range.start + range.length];
1429
1430
1431
1432
1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500

1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516

1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534

1535
1536
1537

1538
1539
1540
1541
1542

1543
1544

1545
1546
1547
1548


1549
1550
1551
1552
1553
1554
1555
1556


1557
1558
1559
1560
1561
1562

1563
1564
1565
1566
1567
1568
1569
1570


1571
1572
1573

1574
1575

1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599

1600
1601
1602
1603
1604
1605

1606

1607

1608
1609

1610
1611

1612
1613

1614
1615

1616
1617
1618

1619
1620
1621
1622
1623
1624

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640

1641
1642
1643

1644
1645
1646
1647

1648

1649

1650
1651

1652
1653

1654
1655

1656
1657

1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672


1673
1674
1675
1676
1677

1678
1679

1680
1681
1682
1683

1684

1685

1686
1687

1688
1689
1690


1691
1692
1693

1694
1695

1696
1697

1698
1699

1700
1701
1702
1703

1704
1705

1706
1707

1708
1709
1710
1711
1712
1713
1714
1715
1716


1717
1718

1719
1720
1721
1722
1723
1724




1725
1726
1727

1728
1729
1730

1731
1732
1733


1734
1735
1736
1737
1738
1739
1740
1741



1742
1743
1744
1745
1746
1747



1748
1749
1750
1751
1752
1753
1754


1755
1756

1757
1758
1759
1760
1761
1762


1763
1764
1765


1766
1767
1768
1769
1770




1771
1772
1773

1774
1775
1776

1777
1778

1779
1780
1781
1782


1783
1784
1785
1786


1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803












1804
1805
1806
1807
1808
1809

1810
1811
1812

1813
1814
1815

1816
1817
1818

1819
1820
1821
1822
1823

1824
1825
1826
1827
1828
1829



1830
1831

1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846

1847
1848
1849
1850
1851
1852



1853
1854

1855
1856
1857
1858
1859
1860
1861
1436
1437
1438
1439
1440
1441
1442

1443
1444

1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457

1458
1459

1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472

1473
1474

1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487

1488
1489

1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502

1503
1504

1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519

1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532

1533
1534

1535
1536
1537

1538
1539
1540
1541
1542

1543
1544

1545
1546
1547


1548
1549
1550
1551
1552
1553
1554
1555


1556
1557
1558
1559
1560
1561
1562

1563
1564
1565
1566
1567
1568
1569


1570
1571
1572
1573

1574
1575

1576
1577
1578

1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595

1596
1597
1598
1599

1600
1601
1602
1603
1604
1605

1606
1607
1608

1609
1610

1611
1612

1613
1614

1615
1616

1617
1618
1619

1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641

1642
1643
1644

1645
1646
1647
1648

1649
1650
1651

1652
1653

1654
1655

1656
1657

1658
1659

1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673


1674
1675
1676
1677
1678
1679

1680
1681

1682
1683
1684
1685

1686
1687
1688

1689
1690

1691
1692


1693
1694
1695
1696

1697
1698

1699
1700

1701
1702

1703
1704
1705
1706

1707
1708

1709
1710

1711
1712
1713
1714
1715
1716
1717
1718


1719
1720
1721

1722
1723
1724




1725
1726
1727
1728
1729
1730

1731
1732
1733

1734
1735


1736
1737
1738
1739
1740
1741
1742



1743
1744
1745
1746
1747
1748



1749
1750
1751
1752
1753
1754
1755
1756


1757
1758
1759

1760
1761
1762
1763
1764


1765
1766
1767


1768
1769
1770




1771
1772
1773
1774
1775
1776

1777
1778
1779

1780
1781

1782
1783
1784


1785
1786
1787
1788


1789
1790
1791
1792
1793
1794
1795












1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812

1813
1814
1815

1816
1817
1818

1819
1820
1821

1822
1823
1824
1825
1826

1827
1828
1829
1830



1831
1832
1833
1834

1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853



1854
1855
1856
1857

1858
1859
1860
1861
1862
1863
1864
1865







-
+

-













-
+

-













-
+

-













-
+

-













-
+

-













-
+

-













-
+

-
+


-
+




-
+

-
+


-
-
+
+






-
-
+
+





-
+






-
-
+
+


-
+

-
+


-
+
















-
+



-
+





-
+

+
-
+

-
+

-
+

-
+

-
+


-
+





-
+















-
+


-
+



-
+

+
-
+

-
+

-
+

-
+

-
+













-
-
+
+




-
+

-
+



-
+

+
-
+

-
+

-
-
+
+


-
+

-
+

-
+

-
+



-
+

-
+

-
+







-
-
+
+

-
+


-
-
-
-
+
+
+
+


-
+


-
+

-
-
+
+





-
-
-
+
+
+



-
-
-
+
+
+





-
-
+
+

-
+




-
-
+
+

-
-
+
+

-
-
-
-
+
+
+
+


-
+


-
+

-
+


-
-
+
+


-
-
+
+





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





-
+


-
+


-
+


-
+




-
+



-
-
-
+
+
+

-
+














-
+



-
-
-
+
+
+

-
+







	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)stringByPrependingString: (OFString*)string
{
	OFMutableString *new;
	OFMutableString *new = [[string mutableCopy] autorelease];

	new = [OFMutableString stringWithString: string];
	[new appendString: self];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)uppercaseString
{
	OFMutableString *new;
	OFMutableString *new = [[self mutableCopy] autorelease];

	new = [OFMutableString stringWithString: self];
	[new upper];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)lowercaseString
{
	OFMutableString *new;
	OFMutableString *new = [[self mutableCopy] autorelease];

	new = [OFMutableString stringWithString: self];
	[new lower];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)stringByDeletingLeadingWhitespaces
{
	OFMutableString *new;
	OFMutableString *new = [[self mutableCopy] autorelease];

	new = [OFMutableString stringWithString: self];
	[new deleteLeadingWhitespaces];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)stringByDeletingTrailingWhitespaces
{
	OFMutableString *new;
	OFMutableString *new = [[self mutableCopy] autorelease];

	new = [OFMutableString stringWithString: self];
	[new deleteTrailingWhitespaces];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (OFString*)stringByDeletingLeadingAndTrailingWhitespaces
{
	OFMutableString *new;
	OFMutableString *new = [[self mutableCopy] autorelease];

	new = [OFMutableString stringWithString: self];
	[new deleteLeadingAndTrailingWhitespaces];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFString class];
	return new;
}

- (BOOL)hasPrefix: (OFString*)prefix
{
	size_t length = [prefix cStringLength];
	size_t cStringLength = [prefix cStringLength];

	if (length > s->length)
	if (cStringLength > s->cStringLength)
		return NO;

	return !memcmp(s->string, [prefix cString], length);
	return !memcmp(s->cString, [prefix cString], cStringLength);
}

- (BOOL)hasSuffix: (OFString*)suffix
{
	size_t length = [suffix cStringLength];
	size_t cStringLength = [suffix cStringLength];

	if (length > s->length)
	if (cStringLength > s->cStringLength)
		return NO;

	return !memcmp(s->string + (s->length - length), [suffix cString],
	    length);
	return !memcmp(s->cString + (s->cStringLength - cStringLength),
	    [suffix cString], cStringLength);
}

- (OFArray*)componentsSeparatedByString: (OFString*)delimiter
{
	OFAutoreleasePool *pool;
	OFMutableArray *array;
	const char *delim = [delimiter cString];
	size_t delimLen = [delimiter cStringLength];
	const char *cString = [delimiter cString];
	size_t cStringLength = [delimiter cStringLength];
	size_t i, last;

	array = [OFMutableArray array];
	pool = [[OFAutoreleasePool alloc] init];

	if (delimLen > s->length) {
	if (cStringLength > s->cStringLength) {
		[array addObject: [[self copy] autorelease]];
		[pool release];

		return array;
	}

	for (i = 0, last = 0; i <= s->length - delimLen; i++) {
		if (memcmp(s->string + i, delim, delimLen))
	for (i = 0, last = 0; i <= s->cStringLength - cStringLength; i++) {
		if (memcmp(s->cString + i, cString, cStringLength))
			continue;

		[array addObject: [OFString stringWithCString: s->string + last
		[array addObject: [OFString stringWithCString: s->cString + last
						       length: i - last]];
		i += delimLen - 1;
		i += cStringLength - 1;
		last = i + 1;
	}
	[array addObject: [OFString stringWithCString: s->string + last]];
	[array addObject: [OFString stringWithCString: s->cString + last]];

	[pool release];

	/*
	 * Class swizzle the array to be immutable. We declared the return type
	 * to be OFArray*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	array->isa = [OFArray class];
	return array;
}

- (OFArray*)pathComponents
{
	OFMutableArray *ret;
	OFAutoreleasePool *pool;
	size_t i, last = 0, pathLen = s->length;
	size_t i, last = 0, pathCStringLength = s->cStringLength;

	ret = [OFMutableArray array];

	if (pathLen == 0)
	if (pathCStringLength == 0)
		return ret;

	pool = [[OFAutoreleasePool alloc] init];

#ifndef _WIN32
	if (s->string[pathLen - 1] == OF_PATH_DELIM)
	if (s->cString[pathCStringLength - 1] == OF_PATH_DELIM)
#else
	if (s->cString[pathCStringLength - 1] == '/' ||
	if (s->string[pathLen - 1] == '/' || s->string[pathLen - 1] == '\\')
	    s->cString[pathCStringLength - 1] == '\\')
#endif
		pathLen--;
		pathCStringLength--;

	for (i = 0; i < pathLen; i++) {
	for (i = 0; i < pathCStringLength; i++) {
#ifndef _WIN32
		if (s->string[i] == OF_PATH_DELIM) {
		if (s->cString[i] == OF_PATH_DELIM) {
#else
		if (s->string[i] == '/' || s->string[i] == '\\') {
		if (s->cString[i] == '/' || s->cString[i] == '\\') {
#endif
			[ret addObject:
			    [OFString stringWithCString: s->string + last
			    [OFString stringWithCString: s->cString + last
						 length: i - last]];
			last = i + 1;
		}
	}

	[ret addObject: [OFString stringWithCString: s->string + last
	[ret addObject: [OFString stringWithCString: s->cString + last
					     length: i - last]];

	[pool release];

	/*
	 * Class swizzle the array to be immutable. We declared the return type
	 * to be OFArray*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFArray class];
	return ret;
}

- (OFString*)lastPathComponent
{
	size_t pathLen = s->length;
	size_t pathCStringLength = s->cStringLength;
	ssize_t i;

	if (pathLen == 0)
	if (pathCStringLength == 0)
		return @"";

#ifndef _WIN32
	if (s->string[pathLen - 1] == OF_PATH_DELIM)
	if (s->cString[pathCStringLength - 1] == OF_PATH_DELIM)
#else
	if (s->cString[pathCStringLength - 1] == '/' ||
	if (s->string[pathLen - 1] == '/' || s->string[pathLen - 1] == '\\')
	    s->cString[pathCStringLength - 1] == '\\')
#endif
		pathLen--;
		pathCStringLength--;

	for (i = pathLen - 1; i >= 0; i--) {
	for (i = pathCStringLength - 1; i >= 0; i--) {
#ifndef _WIN32
		if (s->string[i] == OF_PATH_DELIM) {
		if (s->cString[i] == OF_PATH_DELIM) {
#else
		if (s->string[i] == '/' || s->string[i] == '\\') {
		if (s->cString[i] == '/' || s->string[i] == '\\') {
#endif
			i++;
			break;
		}
	}

	/*
	 * Only one component, but the trailing delimiter might have been
	 * removed, so return a new string anyway.
	 */
	if (i < 0)
		i = 0;

	return [OFString stringWithCString: s->string + i
				    length: pathLen - i];
	return [OFString stringWithCString: s->cString + i
				    length: pathCStringLength - i];
}

- (OFString*)stringByDeletingLastPathComponent
{
	size_t i, pathLen = s->length;
	size_t i, pathCStringLength = s->cStringLength;

	if (pathLen == 0)
	if (pathCStringLength == 0)
		return @"";

#ifndef _WIN32
	if (s->string[pathLen - 1] == OF_PATH_DELIM)
	if (s->cString[pathCStringLength - 1] == OF_PATH_DELIM)
#else
	if (s->cString[pathCStringLength - 1] == '/' ||
	if (s->string[pathLen - 1] == '/' || s->string[pathLen - 1] == '\\')
	    s->cString[pathCStringLength - 1] == '\\')
#endif
		pathLen--;
		pathCStringLength--;

	if (pathLen == 0)
		return [OFString stringWithCString: s->string
	if (pathCStringLength == 0)
		return [OFString stringWithCString: s->cString
					    length: 1];

	for (i = pathLen - 1; i >= 1; i--)
	for (i = pathCStringLength - 1; i >= 1; i--)
#ifndef _WIN32
		if (s->string[i] == OF_PATH_DELIM)
		if (s->cString[i] == OF_PATH_DELIM)
#else
		if (s->string[i] == '/' || s->string[i] == '\\')
		if (s->cString[i] == '/' || s->cString[i] == '\\')
#endif
			return [OFString stringWithCString: s->string
			return [OFString stringWithCString: s->cString
						    length: i];

#ifndef _WIN32
	if (s->string[0] == OF_PATH_DELIM)
	if (s->cString[0] == OF_PATH_DELIM)
#else
	if (s->string[i] == '/' || s->string[i] == '\\')
	if (s->cString[0] == '/' || s->cString[0] == '\\')
#endif
		return [OFString stringWithCString: s->string
		return [OFString stringWithCString: s->cString
					    length: 1];

	return @".";
}

- (intmax_t)decimalValue
{
	const char *string = s->string;
	size_t length = s->length;
	const char *cString = s->cString;
	size_t cStringLength = s->cStringLength;
	int i = 0;
	intmax_t num = 0;
	intmax_t value = 0;
	BOOL expectWhitespace = NO;

	while (*string == ' ' || *string == '\t' || *string == '\n' ||
	    *string == '\r') {
		string++;
		length--;
	while (*cString == ' ' || *cString == '\t' || *cString == '\n' ||
	    *cString == '\r') {
		cString++;
		cStringLength--;
	}

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

	for (; i < length; i++) {
	for (; i < cStringLength; i++) {
		if (expectWhitespace) {
			if (string[i] != ' ' && string[i] != '\t' &&
			    string[i] != '\n' && string[i] != '\r')
			if (cString[i] != ' ' && cString[i] != '\t' &&
			    cString[i] != '\n' && cString[i] != '\r')
				@throw [OFInvalidFormatException
				    newWithClass: isa];
			continue;
		}

		if (string[i] >= '0' && string[i] <= '9') {
			if (INTMAX_MAX / 10 < num ||
			    INTMAX_MAX - num * 10 < string[i] - '0')
		if (cString[i] >= '0' && cString[i] <= '9') {
			if (INTMAX_MAX / 10 < value ||
			    INTMAX_MAX - value * 10 < cString[i] - '0')
				@throw [OFOutOfRangeException
				    newWithClass: isa];

			num = (num * 10) + (string[i] - '0');
		} else if (string[i] == ' ' || string[i] == '\t' ||
		    string[i] == '\n' || string[i] == '\r')
			value = (value * 10) + (cString[i] - '0');
		} else if (cString[i] == ' ' || cString[i] == '\t' ||
		    cString[i] == '\n' || cString[i] == '\r')
			expectWhitespace = YES;
		else
			@throw [OFInvalidFormatException newWithClass: isa];
	}

	if (string[0] == '-')
		num *= -1;
	if (cString[0] == '-')
		value *= -1;

	return num;
	return value;
}

- (uintmax_t)hexadecimalValue
{
	const char *string = s->string;
	size_t length = s->length;
	const char *cString = s->cString;
	size_t cStringLength = s->cStringLength;
	int i = 0;
	uintmax_t num = 0;
	BOOL expectWhitespace = NO, gotNumber = NO;
	uintmax_t value = 0;
	BOOL expectWhitespace = NO, foundValue = NO;

	while (*string == ' ' || *string == '\t' || *string == '\n' ||
	    *string == '\r') {
		string++;
		length--;
	while (*cString == ' ' || *cString == '\t' || *cString == '\n' ||
	    *cString == '\r') {
		cString++;
		cStringLength--;
	}

	if (length == 0)
	if (cStringLength == 0)
		return 0;

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

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

		if (expectWhitespace) {
			if (string[i] != ' ' && string[i] != '\t' &&
			    string[i] != '\n' && string[i] != '\r')
			if (cString[i] != ' ' && cString[i] != '\t' &&
			    cString[i] != '\n' && cString[i] != '\r')
				@throw [OFInvalidFormatException
				    newWithClass: isa];
			continue;
		}

		if (string[i] >= '0' && string[i] <= '9') {
			newNum = (num << 4) | (string[i] - '0');
			gotNumber = YES;
		} else if (string[i] >= 'A' && string[i] <= 'F') {
			newNum = (num << 4) | (string[i] - 'A' + 10);
			gotNumber = YES;
		} else if (string[i] >= 'a' && string[i] <= 'f') {
			newNum = (num << 4) | (string[i] - 'a' + 10);
			gotNumber = YES;
		} else if (string[i] == 'h' || string[i] == ' ' ||
		    string[i] == '\t' || string[i] == '\n' ||
		    string[i] == '\r') {
		if (cString[i] >= '0' && cString[i] <= '9') {
			newValue = (value << 4) | (cString[i] - '0');
			foundValue = YES;
		} else if (cString[i] >= 'A' && cString[i] <= 'F') {
			newValue = (value << 4) | (cString[i] - 'A' + 10);
			foundValue = YES;
		} else if (cString[i] >= 'a' && cString[i] <= 'f') {
			newValue = (value << 4) | (cString[i] - 'a' + 10);
			foundValue = YES;
		} else if (cString[i] == 'h' || cString[i] == ' ' ||
		    cString[i] == '\t' || cString[i] == '\n' ||
		    cString[i] == '\r') {
			expectWhitespace = YES;
			continue;
		} else
			@throw [OFInvalidFormatException newWithClass: isa];

		if (newNum < num)
		if (newValue < value)
			@throw [OFOutOfRangeException newWithClass: isa];

		num = newNum;
		value = newValue;
	}

	if (!gotNumber)
	if (!foundValue)
		@throw [OFInvalidFormatException newWithClass: isa];

	return num;
	return value;
}

- (float)floatValue
{
	const char *string = s->string;
	const char *cString = s->cString;
	char *endPointer = NULL;
	float value;

	while (*string == ' ' || *string == '\t' || *string == '\n' ||
	    *string == '\r')
		string++;
	while (*cString == ' ' || *cString == '\t' || *cString == '\n' ||
	    *cString == '\r')
		cString++;

	value = strtof(string, &endPointer);
	value = strtof(cString, &endPointer);

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

	return value;
}

- (double)doubleValue
{
	const char *string = s->string;
	const char *cString = s->cString;
	char *endPointer = NULL;
	double value;

	while (*string == ' ' || *string == '\t' || *string == '\n' ||
	    *string == '\r')
		string++;
	while (*cString == ' ' || *cString == '\t' || *cString == '\n' ||
	    *cString == '\r')
		cString++;

	value = strtod(string, &endPointer);
	value = strtod(cString, &endPointer);

	/* Check if there are any invalid chars left */
	if (endPointer != NULL)
		for (; *endPointer != '\0'; endPointer++)
			if (*endPointer != ' ' && *endPointer != '\t' &&
			    *endPointer != '\n' && *endPointer != '\r')
				@throw [OFInvalidFormatException
1874
1875
1876
1877
1878
1879
1880
1881

1882
1883
1884
1885
1886


1887
1888
1889
1890
1891
1892
1893
1878
1879
1880
1881
1882
1883
1884

1885
1886
1887
1888


1889
1890
1891
1892
1893
1894
1895
1896
1897







-
+



-
-
+
+







				  withSize: sizeof(of_unichar_t)];

	i = 0;
	j = 0;

	ret[j++] = 0xFEFF;

	while (i < s->length) {
	while (i < s->cStringLength) {
		of_unichar_t c;
		size_t cLen;

		cLen = of_string_utf8_to_unicode(s->string + i, s->length - i,
		    &c);
		cLen = of_string_utf8_to_unicode(s->cString + i,
		    s->cStringLength - i, &c);

		if (cLen == 0 || c > 0x10FFFF)
			@throw [OFInvalidEncodingException newWithClass: isa];

		ret[j++] = c;
		i += cLen;
	}