︙ | | | ︙ | |
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
if (freeWhenDone)
free(UTF8String);
return self;
}
#ifdef OF_HAVE_UNICODE_TABLES
- (void)of_convertWithWordStartTable: (const of_unichar_t *const [])startTable
wordMiddleTable: (const of_unichar_t *const [])middleTable
wordStartTableSize: (size_t)startTableSize
wordMiddleTableSize: (size_t)middleTableSize
{
of_unichar_t *unicodeString;
size_t unicodeLen, newCStringLength;
size_t i, j;
char *newCString;
bool isStart = true;
if (!_s->isUTF8) {
uint8_t t;
const of_unichar_t *const *table;
assert(startTableSize >= 1 && middleTableSize >= 1);
_s->hashed = false;
for (i = 0; i < _s->cStringLength; i++) {
if (isStart)
|
|
|
|
|
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
if (freeWhenDone)
free(UTF8String);
return self;
}
#ifdef OF_HAVE_UNICODE_TABLES
- (void)of_convertWithWordStartTable: (const OFUnichar *const [])startTable
wordMiddleTable: (const OFUnichar *const [])middleTable
wordStartTableSize: (size_t)startTableSize
wordMiddleTableSize: (size_t)middleTableSize
{
OFUnichar *unicodeString;
size_t unicodeLen, newCStringLength;
size_t i, j;
char *newCString;
bool isStart = true;
if (!_s->isUTF8) {
uint8_t t;
const OFUnichar *const *table;
assert(startTableSize >= 1 && middleTableSize >= 1);
_s->hashed = false;
for (i = 0; i < _s->cStringLength; i++) {
if (isStart)
|
︙ | | | ︙ | |
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
_s->cString[i] = t;
}
return;
}
unicodeLen = self.length;
unicodeString = of_alloc(unicodeLen, sizeof(of_unichar_t));
i = j = 0;
newCStringLength = 0;
while (i < _s->cStringLength) {
const of_unichar_t *const *table;
size_t tableSize;
of_unichar_t c;
ssize_t cLen;
if (isStart) {
table = startTable;
tableSize = middleTableSize;
} else {
table = middleTable;
|
|
|
|
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
_s->cString[i] = t;
}
return;
}
unicodeLen = self.length;
unicodeString = of_alloc(unicodeLen, sizeof(OFUnichar));
i = j = 0;
newCStringLength = 0;
while (i < _s->cStringLength) {
const OFUnichar *const *table;
size_t tableSize;
OFUnichar c;
ssize_t cLen;
if (isStart) {
table = startTable;
tableSize = middleTableSize;
} else {
table = middleTable;
|
︙ | | | ︙ | |
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
free(unicodeString);
@throw [OFInvalidEncodingException exception];
}
isStart = of_ascii_isspace(c);
if (c >> 8 < tableSize) {
of_unichar_t tc = table[c >> 8][c & 0xFF];
if (tc)
c = tc;
}
unicodeString[j++] = c;
if (c < 0x80)
|
|
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
free(unicodeString);
@throw [OFInvalidEncodingException exception];
}
isStart = of_ascii_isspace(c);
if (c >> 8 < tableSize) {
OFUnichar tc = table[c >> 8][c & 0xFF];
if (tc)
c = tc;
}
unicodeString[j++] = c;
if (c < 0x80)
|
︙ | | | ︙ | |
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* Even though cStringLength can change, length cannot, therefore no
* need to change it.
*/
}
#endif
- (void)setCharacter: (of_unichar_t)character atIndex: (size_t)idx
{
char buffer[4];
of_unichar_t c;
size_t lenNew;
ssize_t lenOld;
if (_s->isUTF8)
idx = of_string_utf8_get_position(_s->cString, idx,
_s->cStringLength);
|
|
|
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/*
* Even though cStringLength can change, length cannot, therefore no
* need to change it.
*/
}
#endif
- (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx
{
char buffer[4];
OFUnichar c;
size_t lenNew;
ssize_t lenOld;
if (_s->isUTF8)
idx = of_string_utf8_get_position(_s->cString, idx,
_s->cStringLength);
|
︙ | | | ︙ | |
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
_s->cStringLength += UTF8StringLength;
_s->length += length;
_s->cString[_s->cStringLength] = 0;
}
- (void)appendCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
{
[self appendCString: cString
encoding: encoding
length: strlen(cString)];
}
- (void)appendCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength
{
if (encoding == OF_STRING_ENCODING_UTF_8)
[self appendUTF8String: cString length: cStringLength];
else {
void *pool = objc_autoreleasePoolPush();
[self appendString:
[OFString stringWithCString: cString
encoding: encoding
|
|
|
|
|
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
_s->cStringLength += UTF8StringLength;
_s->length += length;
_s->cString[_s->cStringLength] = 0;
}
- (void)appendCString: (const char *)cString
encoding: (OFStringEncoding)encoding
{
[self appendCString: cString
encoding: encoding
length: strlen(cString)];
}
- (void)appendCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
if (encoding == OFStringEncodingUTF8)
[self appendUTF8String: cString length: cStringLength];
else {
void *pool = objc_autoreleasePoolPush();
[self appendString:
[OFString stringWithCString: cString
encoding: encoding
|
︙ | | | ︙ | |
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
[string isKindOfClass: [OFMutableUTF8String class]]) {
if (((OFMutableUTF8String *)string)->_s->isUTF8)
_s->isUTF8 = true;
} else
_s->isUTF8 = true;
}
- (void)appendCharacters: (const of_unichar_t *)characters
length: (size_t)length
{
char *tmp = of_alloc((length * 4) + 1, 1);
@try {
size_t j = 0;
bool isUTF8 = false;
|
|
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
[string isKindOfClass: [OFMutableUTF8String class]]) {
if (((OFMutableUTF8String *)string)->_s->isUTF8)
_s->isUTF8 = true;
} else
_s->isUTF8 = true;
}
- (void)appendCharacters: (const OFUnichar *)characters
length: (size_t)length
{
char *tmp = of_alloc((length * 4) + 1, 1);
@try {
size_t j = 0;
bool isUTF8 = false;
|
︙ | | | ︙ | |
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
[string isKindOfClass: [OFMutableUTF8String class]]) {
if (((OFMutableUTF8String *)string)->_s->isUTF8)
_s->isUTF8 = true;
} else
_s->isUTF8 = true;
}
- (void)deleteCharactersInRange: (of_range_t)range
{
size_t start = range.location;
size_t end = range.location + range.length;
if (range.length > SIZE_MAX - range.location || end > _s->length)
@throw [OFOutOfRangeException exception];
|
|
|
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
[string isKindOfClass: [OFMutableUTF8String class]]) {
if (((OFMutableUTF8String *)string)->_s->isUTF8)
_s->isUTF8 = true;
} else
_s->isUTF8 = true;
}
- (void)deleteCharactersInRange: (OFRange)range
{
size_t start = range.location;
size_t end = range.location + range.length;
if (range.length > SIZE_MAX - range.location || end > _s->length)
@throw [OFOutOfRangeException exception];
|
︙ | | | ︙ | |
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
@try {
_s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1);
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)replaceCharactersInRange: (of_range_t)range
withString: (OFString *)replacement
{
size_t start = range.location;
size_t end = range.location + range.length;
size_t newCStringLength, newLength;
if (replacement == nil)
|
|
|
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
@try {
_s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1);
} @catch (OFOutOfMemoryException *e) {
/* We don't really care, as we only made it smaller */
}
}
- (void)replaceCharactersInRange: (OFRange)range
withString: (OFString *)replacement
{
size_t start = range.location;
size_t end = range.location + range.length;
size_t newCStringLength, newLength;
if (replacement == nil)
|
︙ | | | ︙ | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
} else
_s->isUTF8 = true;
}
- (void)replaceOccurrencesOfString: (OFString *)string
withString: (OFString *)replacement
options: (int)options
range: (of_range_t)range
{
const char *searchString = string.UTF8String;
const char *replacementString = replacement.UTF8String;
size_t searchLength = string.UTF8StringLength;
size_t replacementLength = replacement.UTF8StringLength;
size_t last, newCStringLength, newLength;
char *newCString;
|
|
|
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
} else
_s->isUTF8 = true;
}
- (void)replaceOccurrencesOfString: (OFString *)string
withString: (OFString *)replacement
options: (int)options
range: (OFRange)range
{
const char *searchString = string.UTF8String;
const char *replacementString = replacement.UTF8String;
size_t searchLength = string.UTF8StringLength;
size_t replacementLength = replacement.UTF8StringLength;
size_t last, newCStringLength, newLength;
char *newCString;
|
︙ | | | ︙ | |