23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#import "OFString.h"
#import "OFMutableString_UTF8.h"
#import "OFAutoreleasePool.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"
static struct {
|
>
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#import "OFString.h"
#import "OFMutableString_UTF8.h"
#import "OFAutoreleasePool.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"
static struct {
|
408
409
410
411
412
413
414
415
416
417
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
|
[self deleteCharactersInRange: range];
[self insertString: replacement
atIndex: range.start];
}
- (void)replaceOccurrencesOfString: (OFString*)string
withString: (OFString*)replacement
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
const of_unichar_t *unicodeString;
const of_unichar_t *searchString = [string unicodeString];
size_t length = [self length];
size_t searchLength = [string length];
size_t replacementLength = [replacement length];
size_t i;
if (searchLength > length) {
[pool release];
return;
}
pool2 = [[OFAutoreleasePool alloc] init];
unicodeString = [self unicodeString];
for (i = 0; i <= length - searchLength; i++) {
if (memcmp(unicodeString + i, searchString,
searchLength * sizeof(of_unichar_t)))
continue;
[self replaceCharactersInRange: of_range(i, searchLength)
withString: replacement];
length -= searchLength;
length += replacementLength;
i += replacementLength - 1;
[pool2 releaseObjects];
unicodeString = [self unicodeString];
}
|
>
>
>
>
>
>
>
>
>
<
>
>
>
|
|
|
|
|
409
410
411
412
413
414
415
416
417
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
|
[self deleteCharactersInRange: range];
[self insertString: replacement
atIndex: range.start];
}
- (void)replaceOccurrencesOfString: (OFString*)string
withString: (OFString*)replacement
{
[self replaceOccurrencesOfString: string
withString: replacement
inRange: of_range(0, [self length])];
}
- (void)replaceOccurrencesOfString: (OFString*)string
withString: (OFString*)replacement
inRange: (of_range_t)range
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
const of_unichar_t *unicodeString;
const of_unichar_t *searchString = [string unicodeString];
size_t searchLength = [string length];
size_t replacementLength = [replacement length];
size_t i;
if (range.start + range.length > [self length])
@throw [OFOutOfRangeException exceptionWithClass: isa];
if (searchLength > range.length) {
[pool release];
return;
}
pool2 = [[OFAutoreleasePool alloc] init];
unicodeString = [self unicodeString];
for (i = range.start; i <= range.length - searchLength; i++) {
if (memcmp(unicodeString + i, searchString,
searchLength * sizeof(of_unichar_t)))
continue;
[self replaceCharactersInRange: of_range(i, searchLength)
withString: replacement];
range.length -= searchLength;
range.length += replacementLength;
i += replacementLength - 1;
[pool2 releaseObjects];
unicodeString = [self unicodeString];
}
|