39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* Worst case: 3 times longer than before.
* Oh, and we can't use [self allocWithSize:] here as self might be a
* @"" literal.
*/
if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithClass: isa
requestedSize: ([self UTF8StringLength] * 3) + 1];
for (i = 0; *string != '\0'; string++) {
if (isalnum((int)*string) || *string == '-' || *string == '_' ||
*string == '.' || *string == '~')
retCString[i++] = *string;
else {
|
|
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* Worst case: 3 times longer than before.
* Oh, and we can't use [self allocWithSize:] here as self might be a
* @"" literal.
*/
if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithClass: [self class]
requestedSize: ([self UTF8StringLength] * 3) + 1];
for (i = 0; *string != '\0'; string++) {
if (isalnum((int)*string) || *string == '-' || *string == '_' ||
*string == '.' || *string == '~')
retCString[i++] = *string;
else {
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
char *retCString;
char byte = 0;
int state = 0;
size_t i;
if ((retCString = malloc([self UTF8StringLength] + 1)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithClass: isa
requestedSize: [self UTF8StringLength] + 1];
for (i = 0; *string; string++) {
switch (state) {
case 0:
if (*string == '%')
state = 1;
|
|
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
char *retCString;
char byte = 0;
int state = 0;
size_t i;
if ((retCString = malloc([self UTF8StringLength] + 1)) == NULL)
@throw [OFOutOfMemoryException
exceptionWithClass: [self class]
requestedSize: [self UTF8StringLength] + 1];
for (i = 0; *string; string++) {
switch (state) {
case 0:
if (*string == '%')
state = 1;
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
else if (*string >= 'A' && *string <= 'F')
byte += (*string - 'A' + 10) << shift;
else if (*string >= 'a' && *string <= 'f')
byte += (*string - 'a' + 10) << shift;
else {
free(retCString);
@throw [OFInvalidEncodingException
exceptionWithClass: isa];
}
if (++state == 3) {
retCString[i++] = byte;
state = 0;
byte = 0;
}
break;
}
}
retCString[i] = '\0';
if (state != 0) {
free(retCString);
@throw [OFInvalidEncodingException exceptionWithClass: isa];
}
@try {
ret = [OFString stringWithUTF8String: retCString
length: i];
} @finally {
free(retCString);
}
return ret;
}
@end
|
|
|
>
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
else if (*string >= 'A' && *string <= 'F')
byte += (*string - 'A' + 10) << shift;
else if (*string >= 'a' && *string <= 'f')
byte += (*string - 'a' + 10) << shift;
else {
free(retCString);
@throw [OFInvalidEncodingException
exceptionWithClass: [self class]];
}
if (++state == 3) {
retCString[i++] = byte;
state = 0;
byte = 0;
}
break;
}
}
retCString[i] = '\0';
if (state != 0) {
free(retCString);
@throw [OFInvalidEncodingException
exceptionWithClass: [self class]];
}
@try {
ret = [OFString stringWithUTF8String: retCString
length: i];
} @finally {
free(retCString);
}
return ret;
}
@end
|