︙ | | | ︙ | |
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
char *newCString;
if (!s->UTF8) {
assert(tableSize >= 1);
uint8_t *p = (uint8_t*)s->cString + s->cStringLength;
uint8_t t;
while (--p >= (uint8_t*)s->cString)
if ((t = table[0][*p]) != 0)
*p = t;
return;
}
|
>
>
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
char *newCString;
if (!s->UTF8) {
assert(tableSize >= 1);
uint8_t *p = (uint8_t*)s->cString + s->cStringLength;
uint8_t t;
s->hashed = NO;
while (--p >= (uint8_t*)s->cString)
if ((t = table[0][*p]) != 0)
*p = t;
return;
}
|
︙ | | | ︙ | |
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
}
assert(j == newCStringLength);
newCString[j] = 0;
[self freeMemory: unicodeString];
[self freeMemory: s->cString];
s->cString = newCString;
s->cStringLength = newCStringLength;
/*
* Even though cStringLength can change, length cannot, therefore no
* need to change it.
*/
|
>
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
}
assert(j == newCStringLength);
newCString[j] = 0;
[self freeMemory: unicodeString];
[self freeMemory: s->cString];
s->hashed = NO;
s->cString = newCString;
s->cStringLength = newCStringLength;
/*
* Even though cStringLength can change, length cannot, therefore no
* need to change it.
*/
|
︙ | | | ︙ | |
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
size_t length, oldLength;
if (s->UTF8)
index = of_string_index_to_position(s->cString, index,
s->cStringLength);
if (!(character & 0x80) && !(s->cString[index] & 0x80)) {
s->cString[index] = character;
return;
}
if ((length = of_string_unicode_to_utf8(character, buffer)) == 0)
@throw [OFInvalidEncodingException exceptionWithClass: isa];
if ((oldLength = of_string_utf8_to_unicode(s->cString + index,
s->cStringLength - index, &c)) == 0)
@throw [OFInvalidEncodingException exceptionWithClass: isa];
if (length == oldLength) {
memcpy(s->cString + index, buffer, length);
return;
}
if (length > oldLength) {
|
>
>
>
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
size_t length, oldLength;
if (s->UTF8)
index = of_string_index_to_position(s->cString, index,
s->cStringLength);
if (!(character & 0x80) && !(s->cString[index] & 0x80)) {
s->hashed = NO;
s->cString[index] = character;
return;
}
if ((length = of_string_unicode_to_utf8(character, buffer)) == 0)
@throw [OFInvalidEncodingException exceptionWithClass: isa];
if ((oldLength = of_string_utf8_to_unicode(s->cString + index,
s->cStringLength - index, &c)) == 0)
@throw [OFInvalidEncodingException exceptionWithClass: isa];
s->hashed = NO;
if (length == oldLength) {
memcpy(s->cString + index, buffer, length);
return;
}
if (length > oldLength) {
|
︙ | | | ︙ | |
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
case 1:
s->UTF8 = YES;
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1);
s->cStringLength += UTF8StringLength;
s->length += length;
|
>
|
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
case 1:
s->UTF8 = YES;
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1);
s->cStringLength += UTF8StringLength;
s->length += length;
|
︙ | | | ︙ | |
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
case 1:
s->UTF8 = YES;
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength);
s->cStringLength += UTF8StringLength;
s->length += length;
|
>
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
case 1:
s->UTF8 = YES;
break;
case -1:
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength);
s->cStringLength += UTF8StringLength;
s->length += length;
|
︙ | | | ︙ | |
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
if (string == nil)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
UTF8StringLength = [string UTF8StringLength];
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, [string UTF8String],
UTF8StringLength);
s->cStringLength += UTF8StringLength;
|
>
|
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
if (string == nil)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
UTF8StringLength = [string UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength +
UTF8StringLength + 1];
memcpy(s->cString + s->cStringLength, [string UTF8String],
UTF8StringLength);
s->cStringLength += UTF8StringLength;
|
︙ | | | ︙ | |
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
free(UTF8String);
}
}
- (void)reverse
{
size_t i, j;
/* We reverse all bytes and restore UTF-8 later, if necessary */
for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2;
i++, j--) {
s->cString[i] ^= s->cString[j];
s->cString[j] ^= s->cString[i];
s->cString[i] ^= s->cString[j];
|
>
>
|
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
free(UTF8String);
}
}
- (void)reverse
{
size_t i, j;
s->hashed = NO;
/* We reverse all bytes and restore UTF-8 later, if necessary */
for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2;
i++, j--) {
s->cString[i] ^= s->cString[j];
s->cString[j] ^= s->cString[i];
s->cString[i] ^= s->cString[j];
|
︙ | | | ︙ | |
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
@throw [OFOutOfRangeException exceptionWithClass: isa];
if (s->UTF8)
index = of_string_index_to_position(s->cString, index,
s->cStringLength);
newCStringLength = s->cStringLength + [string UTF8StringLength];
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
memmove(s->cString + index + [string UTF8StringLength],
s->cString + index, s->cStringLength - index);
memcpy(s->cString + index, [string UTF8String],
[string UTF8StringLength]);
|
>
|
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
@throw [OFOutOfRangeException exceptionWithClass: isa];
if (s->UTF8)
index = of_string_index_to_position(s->cString, index,
s->cStringLength);
newCStringLength = s->cStringLength + [string UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
memmove(s->cString + index + [string UTF8StringLength],
s->cString + index, s->cStringLength - index);
memcpy(s->cString + index, [string UTF8String],
[string UTF8StringLength]);
|
︙ | | | ︙ | |
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
if (start > end)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
if (end > s->length)
@throw [OFOutOfRangeException exceptionWithClass: isa];
s->length -= end - start;
if (s->UTF8) {
start = of_string_index_to_position(s->cString, start,
s->cStringLength);
end = of_string_index_to_position(s->cString, end,
s->cStringLength);
|
>
|
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
if (start > end)
@throw [OFInvalidArgumentException exceptionWithClass: isa
selector: _cmd];
if (end > s->length)
@throw [OFOutOfRangeException exceptionWithClass: isa];
s->hashed = NO;
s->length -= end - start;
if (s->UTF8) {
start = of_string_index_to_position(s->cString, start,
s->cStringLength);
end = of_string_index_to_position(s->cString, end,
s->cStringLength);
|
︙ | | | ︙ | |
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
s->cStringLength);
end = of_string_index_to_position(s->cString, end,
s->cStringLength);
}
newCStringLength = s->cStringLength - (end - start) +
[replacement UTF8StringLength];
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
memmove(s->cString + end, s->cString + start +
[replacement UTF8StringLength], s->cStringLength - end);
memcpy(s->cString + start, [replacement UTF8String],
[replacement UTF8StringLength]);
|
>
|
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
s->cStringLength);
end = of_string_index_to_position(s->cString, end,
s->cStringLength);
}
newCStringLength = s->cStringLength - (end - start) +
[replacement UTF8StringLength];
s->hashed = NO;
s->cString = [self resizeMemory: s->cString
toSize: newCStringLength + 1];
memmove(s->cString + end, s->cString + start +
[replacement UTF8StringLength], s->cStringLength - end);
memcpy(s->cString + start, [replacement UTF8String],
[replacement UTF8StringLength]);
|
︙ | | | ︙ | |
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
|
}
memcpy(newCString + newCStringLength, s->cString + last,
s->cStringLength - last);
newCStringLength += s->cStringLength - last;
newCString[newCStringLength] = 0;
[self freeMemory: s->cString];
s->cString = newCString;
s->cStringLength = newCStringLength;
s->length = newLength;
}
- (void)deleteLeadingWhitespaces
{
size_t i;
for (i = 0; i < s->cStringLength; i++)
if (s->cString[i] != ' ' && s->cString[i] != '\t' &&
s->cString[i] != '\n' && s->cString[i] != '\r' &&
s->cString[i] != '\f')
break;
s->cStringLength -= i;
s->length -= i;
memmove(s->cString, s->cString + i, s->cStringLength);
s->cString[s->cStringLength] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)deleteTrailingWhitespaces
{
size_t d;
char *p;
d = 0;
for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) {
if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' &&
*p != '\f')
break;
|
>
>
>
>
|
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
|
}
memcpy(newCString + newCStringLength, s->cString + last,
s->cStringLength - last);
newCStringLength += s->cStringLength - last;
newCString[newCStringLength] = 0;
[self freeMemory: s->cString];
s->hashed = NO;
s->cString = newCString;
s->cStringLength = newCStringLength;
s->length = newLength;
}
- (void)deleteLeadingWhitespaces
{
size_t i;
for (i = 0; i < s->cStringLength; i++)
if (s->cString[i] != ' ' && s->cString[i] != '\t' &&
s->cString[i] != '\n' && s->cString[i] != '\r' &&
s->cString[i] != '\f')
break;
s->hashed = NO;
s->cStringLength -= i;
s->length -= i;
memmove(s->cString, s->cString + i, s->cStringLength);
s->cString[s->cStringLength] = '\0';
@try {
s->cString = [self resizeMemory: s->cString
toSize: s->cStringLength + 1];
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)deleteTrailingWhitespaces
{
size_t d;
char *p;
s->hashed = NO;
d = 0;
for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) {
if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' &&
*p != '\f')
break;
|
︙ | | | ︙ | |
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
}
}
- (void)deleteEnclosingWhitespaces
{
size_t d, i;
char *p;
d = 0;
for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) {
if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' &&
*p != '\f')
break;
|
>
>
|
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
|
}
}
- (void)deleteEnclosingWhitespaces
{
size_t d, i;
char *p;
s->hashed = NO;
d = 0;
for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) {
if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' &&
*p != '\f')
break;
|
︙ | | | ︙ | |