ObjFW  Diff

Differences From Artifact [fc29ab31f7]:

To Artifact [4a3385c744]:


209
210
211
212
213
214
215
216
217
218



219
220
221
222
223
224
225
209
210
211
212
213
214
215



216
217
218
219
220
221
222
223
224
225







-
-
-
+
+
+







		@throw [OFInvalidEncodingException exception];

	_s->hashed = false;

	if (lenNew == (size_t)lenOld)
		memcpy(_s->cString + index, buffer, lenNew);
	else if (lenNew > (size_t)lenOld) {
		_s->cString = (void *)[self resizeMemory: _s->cString
						    size: _s->cStringLength -
							  lenOld + lenNew + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength -
						  lenOld + lenNew + 1];

		memmove(_s->cString + index + lenNew,
		    _s->cString + index + lenOld,
		    _s->cStringLength - index - lenOld);
		memcpy(_s->cString + index, buffer, lenNew);

		_s->cStringLength -= lenOld;
238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252







-
+







		_s->cStringLength += lenNew;
		_s->cString[_s->cStringLength] = '\0';

		if (character >= 0x80)
			_s->isUTF8 = true;

		@try {
			_s->cString = (void *)[self
			_s->cString = [self
			    resizeMemory: _s->cString
				    size: _s->cStringLength + 1];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't really care, as we only made it smaller */
		}
	}
}
267
268
269
270
271
272
273
274
275
276



277
278
279
280
281
282
283
267
268
269
270
271
272
273



274
275
276
277
278
279
280
281
282
283







-
-
-
+
+
+







		_s->isUTF8 = true;
		break;
	case -1:
		@throw [OFInvalidEncodingException exception];
	}

	_s->hashed = false;
	_s->cString = (void *)[self resizeMemory: _s->cString
					    size: _s->cStringLength +
						  UTF8StringLength + 1];
	_s->cString = [self resizeMemory: _s->cString
				    size: _s->cStringLength +
					  UTF8StringLength + 1];
	memcpy(_s->cString + _s->cStringLength, UTF8String,
	    UTF8StringLength + 1);

	_s->cStringLength += UTF8StringLength;
	_s->length += length;
}

297
298
299
300
301
302
303
304
305
306



307
308
309
310
311
312
313
297
298
299
300
301
302
303



304
305
306
307
308
309
310
311
312
313







-
-
-
+
+
+







		_s->isUTF8 = true;
		break;
	case -1:
		@throw [OFInvalidEncodingException exception];
	}

	_s->hashed = false;
	_s->cString = (void *)[self resizeMemory: _s->cString
					    size: _s->cStringLength +
						  UTF8StringLength + 1];
	_s->cString = [self resizeMemory: _s->cString
				    size: _s->cStringLength +
					  UTF8StringLength + 1];
	memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength);

	_s->cStringLength += UTF8StringLength;
	_s->length += length;

	_s->cString[_s->cStringLength] = 0;
}
345
346
347
348
349
350
351
352
353
354



355
356
357
358
359
360
361
345
346
347
348
349
350
351



352
353
354
355
356
357
358
359
360
361







-
-
-
+
+
+








	if (string == nil)
		@throw [OFInvalidArgumentException exception];

	UTF8StringLength = [string UTF8StringLength];

	_s->hashed = false;
	_s->cString = (void *)[self resizeMemory: _s->cString
					    size: _s->cStringLength +
						  UTF8StringLength + 1];
	_s->cString = [self resizeMemory: _s->cString
				    size: _s->cStringLength +
					  UTF8StringLength + 1];
	memcpy(_s->cString + _s->cStringLength, [string UTF8String],
	    UTF8StringLength);

	_s->cStringLength += UTF8StringLength;
	_s->length += [string length];

	_s->cString[_s->cStringLength] = 0;
390
391
392
393
394
395
396
397
398
399


400
401
402
403
404
405
406
390
391
392
393
394
395
396



397
398
399
400
401
402
403
404
405







-
-
-
+
+








			j += len;
		}

		tmp[j] = '\0';

		_s->hashed = false;
		_s->cString = (void *)[self
		    resizeMemory: _s->cString
			    size: _s->cStringLength + j + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + j + 1];
		memcpy(_s->cString + _s->cStringLength, tmp, j + 1);

		_s->cStringLength += j;
		_s->length += length;

		if (isUTF8)
			_s->isUTF8 = true;
520
521
522
523
524
525
526
527
528


529
530
531
532
533
534
535
519
520
521
522
523
524
525


526
527
528
529
530
531
532
533
534







-
-
+
+








	if (_s->isUTF8)
		index = of_string_utf8_get_position(_s->cString, index,
		    _s->cStringLength);

	newCStringLength = _s->cStringLength + [string UTF8StringLength];
	_s->hashed = false;
	_s->cString = (void *)[self resizeMemory: _s->cString
					    size: newCStringLength + 1];
	_s->cString = [self resizeMemory: _s->cString
				    size: newCStringLength + 1];

	memmove(_s->cString + index + [string UTF8StringLength],
	    _s->cString + index, _s->cStringLength - index);
	memcpy(_s->cString + index, [string UTF8String],
	    [string UTF8StringLength]);
	_s->cString[newCStringLength] = '\0';

563
564
565
566
567
568
569
570
571
572


573
574
575
576
577
578
579
562
563
564
565
566
567
568



569
570
571
572
573
574
575
576
577







-
-
-
+
+







	    _s->cStringLength - end);
	_s->hashed = false;
	_s->length -= range.length;
	_s->cStringLength -= end - start;
	_s->cString[_s->cStringLength] = 0;

	@try {
		_s->cString = (void *)[self
		    resizeMemory: _s->cString
			    size: _s->cStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)replaceCharactersInRange: (of_range_t)range
		      withString: (OFString *)replacement
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
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







-
-
+
+












-
-
+
+







	 * memmove() the rest of the string to the end.
	 *
	 * We must not resize the string if the new string is smaller, because
	 * then we can't memmove() the rest of the string forward as the rest is
	 * lost due to the resize!
	 */
	if (newCStringLength > _s->cStringLength)
		_s->cString = (void *)[self resizeMemory: _s->cString
						    size: newCStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: newCStringLength + 1];

	memmove(_s->cString + start + [replacement UTF8StringLength],
	    _s->cString + end, _s->cStringLength - end);
	memcpy(_s->cString + start, [replacement UTF8String],
	    [replacement UTF8StringLength]);
	_s->cString[newCStringLength] = '\0';

	/*
	 * If the new string is smaller, we can safely resize it now as we're
	 * done with memmove().
	 */
	if (newCStringLength < _s->cStringLength)
		_s->cString = (void *)[self resizeMemory: _s->cString
						    size: newCStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: newCStringLength + 1];

	_s->cStringLength = newCStringLength;
	_s->length = newLength;

	if ([replacement isKindOfClass: [OFString_UTF8 class]] ||
	    [replacement isKindOfClass: [OFMutableString_UTF8 class]]) {
		if (((OFString_UTF8 *)replacement)->_s->isUTF8)
737
738
739
740
741
742
743
744
745
746


747
748
749
750
751
752
753
735
736
737
738
739
740
741



742
743
744
745
746
747
748
749
750







-
-
-
+
+







	_s->cStringLength -= i;
	_s->length -= i;

	memmove(_s->cString, _s->cString + i, _s->cStringLength);
	_s->cString[_s->cStringLength] = '\0';

	@try {
		_s->cString = (void *)[self
		    resizeMemory: _s->cString
			    size: _s->cStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)deleteTrailingWhitespaces
{
765
766
767
768
769
770
771
772
773
774


775
776
777
778
779
780
781
762
763
764
765
766
767
768



769
770
771
772
773
774
775
776
777







-
-
-
+
+







		d++;
	}

	_s->cStringLength -= d;
	_s->length -= d;

	@try {
		_s->cString = (void *)[self
		    resizeMemory: _s->cString
			    size: _s->cStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)deleteEnclosingWhitespaces
{
803
804
805
806
807
808
809
810
811
812


813
814
815
816
817
818
819
820
821
822
799
800
801
802
803
804
805



806
807
808
809
810
811
812
813
814
815
816
817







-
-
-
+
+










	_s->cStringLength -= i;
	_s->length -= i;

	memmove(_s->cString, _s->cString + i, _s->cStringLength);
	_s->cString[_s->cStringLength] = '\0';

	@try {
		_s->cString = (void *)[self
		    resizeMemory: _s->cString
			    size: _s->cStringLength + 1];
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)makeImmutable
{
	object_setClass(self, [OFString_UTF8 class]);
}
@end