25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#endif
#import "OFMutableString.h"
#import "OFExceptions.h"
#import "OFMacros.h"
#import "asprintf.h"
extern const of_unichar_t* const of_unicode_upper_table[0x1100];
extern const of_unichar_t* const of_unicode_lower_table[0x1100];
static void
apply_table(id self, Class isa, char **string, unsigned int *length,
BOOL is_utf8, const of_unichar_t* const table[])
{
of_unichar_t c, tc;
of_unichar_t *ustr;
size_t ulen, nlen;
size_t i, j, d;
char *nstr;
if (!is_utf8) {
uint8_t *p = (uint8_t*)*string + *length;
uint8_t t;
while (--p >= (uint8_t*)*string)
if ((t = table[0][*p]) != 0)
*p = t;
|
|
<
<
|
>
>
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#endif
#import "OFMutableString.h"
#import "OFExceptions.h"
#import "OFMacros.h"
#import "asprintf.h"
#import "unicode.h"
static void
apply_table(id self, Class isa, char **string, unsigned int *length,
BOOL is_utf8, const of_unichar_t* const table[], const size_t table_size)
{
of_unichar_t c, tc;
of_unichar_t *ustr;
size_t ulen, nlen;
size_t i, j, d;
char *nstr;
if (!is_utf8) {
assert(table_size >= 1);
uint8_t *p = (uint8_t*)*string + *length;
uint8_t t;
while (--p >= (uint8_t*)*string)
if ((t = table[0][*p]) != 0)
*p = t;
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
c = of_string_utf8_to_unicode(*string + i, *length - i);
if (c == OF_INVALID_UNICHAR || c > 0x10FFFF) {
[self freeMemory: ustr];
@throw [OFInvalidEncodingException newWithClass: isa];
}
if ((tc = table[c >> 8][c & 0xFF]) == 0)
tc = c;
ustr[j++] = tc;
if (tc < 0x80)
nlen++;
else if (tc < 0x800)
nlen += 2;
|
>
|
>
>
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
c = of_string_utf8_to_unicode(*string + i, *length - i);
if (c == OF_INVALID_UNICHAR || c > 0x10FFFF) {
[self freeMemory: ustr];
@throw [OFInvalidEncodingException newWithClass: isa];
}
if (c >> 8 < table_size) {
if ((tc = table[c >> 8][c & 0xFF]) == 0)
tc = c;
} else
tc = c;
ustr[j++] = tc;
if (tc < 0x80)
nlen++;
else if (tc < 0x800)
nlen += 2;
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
return self;
}
- upper
{
apply_table(self, isa, &string, &length, is_utf8,
of_unicode_upper_table);
return self;
}
- lower
{
apply_table(self, isa, &string, &length, is_utf8,
of_unicode_lower_table);
return self;
}
- removeCharactersFromIndex: (size_t)start
toIndex: (size_t)end
{
|
|
|
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
return self;
}
- upper
{
apply_table(self, isa, &string, &length, is_utf8,
of_unicode_upper_table, OF_UNICODE_UPPER_TABLE_SIZE);
return self;
}
- lower
{
apply_table(self, isa, &string, &length, is_utf8,
of_unicode_lower_table, OF_UNICODE_LOWER_TABLE_SIZE);
return self;
}
- removeCharactersFromIndex: (size_t)start
toIndex: (size_t)end
{
|