︙ | | | ︙ | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
[attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid]
forKey: of_file_attribute_key_posix_gid];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
of_string_encoding_t encoding = [OFLocale encoding];
struct passwd *passwd = getpwuid(s->st_uid);
struct group *group_ = getgrgid(s->st_gid);
if (passwd != NULL) {
OFString *owner = [OFString
stringWithCString: passwd->pw_name
encoding: encoding];
|
|
|
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
[attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid]
forKey: of_file_attribute_key_posix_gid];
# ifdef OF_HAVE_THREADS
[passwdMutex lock];
@try {
# endif
OFStringEncoding encoding = [OFLocale encoding];
struct passwd *passwd = getpwuid(s->st_uid);
struct group *group_ = getgrgid(s->st_gid);
if (passwd != NULL) {
OFString *owner = [OFString
stringWithCString: passwd->pw_name
encoding: encoding];
|
︙ | | | ︙ | |
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
static void
setSymbolicLinkDestinationAttribute(of_mutable_file_attributes_t attributes,
OFURL *URL)
{
OFString *path = URL.fileSystemRepresentation;
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocale encoding];
char destinationC[PATH_MAX];
ssize_t length;
OFString *destination;
of_file_attribute_key_t key;
length = readlink([path cStringWithEncoding: encoding], destinationC,
PATH_MAX);
|
|
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
static void
setSymbolicLinkDestinationAttribute(of_mutable_file_attributes_t attributes,
OFURL *URL)
{
OFString *path = URL.fileSystemRepresentation;
# ifndef OF_WINDOWS
OFStringEncoding encoding = [OFLocale encoding];
char destinationC[PATH_MAX];
ssize_t length;
OFString *destination;
of_file_attribute_key_t key;
length = readlink([path cStringWithEncoding: encoding], destinationC,
PATH_MAX);
|
︙ | | | ︙ | |
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
|
attributeKey: (of_file_attribute_key_t)attributeKey
attributes: (of_file_attributes_t)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
OFString *path = URL.fileSystemRepresentation;
uid_t uid = -1;
gid_t gid = -1;
of_string_encoding_t encoding;
if (owner == nil && group == nil)
@throw [OFInvalidArgumentException exception];
encoding = [OFLocale encoding];
# ifdef OF_HAVE_THREADS
|
|
|
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
|
attributeKey: (of_file_attribute_key_t)attributeKey
attributes: (of_file_attributes_t)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
OFString *path = URL.fileSystemRepresentation;
uid_t uid = -1;
gid_t gid = -1;
OFStringEncoding encoding;
if (owner == nil && group == nil)
@throw [OFInvalidArgumentException exception];
encoding = [OFLocale encoding];
# ifdef OF_HAVE_THREADS
|
︙ | | | ︙ | |
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
exceptionWithObject: self
requestedLength: 0
errNo: retrieveError()];
} @finally {
FindClose(handle);
}
} else {
of_string_encoding_t encoding = [OFLocale encoding];
WIN32_FIND_DATA fd;
if ((handle = FindFirstFileA(
[path cStringWithEncoding: encoding], &fd)) ==
INVALID_HANDLE_VALUE)
@throw [OFOpenItemFailedException
exceptionWithURL: URL
|
|
|
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
exceptionWithObject: self
requestedLength: 0
errNo: retrieveError()];
} @finally {
FindClose(handle);
}
} else {
OFStringEncoding encoding = [OFLocale encoding];
WIN32_FIND_DATA fd;
if ((handle = FindFirstFileA(
[path cStringWithEncoding: encoding], &fd)) ==
INVALID_HANDLE_VALUE)
@throw [OFOpenItemFailedException
exceptionWithURL: URL
|
︙ | | | ︙ | |
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
|
requestedLength: 0
errNo: retrieveError()];
} @finally {
FindClose(handle);
}
}
#elif defined(OF_AMIGAOS)
of_string_encoding_t encoding = [OFLocale encoding];
BPTR lock;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0)
@throw [OFOpenItemFailedException
exceptionWithURL: URL
mode: nil
|
|
|
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
|
requestedLength: 0
errNo: retrieveError()];
} @finally {
FindClose(handle);
}
}
#elif defined(OF_AMIGAOS)
OFStringEncoding encoding = [OFLocale encoding];
BPTR lock;
if ((lock = Lock([path cStringWithEncoding: encoding],
SHARED_LOCK)) == 0)
@throw [OFOpenItemFailedException
exceptionWithURL: URL
mode: nil
|
︙ | | | ︙ | |
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
|
exceptionWithObject: self
requestedLength: 0
errNo: retrieveError()];
} @finally {
UnLock(lock);
}
#else
of_string_encoding_t encoding = [OFLocale encoding];
DIR *dir;
if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errno];
# if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS)
|
|
|
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
|
exceptionWithObject: self
requestedLength: 0
errNo: retrieveError()];
} @finally {
UnLock(lock);
}
#else
OFStringEncoding encoding = [OFLocale encoding];
DIR *dir;
if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
@throw [OFOpenItemFailedException exceptionWithURL: URL
mode: nil
errNo: errno];
# if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS)
|
︙ | | | ︙ | |
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
|
![destination.scheme isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
sourcePath = source.fileSystemRepresentation;
destinationPath = destination.fileSystemRepresentation;
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocale encoding];
if (link([sourcePath cStringWithEncoding: encoding],
[destinationPath cStringWithEncoding: encoding]) != 0)
@throw [OFLinkFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
|
|
|
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
|
![destination.scheme isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
sourcePath = source.fileSystemRepresentation;
destinationPath = destination.fileSystemRepresentation;
# ifndef OF_WINDOWS
OFStringEncoding encoding = [OFLocale encoding];
if (link([sourcePath cStringWithEncoding: encoding],
[destinationPath cStringWithEncoding: encoding]) != 0)
@throw [OFLinkFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: errno];
|
︙ | | | ︙ | |
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
|
if (![URL.scheme isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
path = URL.fileSystemRepresentation;
# ifndef OF_WINDOWS
of_string_encoding_t encoding = [OFLocale encoding];
if (symlink([target cStringWithEncoding: encoding],
[path cStringWithEncoding: encoding]) != 0)
@throw [OFCreateSymbolicLinkFailedException
exceptionWithURL: URL
target: target
errNo: errno];
|
|
|
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
|
if (![URL.scheme isEqual: _scheme])
@throw [OFInvalidArgumentException exception];
path = URL.fileSystemRepresentation;
# ifndef OF_WINDOWS
OFStringEncoding encoding = [OFLocale encoding];
if (symlink([target cStringWithEncoding: encoding],
[path cStringWithEncoding: encoding]) != 0)
@throw [OFCreateSymbolicLinkFailedException
exceptionWithURL: URL
target: target
errNo: errno];
|
︙ | | | ︙ | |
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
|
exceptionWithSourceURL: source
destinationURL: destination
errNo: EEXIST];
pool = objc_autoreleasePoolPush();
#ifdef OF_AMIGAOS
of_string_encoding_t encoding = [OFLocale encoding];
if (!Rename([source.fileSystemRepresentation
cStringWithEncoding: encoding],
[destination.fileSystemRepresentation
cStringWithEncoding: encoding]))
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: retrieveError()];
#else
int status;
# ifdef OF_WINDOWS
if ([OFSystemInfo isWindowsNT])
status = _wrename(source.fileSystemRepresentation.UTF16String,
destination.fileSystemRepresentation.UTF16String);
else {
# endif
of_string_encoding_t encoding = [OFLocale encoding];
status = rename([source.fileSystemRepresentation
cStringWithEncoding: encoding],
[destination.fileSystemRepresentation
cStringWithEncoding: encoding]);
# ifdef OF_WINDOWS
}
|
|
|
|
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
|
exceptionWithSourceURL: source
destinationURL: destination
errNo: EEXIST];
pool = objc_autoreleasePoolPush();
#ifdef OF_AMIGAOS
OFStringEncoding encoding = [OFLocale encoding];
if (!Rename([source.fileSystemRepresentation
cStringWithEncoding: encoding],
[destination.fileSystemRepresentation
cStringWithEncoding: encoding]))
@throw [OFMoveItemFailedException
exceptionWithSourceURL: source
destinationURL: destination
errNo: retrieveError()];
#else
int status;
# ifdef OF_WINDOWS
if ([OFSystemInfo isWindowsNT])
status = _wrename(source.fileSystemRepresentation.UTF16String,
destination.fileSystemRepresentation.UTF16String);
else {
# endif
OFStringEncoding encoding = [OFLocale encoding];
status = rename([source.fileSystemRepresentation
cStringWithEncoding: encoding],
[destination.fileSystemRepresentation
cStringWithEncoding: encoding]);
# ifdef OF_WINDOWS
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
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
|
case 505:
return @"HTTP Version Not Supported";
default:
return @"(unknown)";
}
}
static of_string_encoding_t
encodingForContentType(OFString *contentType)
{
const char *UTF8String = contentType.UTF8String;
size_t last, length = contentType.UTF8StringLength;
enum {
STATE_TYPE,
STATE_BEFORE_PARAM_NAME,
STATE_PARAM_NAME,
STATE_PARAM_VALUE_OR_QUOTE,
STATE_PARAM_VALUE,
STATE_PARAM_QUOTED_VALUE,
STATE_AFTER_PARAM_VALUE
} state = STATE_TYPE;
OFString *name = nil, *value = nil, *charset = nil;
of_string_encoding_t ret;
last = 0;
for (size_t i = 0; i < length; i++) {
switch (state) {
case STATE_TYPE:
if (UTF8String[i] == ';') {
state = STATE_BEFORE_PARAM_NAME;
|
|
|
|
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
|
case 505:
return @"HTTP Version Not Supported";
default:
return @"(unknown)";
}
}
static OFStringEncoding
encodingForContentType(OFString *contentType)
{
const char *UTF8String = contentType.UTF8String;
size_t last, length = contentType.UTF8StringLength;
enum {
STATE_TYPE,
STATE_BEFORE_PARAM_NAME,
STATE_PARAM_NAME,
STATE_PARAM_VALUE_OR_QUOTE,
STATE_PARAM_VALUE,
STATE_PARAM_QUOTED_VALUE,
STATE_AFTER_PARAM_VALUE
} state = STATE_TYPE;
OFString *name = nil, *value = nil, *charset = nil;
OFStringEncoding ret;
last = 0;
for (size_t i = 0; i < length; i++) {
switch (state) {
case STATE_TYPE:
if (UTF8String[i] == ';') {
state = STATE_BEFORE_PARAM_NAME;
|
︙ | | | ︙ | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
}
break;
case STATE_AFTER_PARAM_VALUE:
if (UTF8String[i] == ';') {
state = STATE_BEFORE_PARAM_NAME;
last = i + 1;
} else if (UTF8String[i] != ' ')
return OF_STRING_ENCODING_AUTODETECT;
break;
}
}
if (state == STATE_PARAM_VALUE) {
value = [OFString stringWithUTF8String: UTF8String + last
length: length - last];
value = value.stringByDeletingTrailingWhitespaces;
if ([name isEqual: @"charset"])
charset = value;
}
@try {
ret = of_string_parse_encoding(charset);
} @catch (OFInvalidArgumentException *e) {
ret = OF_STRING_ENCODING_AUTODETECT;
}
return ret;
}
@implementation OFHTTPResponse
@synthesize statusCode = _statusCode, headers = _headers;
|
|
|
|
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
}
break;
case STATE_AFTER_PARAM_VALUE:
if (UTF8String[i] == ';') {
state = STATE_BEFORE_PARAM_NAME;
last = i + 1;
} else if (UTF8String[i] != ' ')
return OFStringEncodingAutodetect;
break;
}
}
if (state == STATE_PARAM_VALUE) {
value = [OFString stringWithUTF8String: UTF8String + last
length: length - last];
value = value.stringByDeletingTrailingWhitespaces;
if ([name isEqual: @"charset"])
charset = value;
}
@try {
ret = OFParseStringEncodingName(charset);
} @catch (OFInvalidArgumentException *e) {
ret = OFStringEncodingAutodetect;
}
return ret;
}
@implementation OFHTTPResponse
@synthesize statusCode = _statusCode, headers = _headers;
|
︙ | | | ︙ | |
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
return [OFString stringWithFormat: @"%hhu.%hhu",
_protocolVersion.major,
_protocolVersion.minor];
}
- (OFString *)string
{
return [self stringWithEncoding: OF_STRING_ENCODING_AUTODETECT];
}
- (OFString *)stringWithEncoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFString *contentType, *contentLengthString, *ret;
OFData *data;
if (encoding == OF_STRING_ENCODING_AUTODETECT &&
(contentType = [_headers objectForKey: @"Content-Type"]) != nil)
encoding = encodingForContentType(contentType);
if (encoding == OF_STRING_ENCODING_AUTODETECT)
encoding = OF_STRING_ENCODING_UTF_8;
data = [self readDataUntilEndOfStream];
contentLengthString = [_headers objectForKey: @"Content-Length"];
if (contentLengthString != nil) {
unsigned long long contentLength =
contentLengthString.unsignedLongLongValue;
|
|
|
|
|
|
|
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
return [OFString stringWithFormat: @"%hhu.%hhu",
_protocolVersion.major,
_protocolVersion.minor];
}
- (OFString *)string
{
return [self stringWithEncoding: OFStringEncodingAutodetect];
}
- (OFString *)stringWithEncoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFString *contentType, *contentLengthString, *ret;
OFData *data;
if (encoding == OFStringEncodingAutodetect &&
(contentType = [_headers objectForKey: @"Content-Type"]) != nil)
encoding = encodingForContentType(contentType);
if (encoding == OFStringEncodingAutodetect)
encoding = OFStringEncodingUTF8;
data = [self readDataUntilEndOfStream];
contentLengthString = [_headers objectForKey: @"Content-Length"];
if (contentLengthString != nil) {
unsigned long long contentLength =
contentLengthString.unsignedLongLongValue;
|
︙ | | | ︙ | |
︙ | | | ︙ | |
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
return [OFDate dateWithLocalDateString: dateString
format: @"%Y-%m-%d %H:%M:%S"];
}
static void
parseFileNameExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
[entry->_fileName release];
entry->_fileName = nil;
entry->_fileName = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: [extension count] - 1];
}
static void
parseDirectoryNameExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
void *pool = objc_autoreleasePoolPush();
OFMutableData *data = [[extension mutableCopy] autorelease];
char *items = data.mutableItems;
size_t count = data.count;
OFMutableString *directoryName;
|
|
|
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
return [OFDate dateWithLocalDateString: dateString
format: @"%Y-%m-%d %H:%M:%S"];
}
static void
parseFileNameExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
[entry->_fileName release];
entry->_fileName = nil;
entry->_fileName = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: [extension count] - 1];
}
static void
parseDirectoryNameExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
void *pool = objc_autoreleasePoolPush();
OFMutableData *data = [[extension mutableCopy] autorelease];
char *items = data.mutableItems;
size_t count = data.count;
OFMutableString *directoryName;
|
︙ | | | ︙ | |
95
96
97
98
99
100
101
102
103
104
105
106
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
|
entry->_directoryName = [directoryName copy];
objc_autoreleasePoolPop(pool);
}
static void
parseCommentExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
[entry->_fileComment release];
entry->_fileComment = nil;
entry->_fileComment = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
uint16_t mode;
if (extension.count != 3)
@throw [OFInvalidFormatException exception];
memcpy(&mode, (char *)extension.items + 1, 2);
mode = OF_BSWAP16_IF_BE(mode);
[entry->_mode release];
entry->_mode = nil;
entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode];
}
static void
parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
uint16_t UID, GID;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&GID, (char *)extension.items + 1, 2);
|
|
|
|
|
95
96
97
98
99
100
101
102
103
104
105
106
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
|
entry->_directoryName = [directoryName copy];
objc_autoreleasePoolPop(pool);
}
static void
parseCommentExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
[entry->_fileComment release];
entry->_fileComment = nil;
entry->_fileComment = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
uint16_t mode;
if (extension.count != 3)
@throw [OFInvalidFormatException exception];
memcpy(&mode, (char *)extension.items + 1, 2);
mode = OF_BSWAP16_IF_BE(mode);
[entry->_mode release];
entry->_mode = nil;
entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode];
}
static void
parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
uint16_t UID, GID;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&GID, (char *)extension.items + 1, 2);
|
︙ | | | ︙ | |
151
152
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
entry->_GID = [[OFNumber alloc] initWithUnsignedShort: GID];
entry->_UID = [[OFNumber alloc] initWithUnsignedShort: UID];
}
static void
parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
[entry->_group release];
entry->_group = nil;
entry->_group = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parseOwnerExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
[entry->_owner release];
entry->_owner = nil;
entry->_owner = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parseModificationDateExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding)
{
uint32_t modificationDate;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&modificationDate, (char *)extension.items + 1, 4);
modificationDate = OF_BSWAP32_IF_BE(modificationDate);
[entry->_modificationDate release];
entry->_modificationDate = nil;
entry->_modificationDate = [[OFDate alloc]
initWithTimeIntervalSince1970: modificationDate];
}
static bool
parseExtension(OFLHAArchiveEntry *entry, OFData *extension,
of_string_encoding_t encoding, bool allowFileName)
{
void (*function)(OFLHAArchiveEntry *, OFData *, of_string_encoding_t) =
NULL;
switch (*(char *)[extension itemAtIndex: 0]) {
case 0x01:
if (allowFileName)
function = parseFileNameExtension;
break;
|
|
|
|
|
|
|
151
152
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
entry->_GID = [[OFNumber alloc] initWithUnsignedShort: GID];
entry->_UID = [[OFNumber alloc] initWithUnsignedShort: UID];
}
static void
parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
[entry->_group release];
entry->_group = nil;
entry->_group = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parseOwnerExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
[entry->_owner release];
entry->_owner = nil;
entry->_owner = [[OFString alloc]
initWithCString: (char *)extension.items + 1
encoding: encoding
length: extension.count - 1];
}
static void
parseModificationDateExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding)
{
uint32_t modificationDate;
if (extension.count != 5)
@throw [OFInvalidFormatException exception];
memcpy(&modificationDate, (char *)extension.items + 1, 4);
modificationDate = OF_BSWAP32_IF_BE(modificationDate);
[entry->_modificationDate release];
entry->_modificationDate = nil;
entry->_modificationDate = [[OFDate alloc]
initWithTimeIntervalSince1970: modificationDate];
}
static bool
parseExtension(OFLHAArchiveEntry *entry, OFData *extension,
OFStringEncoding encoding, bool allowFileName)
{
void (*function)(OFLHAArchiveEntry *, OFData *, OFStringEncoding) =
NULL;
switch (*(char *)[extension itemAtIndex: 0]) {
case 0x01:
if (allowFileName)
function = parseFileNameExtension;
break;
|
︙ | | | ︙ | |
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
function(entry, extension, encoding);
return true;
}
static void
readExtensions(OFLHAArchiveEntry *entry, OFStream *stream,
of_string_encoding_t encoding, bool allowFileName)
{
uint16_t size;
while ((size = [stream readLittleEndianInt16]) > 0) {
OFData *extension;
if (size < 2)
|
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
function(entry, extension, encoding);
return true;
}
static void
readExtensions(OFLHAArchiveEntry *entry, OFStream *stream,
OFStringEncoding encoding, bool allowFileName)
{
uint16_t size;
while ((size = [stream readLittleEndianInt16]) > 0) {
OFData *extension;
if (size < 2)
|
︙ | | | ︙ | |
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
entry->_compressedSize -= size;
}
}
}
static void
getFileNameAndDirectoryName(OFLHAArchiveEntry *entry,
of_string_encoding_t encoding,
const char **fileName, size_t *fileNameLength,
const char **directoryName, size_t *directoryNameLength)
{
OFMutableData *data;
char *cString;
size_t length;
size_t pos;
|
|
<
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
entry->_compressedSize -= size;
}
}
}
static void
getFileNameAndDirectoryName(OFLHAArchiveEntry *entry, OFStringEncoding encoding,
const char **fileName, size_t *fileNameLength,
const char **directoryName, size_t *directoryNameLength)
{
OFMutableData *data;
char *cString;
size_t length;
size_t pos;
|
︙ | | | ︙ | |
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
}
return self;
}
- (instancetype)of_initWithHeader: (char [21])header
stream: (OFStream *)stream
encoding: (of_string_encoding_t)encoding
{
self = [super init];
@try {
uint32_t date;
_compressionMethod = [[OFString alloc]
initWithCString: header + 2
encoding: OF_STRING_ENCODING_ASCII
length: 5];
memcpy(&_compressedSize, header + 7, 4);
_compressedSize = OF_BSWAP32_IF_BE(_compressedSize);
memcpy(&_uncompressedSize, header + 11, 4);
_uncompressedSize = OF_BSWAP32_IF_BE(_uncompressedSize);
|
|
|
|
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
}
return self;
}
- (instancetype)of_initWithHeader: (char [21])header
stream: (OFStream *)stream
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
uint32_t date;
_compressionMethod = [[OFString alloc]
initWithCString: header + 2
encoding: OFStringEncodingASCII
length: 5];
memcpy(&_compressedSize, header + 7, 4);
_compressedSize = OF_BSWAP32_IF_BE(_compressedSize);
memcpy(&_uncompressedSize, header + 11, 4);
_uncompressedSize = OF_BSWAP32_IF_BE(_uncompressedSize);
|
︙ | | | ︙ | |
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
- (OFArray OF_GENERIC(OFData *) *)extensions
{
return _extensions;
}
- (void)of_writeToStream: (OFStream *)stream
encoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFMutableData *data = [OFMutableData dataWithCapacity: 24];
const char *fileName, *directoryName;
size_t fileNameLength, directoryNameLength;
uint16_t tmp16;
uint32_t tmp32;
size_t headerSize;
if ([_compressionMethod cStringLengthWithEncoding:
OF_STRING_ENCODING_ASCII] != 5)
@throw [OFInvalidArgumentException exception];
getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength,
&directoryName, &directoryNameLength);
if (fileNameLength > UINT16_MAX - 3 ||
directoryNameLength > UINT16_MAX - 3)
@throw [OFOutOfRangeException exception];
/* Length. Filled in after we're done. */
[data increaseCountBy: 2];
[data addItems: [_compressionMethod
cStringWithEncoding: OF_STRING_ENCODING_ASCII]
count: 5];
tmp32 = OF_BSWAP32_IF_BE(_compressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
tmp32 = OF_BSWAP32_IF_BE(_uncompressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
|
|
|
|
|
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
- (OFArray OF_GENERIC(OFData *) *)extensions
{
return _extensions;
}
- (void)of_writeToStream: (OFStream *)stream
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFMutableData *data = [OFMutableData dataWithCapacity: 24];
const char *fileName, *directoryName;
size_t fileNameLength, directoryNameLength;
uint16_t tmp16;
uint32_t tmp32;
size_t headerSize;
if ([_compressionMethod cStringLengthWithEncoding:
OFStringEncodingASCII] != 5)
@throw [OFInvalidArgumentException exception];
getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength,
&directoryName, &directoryNameLength);
if (fileNameLength > UINT16_MAX - 3 ||
directoryNameLength > UINT16_MAX - 3)
@throw [OFOutOfRangeException exception];
/* Length. Filled in after we're done. */
[data increaseCountBy: 2];
[data addItems: [_compressionMethod
cStringWithEncoding: OFStringEncodingASCII]
count: 5];
tmp32 = OF_BSWAP32_IF_BE(_compressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
tmp32 = OF_BSWAP32_IF_BE(_uncompressedSize);
[data addItems: &tmp32 count: sizeof(tmp32)];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
*
* @brief A class for querying the locale and retrieving localized strings.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFLocale: OFObject
{
OFString *_Nullable _language, *_Nullable _territory;
of_string_encoding_t _encoding;
OFString *_decimalPoint;
OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
*_localizedStrings;
}
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nullable, nonatomic) OFLocale *currentLocale;
@property (class, readonly, nullable, nonatomic) OFString *language;
@property (class, readonly, nullable, nonatomic) OFString *territory;
@property (class, readonly, nonatomic) of_string_encoding_t encoding;
@property (class, readonly, nullable, nonatomic) OFString *decimalPoint;
#endif
/**
* @brief The language of the locale for messages.
*
* If the language is unknown, it is `nil`.
|
|
|
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
*
* @brief A class for querying the locale and retrieving localized strings.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFLocale: OFObject
{
OFString *_Nullable _language, *_Nullable _territory;
OFStringEncoding _encoding;
OFString *_decimalPoint;
OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *)
*_localizedStrings;
}
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nullable, nonatomic) OFLocale *currentLocale;
@property (class, readonly, nullable, nonatomic) OFString *language;
@property (class, readonly, nullable, nonatomic) OFString *territory;
@property (class, readonly, nonatomic) OFStringEncoding encoding;
@property (class, readonly, nullable, nonatomic) OFString *decimalPoint;
#endif
/**
* @brief The language of the locale for messages.
*
* If the language is unknown, it is `nil`.
|
︙ | | | ︙ | |
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
* @brief The native 8-bit string encoding of the locale for messages.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*/
@property (readonly, nonatomic) of_string_encoding_t encoding;
/**
* @brief The decimal point of the system's locale.
*/
@property (readonly, nonatomic) OFString *decimalPoint;
/**
|
|
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
* @brief The native 8-bit string encoding of the locale for messages.
*
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*/
@property (readonly, nonatomic) OFStringEncoding encoding;
/**
* @brief The decimal point of the system's locale.
*/
@property (readonly, nonatomic) OFString *decimalPoint;
/**
|
︙ | | | ︙ | |
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*
* @return The native 8-bit string encoding for the locale
*/
+ (of_string_encoding_t)encoding;
/**
* @brief Returns the decimal point of the system's locale.
*
* @return The decimal point of the system's locale
*/
+ (nullable OFString *)decimalPoint;
|
|
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
* This is useful to encode strings correctly for passing them to operating
* system calls.
*
* If the native 8-bit encoding is unknown, UTF-8 is assumed.
*
* @return The native 8-bit string encoding for the locale
*/
+ (OFStringEncoding)encoding;
/**
* @brief Returns the decimal point of the system's locale.
*
* @return The decimal point of the system's locale
*/
+ (nullable OFString *)decimalPoint;
|
︙ | | | ︙ | |
︙ | | | ︙ | |
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#endif
static OFLocale *currentLocale = nil;
static OFDictionary *operatorPrecedences = nil;
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, of_string_encoding_t *encoding,
OFString **language, OFString **territory)
{
if ((locale = of_strdup(locale)) == NULL)
return;
@try {
const of_string_encoding_t enc = OF_STRING_ENCODING_ASCII;
char *tmp;
/* We don't care for extras behind the @ */
if ((tmp = strrchr(locale, '@')) != NULL)
*tmp = '\0';
/* Encoding */
if ((tmp = strrchr(locale, '.')) != NULL) {
*tmp++ = '\0';
@try {
if (encoding != NULL)
*encoding = of_string_parse_encoding(
[OFString stringWithCString: tmp
encoding: enc]);
} @catch (OFInvalidArgumentException *e) {
}
}
/* Territory */
|
|
|
|
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#endif
static OFLocale *currentLocale = nil;
static OFDictionary *operatorPrecedences = nil;
#ifndef OF_AMIGAOS
static void
parseLocale(char *locale, OFStringEncoding *encoding,
OFString **language, OFString **territory)
{
if ((locale = of_strdup(locale)) == NULL)
return;
@try {
OFStringEncoding enc = OFStringEncodingASCII;
char *tmp;
/* We don't care for extras behind the @ */
if ((tmp = strrchr(locale, '@')) != NULL)
*tmp = '\0';
/* Encoding */
if ((tmp = strrchr(locale, '.')) != NULL) {
*tmp++ = '\0';
@try {
if (encoding != NULL)
*encoding = OFParseStringEncodingName(
[OFString stringWithCString: tmp
encoding: enc]);
} @catch (OFInvalidArgumentException *e) {
}
}
/* Territory */
|
︙ | | | ︙ | |
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
}
+ (OFString *)territory
{
return currentLocale.territory;
}
+ (of_string_encoding_t)encoding
{
return currentLocale.encoding;
}
+ (OFString *)decimalPoint
{
return currentLocale.decimalPoint;
|
|
|
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
}
+ (OFString *)territory
{
return currentLocale.territory;
}
+ (OFStringEncoding)encoding
{
return currentLocale.encoding;
}
+ (OFString *)decimalPoint
{
return currentLocale.decimalPoint;
|
︙ | | | ︙ | |
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
#ifndef OF_AMIGAOS
char *locale, *messagesLocale = NULL;
if (currentLocale != nil)
@throw [OFInitializationFailedException
exceptionWithClass: self.class];
_encoding = OF_STRING_ENCODING_UTF_8;
_decimalPoint = @".";
_localizedStrings = [[OFMutableArray alloc] init];
if ((locale = setlocale(LC_ALL, "")) != NULL)
_decimalPoint = [[OFString alloc]
initWithCString: localeconv()->decimal_point
encoding: _encoding];
|
|
|
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
#ifndef OF_AMIGAOS
char *locale, *messagesLocale = NULL;
if (currentLocale != nil)
@throw [OFInitializationFailedException
exceptionWithClass: self.class];
_encoding = OFStringEncodingUTF8;
_decimalPoint = @".";
_localizedStrings = [[OFMutableArray alloc] init];
if ((locale = setlocale(LC_ALL, "")) != NULL)
_decimalPoint = [[OFString alloc]
initWithCString: localeconv()->decimal_point
encoding: _encoding];
|
︙ | | | ︙ | |
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
|
# if defined(OF_MORPHOS)
if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) {
# elif defined(OF_AMIGAOS4)
if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) {
# else
if (0) {
# endif
of_string_encoding_t ASCII = OF_STRING_ENCODING_ASCII;
@try {
_encoding = of_string_parse_encoding(
[OFString stringWithCString: buffer
encoding: ASCII]);
} @catch (OFInvalidArgumentException *e) {
_encoding = OF_STRING_ENCODING_ISO_8859_1;
}
} else
_encoding = OF_STRING_ENCODING_ISO_8859_1;
/*
* Get it via localeconv() instead of from the Locale struct,
* to make sure we and printf etc. have the same expectations.
*/
_decimalPoint = [[OFString alloc]
initWithCString: localeconv()->decimal_point
|
|
|
|
|
|
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
|
# if defined(OF_MORPHOS)
if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) {
# elif defined(OF_AMIGAOS4)
if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) {
# else
if (0) {
# endif
OFStringEncoding ASCII = OFStringEncodingASCII;
@try {
_encoding = OFStringEncodingForName(
[OFString stringWithCString: buffer
encoding: ASCII]);
} @catch (OFInvalidArgumentException *e) {
_encoding = OFStringEncodingISO8859_1;
}
} else
_encoding = OFStringEncodingISO8859_1;
/*
* Get it via localeconv() instead of from the Locale struct,
* to make sure we and printf etc. have the same expectations.
*/
_decimalPoint = [[OFString alloc]
initWithCString: localeconv()->decimal_point
|
︙ | | | ︙ | |
︙ | | | ︙ | |
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
* matches the length of the specified data on the
* asynchronous write if no exception was encountered.
* @param exception An exception that occurred while writing, or nil on success
* @return The string to repeat the write with or nil if it should not repeat
*/
- (nullable OFString *)stream: (OFStream *)stream
didWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
bytesWritten: (size_t)bytesWritten
exception: (nullable id)exception;
@end
/**
* @class OFStream OFStream.h ObjFW/OFStream.h
*
|
|
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
* matches the length of the specified data on the
* asynchronous write if no exception was encountered.
* @param exception An exception that occurred while writing, or nil on success
* @return The string to repeat the write with or nil if it should not repeat
*/
- (nullable OFString *)stream: (OFStream *)stream
didWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
bytesWritten: (size_t)bytesWritten
exception: (nullable id)exception;
@end
/**
* @class OFStream OFStream.h ObjFW/OFStream.h
*
|
︙ | | | ︙ | |
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
* Otherwise you will get an exception!
*
* @param encoding The encoding of the string to read from the stream
* @param length The length (in bytes) of the string to read from the stream
* @return A string with the specified length
*/
- (OFString *)readStringWithLength: (size_t)length
encoding: (of_string_encoding_t)encoding;
/**
* @brief Reads until a newline, `\0` or end of stream occurs.
*
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readLine;
/**
* @brief Reads with the specified encoding until a newline, `\0` or end of
* stream occurs.
*
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readLineWithEncoding: (of_string_encoding_t)encoding;
#ifdef OF_HAVE_SOCKETS
/**
* @brief Asynchronously reads until a newline, `\0`, end of stream or an
* exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*/
- (void)asyncReadLine;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
*/
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
* @param runLoopMode The run loop mode in which to perform the async read
*/
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode;
# ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously reads until a newline, `\0`, end of stream or an
* exception occurs.
*
|
|
|
|
|
|
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
* Otherwise you will get an exception!
*
* @param encoding The encoding of the string to read from the stream
* @param length The length (in bytes) of the string to read from the stream
* @return A string with the specified length
*/
- (OFString *)readStringWithLength: (size_t)length
encoding: (OFStringEncoding)encoding;
/**
* @brief Reads until a newline, `\0` or end of stream occurs.
*
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readLine;
/**
* @brief Reads with the specified encoding until a newline, `\0` or end of
* stream occurs.
*
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readLineWithEncoding: (OFStringEncoding)encoding;
#ifdef OF_HAVE_SOCKETS
/**
* @brief Asynchronously reads until a newline, `\0`, end of stream or an
* exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*/
- (void)asyncReadLine;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
*/
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
* @param runLoopMode The run loop mode in which to perform the async read
*/
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode;
# ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously reads until a newline, `\0`, end of stream or an
* exception occurs.
*
|
︙ | | | ︙ | |
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
* @param encoding The encoding used by the stream
* @param block The block to call when the data has been received.
* If the block returns true, it will be called again when the next
* line has been received. If you want the next block in the queue
* to handle the next line, you need to return false from the
* block.
*/
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
block: (of_stream_async_read_line_block_t)block;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
* @param runLoopMode The run loop mode in which to perform the async read
* @param block The block to call when the data has been received.
* If the block returns true, it will be called again when the next
* line has been received. If you want the next block in the queue
* to handle the next line, you need to return false from the
* block.
*/
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_read_line_block_t)block;
# endif
#endif
/**
* @brief Tries to read a line from the stream (see @ref readLine) and returns
|
|
|
|
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
* @param encoding The encoding used by the stream
* @param block The block to call when the data has been received.
* If the block returns true, it will be called again when the next
* line has been received. If you want the next block in the queue
* to handle the next line, you need to return false from the
* block.
*/
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
block: (of_stream_async_read_line_block_t)block;
/**
* @brief Asynchronously reads with the specified encoding until a newline,
* `\0`, end of stream or an exception occurs.
*
* @note The stream must conform to @ref OFReadyForReadingObserving in order
* for this to work!
*
* @param encoding The encoding used by the stream
* @param runLoopMode The run loop mode in which to perform the async read
* @param block The block to call when the data has been received.
* If the block returns true, it will be called again when the next
* line has been received. If you want the next block in the queue
* to handle the next line, you need to return false from the
* block.
*/
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_read_line_block_t)block;
# endif
#endif
/**
* @brief Tries to read a line from the stream (see @ref readLine) and returns
|
︙ | | | ︙ | |
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
* @ref readLineWithEncoding:) and returns `nil` if no complete line has
* been received yet.
*
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the line is not
* complete yet
*/
- (nullable OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding;
/**
* @brief Reads until the specified string or `\0` is found or the end of
* stream occurs.
*
* @param delimiter The delimiter
* @return The line that was read, autoreleased, or `nil` if the end of the
|
|
|
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
|
* @ref readLineWithEncoding:) and returns `nil` if no complete line has
* been received yet.
*
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the line is not
* complete yet
*/
- (nullable OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding;
/**
* @brief Reads until the specified string or `\0` is found or the end of
* stream occurs.
*
* @param delimiter The delimiter
* @return The line that was read, autoreleased, or `nil` if the end of the
|
︙ | | | ︙ | |
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
|
*
* @param delimiter The delimiter
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding;
/**
* @brief Tries to reads until the specified string or `\0` is found or the end
* of stream (see @ref readTillDelimiter:) and returns `nil` if not
* enough data has been received yet.
*
* @param delimiter The delimiter
|
|
|
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
|
*
* @param delimiter The delimiter
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (OFStringEncoding)encoding;
/**
* @brief Tries to reads until the specified string or `\0` is found or the end
* of stream (see @ref readTillDelimiter:) and returns `nil` if not
* enough data has been received yet.
*
* @param delimiter The delimiter
|
︙ | | | ︙ | |
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
|
*
* @param delimiter The delimiter
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)tryReadTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding;
/**
* @brief Writes everything in the write buffer to the stream.
*/
- (void)flushWriteBuffer;
/**
|
|
|
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
|
*
* @param delimiter The delimiter
* @param encoding The encoding used by the stream
* @return The line that was read, autoreleased, or `nil` if the end of the
* stream has been reached.
*/
- (nullable OFString *)tryReadTillDelimiter: (OFString *)delimiter
encoding: (OFStringEncoding)encoding;
/**
* @brief Writes everything in the write buffer to the stream.
*/
- (void)flushWriteBuffer;
/**
|
︙ | | | ︙ | |
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
|
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
*/
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding;
/**
* @brief Asynchronously writes a string in the specified encoding into the
* stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
* @param runLoopMode The run loop mode in which to perform the async write
*/
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode;
# ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously writes data into the stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
|
|
|
|
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
|
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
*/
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding;
/**
* @brief Asynchronously writes a string in the specified encoding into the
* stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
* @param runLoopMode The run loop mode in which to perform the async write
*/
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode;
# ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously writes data into the stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
|
︙ | | | ︙ | |
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
|
* @param encoding The encoding in which the string should be written to the
* stream
* @param block The block to call when the string has been written. It should
* return the string for the next write with the same callback or
* nil if it should not repeat.
*/
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
block: (of_stream_async_write_string_block_t)block;
/**
* @brief Asynchronously writes a string in the specified encoding into the
* stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
* @param runLoopMode The run loop mode in which to perform the async write
* @param block The block to call when the string has been written. It should
* return the string for the next write with the same callback or
* nil if it should not repeat.
*/
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_write_string_block_t)block;
# endif
#endif
/**
* @brief Writes a uint8_t into the stream.
|
|
|
|
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
|
* @param encoding The encoding in which the string should be written to the
* stream
* @param block The block to call when the string has been written. It should
* return the string for the next write with the same callback or
* nil if it should not repeat.
*/
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
block: (of_stream_async_write_string_block_t)block;
/**
* @brief Asynchronously writes a string in the specified encoding into the
* stream.
*
* @note The stream must conform to @ref OFReadyForWritingObserving in order
* for this to work!
*
* @param string The string which is written into the stream
* @param encoding The encoding in which the string should be written to the
* stream
* @param runLoopMode The run loop mode in which to perform the async write
* @param block The block to call when the string has been written. It should
* return the string for the next write with the same callback or
* nil if it should not repeat.
*/
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_write_string_block_t)block;
# endif
#endif
/**
* @brief Writes a uint8_t into the stream.
|
︙ | | | ︙ | |
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
|
* @brief Writes a string into the stream in the specified encoding, without
* the trailing zero.
*
* @param string The string from which the data is written to the stream
* @param encoding The encoding in which to write the string to the stream
* @return The number of bytes written
*/
- (size_t)writeString: (OFString *)string
encoding: (of_string_encoding_t)encoding;
/**
* @brief Writes a string into the stream with a trailing newline.
*
* @param string The string from which the data is written to the stream
* @return The number of bytes written
*/
- (size_t)writeLine: (OFString *)string;
/**
* @brief Writes a string into the stream in the specified encoding with a
* trailing newline.
*
* @param string The string from which the data is written to the stream
* @param encoding The encoding in which to write the string to the stream
* @return The number of bytes written
*/
- (size_t)writeLine: (OFString *)string
encoding: (of_string_encoding_t)encoding;
/**
* @brief Writes a formatted string into the stream.
*
* See printf for the format syntax. As an addition, `%@` is available as
* format specifier for objects, `%C` for `OFUnichar` and `%S` for
* `const OFUnichar *`.
|
|
<
|
<
|
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
|
* @brief Writes a string into the stream in the specified encoding, without
* the trailing zero.
*
* @param string The string from which the data is written to the stream
* @param encoding The encoding in which to write the string to the stream
* @return The number of bytes written
*/
- (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding;
/**
* @brief Writes a string into the stream with a trailing newline.
*
* @param string The string from which the data is written to the stream
* @return The number of bytes written
*/
- (size_t)writeLine: (OFString *)string;
/**
* @brief Writes a string into the stream in the specified encoding with a
* trailing newline.
*
* @param string The string from which the data is written to the stream
* @param encoding The encoding in which to write the string to the stream
* @return The number of bytes written
*/
- (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding;
/**
* @brief Writes a formatted string into the stream.
*
* See printf for the format syntax. As an addition, `%@` is available as
* format specifier for objects, `%C` for `OFUnichar` and `%S` for
* `const OFUnichar *`.
|
︙ | | | ︙ | |
︙ | | | ︙ | |
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
649
650
651
652
|
[data makeImmutable];
return data;
}
- (OFString *)readStringWithLength: (size_t)length
{
return [self readStringWithLength: length
encoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString *)readStringWithLength: (size_t)length
encoding: (of_string_encoding_t)encoding
{
OFString *ret;
char *buffer = of_alloc(length + 1, 1);
buffer[length] = 0;
@try {
[self readIntoBuffer: buffer exactLength: length];
ret = [OFString stringWithCString: buffer encoding: encoding];
} @finally {
free(buffer);
}
return ret;
}
- (OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding
{
size_t pageSize, bufferLength;
char *buffer, *readBuffer;
OFString *ret;
/* Look if there's a line or \0 in our buffer */
if (!_waitingForDelimiter && _readBuffer != NULL) {
|
|
|
|
|
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
649
650
651
652
|
[data makeImmutable];
return data;
}
- (OFString *)readStringWithLength: (size_t)length
{
return [self readStringWithLength: length
encoding: OFStringEncodingUTF8];
}
- (OFString *)readStringWithLength: (size_t)length
encoding: (OFStringEncoding)encoding
{
OFString *ret;
char *buffer = of_alloc(length + 1, 1);
buffer[length] = 0;
@try {
[self readIntoBuffer: buffer exactLength: length];
ret = [OFString stringWithCString: buffer encoding: encoding];
} @finally {
free(buffer);
}
return ret;
}
- (OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding
{
size_t pageSize, bufferLength;
char *buffer, *readBuffer;
OFString *ret;
/* Look if there's a line or \0 in our buffer */
if (!_waitingForDelimiter && _readBuffer != NULL) {
|
︙ | | | ︙ | |
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
|
_waitingForDelimiter = true;
return nil;
}
- (OFString *)readLine
{
return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString *)readLineWithEncoding: (of_string_encoding_t)encoding
{
OFString *line = nil;
while ((line = [self tryReadLineWithEncoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return line;
}
#ifdef OF_HAVE_SOCKETS
- (void)asyncReadLine
{
[self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
{
[self asyncReadLineWithEncoding: encoding
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
{
OFStream <OFReadyForReadingObserving> *stream =
(OFStream <OFReadyForReadingObserving> *)self;
[OFRunLoop of_addAsyncReadLineForStream: stream
encoding: encoding
mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
block: NULL
# endif
delegate: _delegate];
}
# ifdef OF_HAVE_BLOCKS
- (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block
{
[self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
block: (of_stream_async_read_line_block_t)block
{
[self asyncReadLineWithEncoding: encoding
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_read_line_block_t)block
{
OFStream <OFReadyForReadingObserving> *stream =
(OFStream <OFReadyForReadingObserving> *)self;
[OFRunLoop of_addAsyncReadLineForStream: stream
encoding: encoding
mode: runLoopMode
block: block
delegate: nil];
}
# endif
#endif
- (OFString *)tryReadLine
{
return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding
{
const char *delimiterCString;
size_t j, delimiterLength, pageSize, bufferLength;
char *buffer, *readBuffer;
OFString *ret;
delimiterCString = [delimiter cStringWithEncoding: encoding];
|
|
|
|
|
|
|
|
|
|
|
|
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
|
_waitingForDelimiter = true;
return nil;
}
- (OFString *)readLine
{
return [self readLineWithEncoding: OFStringEncodingUTF8];
}
- (OFString *)readLineWithEncoding: (OFStringEncoding)encoding
{
OFString *line = nil;
while ((line = [self tryReadLineWithEncoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return line;
}
#ifdef OF_HAVE_SOCKETS
- (void)asyncReadLine
{
[self asyncReadLineWithEncoding: OFStringEncodingUTF8
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
{
[self asyncReadLineWithEncoding: encoding
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
{
OFStream <OFReadyForReadingObserving> *stream =
(OFStream <OFReadyForReadingObserving> *)self;
[OFRunLoop of_addAsyncReadLineForStream: stream
encoding: encoding
mode: runLoopMode
# ifdef OF_HAVE_BLOCKS
block: NULL
# endif
delegate: _delegate];
}
# ifdef OF_HAVE_BLOCKS
- (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block
{
[self asyncReadLineWithEncoding: OFStringEncodingUTF8
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
block: (of_stream_async_read_line_block_t)block
{
[self asyncReadLineWithEncoding: encoding
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_read_line_block_t)block
{
OFStream <OFReadyForReadingObserving> *stream =
(OFStream <OFReadyForReadingObserving> *)self;
[OFRunLoop of_addAsyncReadLineForStream: stream
encoding: encoding
mode: runLoopMode
block: block
delegate: nil];
}
# endif
#endif
- (OFString *)tryReadLine
{
return [self tryReadLineWithEncoding: OFStringEncodingUTF8];
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
encoding: (OFStringEncoding)encoding
{
const char *delimiterCString;
size_t j, delimiterLength, pageSize, bufferLength;
char *buffer, *readBuffer;
OFString *ret;
delimiterCString = [delimiter cStringWithEncoding: encoding];
|
︙ | | | ︙ | |
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
return nil;
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
{
return [self readTillDelimiter: delimiter
encoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding
{
OFString *ret = nil;
while ((ret = [self tryReadTillDelimiter: delimiter
encoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return ret;
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
return [self tryReadTillDelimiter: delimiter
encoding: OF_STRING_ENCODING_UTF_8];
}
- (void)flushWriteBuffer
{
if (_writeBuffer == NULL)
return;
|
|
|
|
|
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
return nil;
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
{
return [self readTillDelimiter: delimiter
encoding: OFStringEncodingUTF8];
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (OFStringEncoding)encoding
{
OFString *ret = nil;
while ((ret = [self tryReadTillDelimiter: delimiter
encoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return ret;
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
return [self tryReadTillDelimiter: delimiter
encoding: OFStringEncodingUTF8];
}
- (void)flushWriteBuffer
{
if (_writeBuffer == NULL)
return;
|
︙ | | | ︙ | |
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
|
# endif
delegate: _delegate];
}
- (void)asyncWriteString: (OFString *)string
{
[self asyncWriteString: string
encoding: OF_STRING_ENCODING_UTF_8
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
{
[self asyncWriteString: string
encoding: encoding
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
{
OFStream <OFReadyForWritingObserving> *stream =
(OFStream <OFReadyForWritingObserving> *)self;
[OFRunLoop of_addAsyncWriteForStream: stream
string: string
|
|
|
|
|
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
|
# endif
delegate: _delegate];
}
- (void)asyncWriteString: (OFString *)string
{
[self asyncWriteString: string
encoding: OFStringEncodingUTF8
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
{
[self asyncWriteString: string
encoding: encoding
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
{
OFStream <OFReadyForWritingObserving> *stream =
(OFStream <OFReadyForWritingObserving> *)self;
[OFRunLoop of_addAsyncWriteForStream: stream
string: string
|
︙ | | | ︙ | |
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
|
delegate: nil];
}
- (void)asyncWriteString: (OFString *)string
block: (of_stream_async_write_string_block_t)block
{
[self asyncWriteString: string
encoding: OF_STRING_ENCODING_UTF_8
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
block: (of_stream_async_write_string_block_t)block
{
[self asyncWriteString: string
encoding: encoding
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncWriteString: (OFString *)string
encoding: (of_string_encoding_t)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_write_string_block_t)block
{
OFStream <OFReadyForWritingObserving> *stream =
(OFStream <OFReadyForWritingObserving> *)self;
[OFRunLoop of_addAsyncWriteForStream: stream
|
|
|
|
|
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
|
delegate: nil];
}
- (void)asyncWriteString: (OFString *)string
block: (of_stream_async_write_string_block_t)block
{
[self asyncWriteString: string
encoding: OFStringEncodingUTF8
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
block: (of_stream_async_write_string_block_t)block
{
[self asyncWriteString: string
encoding: encoding
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncWriteString: (OFString *)string
encoding: (OFStringEncoding)encoding
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_stream_async_write_string_block_t)block
{
OFStream <OFReadyForWritingObserving> *stream =
(OFStream <OFReadyForWritingObserving> *)self;
[OFRunLoop of_addAsyncWriteForStream: stream
|
︙ | | | ︙ | |
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
|
objc_autoreleasePoolPop(pool);
return length;
}
- (size_t)writeString: (OFString *)string
{
return [self writeString: string encoding: OF_STRING_ENCODING_UTF_8];
}
- (size_t)writeString: (OFString *)string
encoding: (of_string_encoding_t)encoding
{
void *pool;
size_t length;
if (string == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
length = [string cStringLengthWithEncoding: encoding];
[self writeBuffer: [string cStringWithEncoding: encoding]
length: length];
objc_autoreleasePoolPop(pool);
return length;
}
- (size_t)writeLine: (OFString *)string
{
return [self writeLine: string encoding: OF_STRING_ENCODING_UTF_8];
}
- (size_t)writeLine: (OFString *)string encoding: (of_string_encoding_t)encoding
{
size_t stringLength = [string cStringLengthWithEncoding: encoding];
char *buffer;
buffer = of_alloc(stringLength + 1, 1);
@try {
|
|
|
<
|
|
|
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
|
objc_autoreleasePoolPop(pool);
return length;
}
- (size_t)writeString: (OFString *)string
{
return [self writeString: string encoding: OFStringEncodingUTF8];
}
- (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding
{
void *pool;
size_t length;
if (string == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
length = [string cStringLengthWithEncoding: encoding];
[self writeBuffer: [string cStringWithEncoding: encoding]
length: length];
objc_autoreleasePoolPop(pool);
return length;
}
- (size_t)writeLine: (OFString *)string
{
return [self writeLine: string encoding: OFStringEncodingUTF8];
}
- (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding
{
size_t stringLength = [string cStringLengthWithEncoding: encoding];
char *buffer;
buffer = of_alloc(stringLength + 1, 1);
@try {
|
︙ | | | ︙ | |
︙ | | | ︙ | |
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
typedef uint_least32_t OFChar32;
#endif
typedef OFChar32 OFUnichar;
/**
* @brief The encoding of a string.
*/
typedef enum of_string_encoding_t {
/*
* UTF-8 *has* to be 0, so that if the current @ref OFLocale is
* `nil`, `[OFLocale encoding]` returns UTF-8.
*/
/** UTF-8 */
OF_STRING_ENCODING_UTF_8,
/** ASCII */
OF_STRING_ENCODING_ASCII,
/** ISO 8859-1 */
OF_STRING_ENCODING_ISO_8859_1,
/** ISO 8859-2 */
OF_STRING_ENCODING_ISO_8859_2,
/** ISO 8859-3 */
OF_STRING_ENCODING_ISO_8859_3,
/** ISO 8859-15 */
OF_STRING_ENCODING_ISO_8859_15,
/** Windows-1251 */
OF_STRING_ENCODING_WINDOWS_1251,
/** Windows-1252 */
OF_STRING_ENCODING_WINDOWS_1252,
/** Codepage 437 */
OF_STRING_ENCODING_CODEPAGE_437,
/** Codepage 850 */
OF_STRING_ENCODING_CODEPAGE_850,
/** Codepage 858 */
OF_STRING_ENCODING_CODEPAGE_858,
/** Mac OS Roman */
OF_STRING_ENCODING_MAC_ROMAN,
/** KOI8-R */
OF_STRING_ENCODING_KOI8_R,
/** KOI8-U */
OF_STRING_ENCODING_KOI8_U,
/** Try to automatically detect the encoding */
OF_STRING_ENCODING_AUTODETECT = 0xFF
} of_string_encoding_t;
enum {
OF_STRING_SEARCH_BACKWARDS = 1,
OF_STRING_SKIP_EMPTY = 2
};
#ifdef OF_HAVE_BLOCKS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
typedef uint_least32_t OFChar32;
#endif
typedef OFChar32 OFUnichar;
/**
* @brief The encoding of a string.
*/
typedef enum OFStringEncoding {
/*
* UTF-8 *has* to be 0, so that if the current @ref OFLocale is
* `nil`, `[OFLocale encoding]` returns UTF-8.
*/
/** UTF-8 */
OFStringEncodingUTF8,
/** ASCII */
OFStringEncodingASCII,
/** ISO 8859-1 */
OFStringEncodingISO8859_1,
/** ISO 8859-2 */
OFStringEncodingISO8859_2,
/** ISO 8859-3 */
OFStringEncodingISO8859_3,
/** ISO 8859-15 */
OFStringEncodingISO8859_15,
/** Windows-1251 */
OFStringEncodingWindows1251,
/** Windows-1252 */
OFStringEncodingWindows1252,
/** Codepage 437 */
OFStringEncodingCodepage437,
/** Codepage 850 */
OFStringEncodingCodepage850,
/** Codepage 858 */
OFStringEncodingCodepage858,
/** Mac OS Roman */
OFStringEncodingMacRoman,
/** KOI8-R */
OFStringEncodingKOI8R,
/** KOI8-U */
OFStringEncodingKOI8U,
/** Try to automatically detect the encoding */
OFStringEncodingAutodetect = 0xFF
} OFStringEncoding;
enum {
OF_STRING_SEARCH_BACKWARDS = 1,
OF_STRING_SKIP_EMPTY = 2
};
#ifdef OF_HAVE_BLOCKS
|
︙ | | | ︙ | |
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
* @brief Creates a new OFString from a C string with the specified encoding.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding;
/**
* @brief Creates a new OFString from a C string with the specified encoding
* and length.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @param cStringLength The length of the C string
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength;
/**
* @brief Creates a new OFString from OFData with the specified encoding.
*
* @param data OFData with the contents of the string
* @param encoding The encoding in which the string is stored in the OFData
* @return An new autoreleased OFString
*/
+ (instancetype)stringWithData: (OFData *)data
encoding: (of_string_encoding_t)encoding;
/**
* @brief Creates a new OFString from another string.
*
* @param string A string to initialize the OFString with
* @return A new autoreleased OFString
*/
|
|
|
|
|
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
* @brief Creates a new OFString from a C string with the specified encoding.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding;
/**
* @brief Creates a new OFString from a C string with the specified encoding
* and length.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @param cStringLength The length of the C string
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength;
/**
* @brief Creates a new OFString from OFData with the specified encoding.
*
* @param data OFData with the contents of the string
* @param encoding The encoding in which the string is stored in the OFData
* @return An new autoreleased OFString
*/
+ (instancetype)stringWithData: (OFData *)data
encoding: (OFStringEncoding)encoding;
/**
* @brief Creates a new OFString from another string.
*
* @param string A string to initialize the OFString with
* @return A new autoreleased OFString
*/
|
︙ | | | ︙ | |
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
* specified encoding.
*
* @param path The path to the file
* @param encoding The encoding of the file
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithContentsOfFile: (OFString *)path
encoding: (of_string_encoding_t)encoding;
# endif
/**
* @brief Creates a new OFString with the contents of the specified URL.
*
* If the URL's scheme is file, it tries UTF-8 encoding.
*
|
|
|
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
|
* specified encoding.
*
* @param path The path to the file
* @param encoding The encoding of the file
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding;
# endif
/**
* @brief Creates a new OFString with the contents of the specified URL.
*
* If the URL's scheme is file, it tries UTF-8 encoding.
*
|
︙ | | | ︙ | |
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
* specified encoding.
*
* @param URL The URL to the contents for the string
* @param encoding The encoding to assume
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
encoding: (of_string_encoding_t)encoding;
/**
* @brief Initializes an already allocated OFString from a UTF-8 encoded C
* string.
*
* @param UTF8String A UTF-8 encoded C string to initialize the OFString with
* @return An initialized OFString
|
|
|
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
* specified encoding.
*
* @param URL The URL to the contents for the string
* @param encoding The encoding to assume
* @return A new autoreleased OFString
*/
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
encoding: (OFStringEncoding)encoding;
/**
* @brief Initializes an already allocated OFString from a UTF-8 encoded C
* string.
*
* @param UTF8String A UTF-8 encoded C string to initialize the OFString with
* @return An initialized OFString
|
︙ | | | ︙ | |
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
|
* specified encoding.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @return An initialized OFString
*/
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding;
/**
* @brief Initializes an already allocated OFString from a C string with the
* specified encoding and length.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @param cStringLength The length of the C string
* @return An initialized OFString
*/
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength;
/**
* @brief Initializes an already allocated OFString from OFData with the
* specified encoding.
*
* @param data OFData with the contents of the string
* @param encoding The encoding in which the string is stored in the OFData
* @return An initialized OFString
*/
- (instancetype)initWithData: (OFData *)data
encoding: (of_string_encoding_t)encoding;
/**
* @brief Initializes an already allocated OFString with another string.
*
* @param string A string to initialize the OFString with
* @return An initialized OFString
*/
|
|
|
|
|
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
|
* specified encoding.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @return An initialized OFString
*/
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding;
/**
* @brief Initializes an already allocated OFString from a C string with the
* specified encoding and length.
*
* @param cString A C string to initialize the OFString with
* @param encoding The encoding of the C string
* @param cStringLength The length of the C string
* @return An initialized OFString
*/
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength;
/**
* @brief Initializes an already allocated OFString from OFData with the
* specified encoding.
*
* @param data OFData with the contents of the string
* @param encoding The encoding in which the string is stored in the OFData
* @return An initialized OFString
*/
- (instancetype)initWithData: (OFData *)data
encoding: (OFStringEncoding)encoding;
/**
* @brief Initializes an already allocated OFString with another string.
*
* @param string A string to initialize the OFString with
* @return An initialized OFString
*/
|
︙ | | | ︙ | |
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
* specified file in the specified encoding.
*
* @param path The path to the file
* @param encoding The encoding of the file
* @return An initialized OFString
*/
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (of_string_encoding_t)encoding;
# endif
/**
* @brief Initializes an already allocated OFString with the contents of the
* specified URL.
*
* If the URL's scheme is file, it tries UTF-8 encoding.
|
|
|
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
* specified file in the specified encoding.
*
* @param path The path to the file
* @param encoding The encoding of the file
* @return An initialized OFString
*/
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding;
# endif
/**
* @brief Initializes an already allocated OFString with the contents of the
* specified URL.
*
* If the URL's scheme is file, it tries UTF-8 encoding.
|
︙ | | | ︙ | |
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
* specified URL in the specified encoding.
*
* @param URL The URL to the contents for the string
* @param encoding The encoding to assume
* @return An initialized OFString
*/
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (of_string_encoding_t)encoding;
/**
* @brief Writes the OFString into the specified C string with the specified
* encoding.
*
* @param cString The C string to write into
* @param maxLength The maximum number of bytes to write into the C string,
* including the terminating zero
* @param encoding The encoding to use for writing into the C string
* @return The number of bytes written into the C string, without the
* terminating zero
*/
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding;
/**
* @brief Writes the OFString into the specified C string with the specified
* encoding, replacing characters that cannot be represented in the
* specified encoding with a question mark.
*
* @param cString The C string to write into
* @param maxLength The maximum number of bytes to write into the C string,
* including the terminating zero
* @param encoding The encoding to use for writing into the C string
* @return The number of bytes written into the C string, without the
* terminating zero
*/
- (size_t)getLossyCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding;
/**
* @brief Returns the OFString as a C string in the specified encoding.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
*
* @param encoding The encoding for the C string
* @return The OFString as a C string in the specified encoding
*/
- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding
OF_RETURNS_INNER_POINTER;
/**
* @brief Returns the OFString as a C string in the specified encoding,
* replacing characters that cannot be represented in the specified
* encoding with a question mark.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
*
* @param encoding The encoding for the C string
* @return The OFString as a C string in the specified encoding
*/
- (const char *)lossyCStringWithEncoding: (of_string_encoding_t)encoding
OF_RETURNS_INNER_POINTER;
/**
* @brief Returns the number of bytes the string needs in the specified
* encoding.
*
* @param encoding The encoding for the string
* @return The number of bytes the string needs in the specified encoding.
*/
- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding;
/**
* @brief Compares the string to another string.
*
* @param string The string to compare the string to
* @return The result of the comparison
*/
|
|
|
|
|
|
|
|
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
* specified URL in the specified encoding.
*
* @param URL The URL to the contents for the string
* @param encoding The encoding to assume
* @return An initialized OFString
*/
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (OFStringEncoding)encoding;
/**
* @brief Writes the OFString into the specified C string with the specified
* encoding.
*
* @param cString The C string to write into
* @param maxLength The maximum number of bytes to write into the C string,
* including the terminating zero
* @param encoding The encoding to use for writing into the C string
* @return The number of bytes written into the C string, without the
* terminating zero
*/
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding;
/**
* @brief Writes the OFString into the specified C string with the specified
* encoding, replacing characters that cannot be represented in the
* specified encoding with a question mark.
*
* @param cString The C string to write into
* @param maxLength The maximum number of bytes to write into the C string,
* including the terminating zero
* @param encoding The encoding to use for writing into the C string
* @return The number of bytes written into the C string, without the
* terminating zero
*/
- (size_t)getLossyCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding;
/**
* @brief Returns the OFString as a C string in the specified encoding.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
*
* @param encoding The encoding for the C string
* @return The OFString as a C string in the specified encoding
*/
- (const char *)cStringWithEncoding: (OFStringEncoding)encoding
OF_RETURNS_INNER_POINTER;
/**
* @brief Returns the OFString as a C string in the specified encoding,
* replacing characters that cannot be represented in the specified
* encoding with a question mark.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
*
* @param encoding The encoding for the C string
* @return The OFString as a C string in the specified encoding
*/
- (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding
OF_RETURNS_INNER_POINTER;
/**
* @brief Returns the number of bytes the string needs in the specified
* encoding.
*
* @param encoding The encoding for the string
* @return The number of bytes the string needs in the specified encoding.
*/
- (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding;
/**
* @brief Compares the string to another string.
*
* @param string The string to compare the string to
* @return The result of the comparison
*/
|
︙ | | | ︙ | |
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
|
/**
* @brief Returns the string as OFData with the specified encoding.
*
* @param encoding The encoding to use for the returned OFData
* @return The string as OFData with the specified encoding
*/
- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding;
# ifdef OF_HAVE_FILES
/**
* @brief Writes the string into the specified file using UTF-8 encoding.
*
* @param path The path of the file to write to
*/
- (void)writeToFile: (OFString *)path;
/**
* @brief Writes the string into the specified file using the specified
* encoding.
*
* @param path The path of the file to write to
* @param encoding The encoding to use to write the string into the file
*/
- (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding;
# endif
/**
* @brief Writes the string to the specified URL using UTF-8 encoding.
*
* @param URL The URL to write to
*/
- (void)writeToURL: (OFURL *)URL;
/**
* @brief Writes the string to the specified URL using the specified encoding.
*
* @param URL The URL to write to
* @param encoding The encoding to use to write the string to the URL
*/
- (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding;
# ifdef OF_HAVE_BLOCKS
/**
* Enumerates all lines in the receiver using the specified block.
*
* @brief block The block to call for each line
*/
- (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block;
# endif
@end
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern of_string_encoding_t of_string_parse_encoding(OFString *);
extern OFString *_Nullable of_string_name_of_encoding(of_string_encoding_t);
extern size_t of_string_utf8_encode(OFUnichar, char *);
extern ssize_t of_string_utf8_decode(const char *, size_t, OFUnichar *);
extern size_t of_string_utf16_length(const OFChar16 *);
extern size_t of_string_utf32_length(const OFChar32 *);
#ifdef __cplusplus
}
#endif
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>
|
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
|
/**
* @brief Returns the string as OFData with the specified encoding.
*
* @param encoding The encoding to use for the returned OFData
* @return The string as OFData with the specified encoding
*/
- (OFData *)dataWithEncoding: (OFStringEncoding)encoding;
# ifdef OF_HAVE_FILES
/**
* @brief Writes the string into the specified file using UTF-8 encoding.
*
* @param path The path of the file to write to
*/
- (void)writeToFile: (OFString *)path;
/**
* @brief Writes the string into the specified file using the specified
* encoding.
*
* @param path The path of the file to write to
* @param encoding The encoding to use to write the string into the file
*/
- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding;
# endif
/**
* @brief Writes the string to the specified URL using UTF-8 encoding.
*
* @param URL The URL to write to
*/
- (void)writeToURL: (OFURL *)URL;
/**
* @brief Writes the string to the specified URL using the specified encoding.
*
* @param URL The URL to write to
* @param encoding The encoding to use to write the string to the URL
*/
- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding;
# ifdef OF_HAVE_BLOCKS
/**
* Enumerates all lines in the receiver using the specified block.
*
* @brief block The block to call for each line
*/
- (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block;
# endif
@end
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Parses the specified string encoding name and returns the
* OFStringEncoding for it.
*
* Throws @ref OFInvalidArgumentException if the specified name is not a valid
* encoding name.
*
* @param name The name to parse as a string encoding
* @return The OFStringEncoding for the specified name
*/
extern OFStringEncoding OFParseStringEncodingName(OFString *name);
/**
* @brief Returns the name of the specified OFStringEncoding.
*
* @param encoding The encoding for which to return the name
* @return The name of the specified OFStringEncoding
*/
extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding);
extern size_t of_string_utf8_encode(OFUnichar, char *);
extern ssize_t of_string_utf8_decode(const char *, size_t, OFUnichar *);
extern size_t of_string_utf16_length(const OFChar16 *);
extern size_t of_string_utf32_length(const OFChar32 *);
#ifdef __cplusplus
}
#endif
|
︙ | | | ︙ | |
︙ | | | ︙ | |
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
static locale_t cLocale;
#endif
@interface OFString ()
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding
lossy: (bool)lossy OF_DIRECT;
- (const char *)of_cStringWithEncoding: (of_string_encoding_t)encoding
lossy: (bool)lossy OF_DIRECT;
- (OFString *)of_JSONRepresentationWithOptions: (int)options
depth: (size_t)depth;
@end
@interface OFStringPlaceholder: OFString
@end
|
|
|
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
static locale_t cLocale;
#endif
@interface OFString ()
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
lossy: (bool)lossy OF_DIRECT;
- (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding
lossy: (bool)lossy OF_DIRECT;
- (OFString *)of_JSONRepresentationWithOptions: (int)options
depth: (size_t)depth;
@end
@interface OFStringPlaceholder: OFString
@end
|
︙ | | | ︙ | |
141
142
143
144
145
146
147
148
149
150
151
152
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
void
_reference_to_OFConstantString(void)
{
[OFConstantString class];
}
of_string_encoding_t
of_string_parse_encoding(OFString *string)
{
void *pool = objc_autoreleasePoolPush();
of_string_encoding_t encoding;
string = string.lowercaseString;
if ([string isEqual: @"utf8"] || [string isEqual: @"utf-8"])
encoding = OF_STRING_ENCODING_UTF_8;
else if ([string isEqual: @"ascii"] || [string isEqual: @"us-ascii"])
encoding = OF_STRING_ENCODING_ASCII;
else if ([string isEqual: @"iso-8859-1"] ||
[string isEqual: @"iso_8859-1"])
encoding = OF_STRING_ENCODING_ISO_8859_1;
else if ([string isEqual: @"iso-8859-2"] ||
[string isEqual: @"iso_8859-2"])
encoding = OF_STRING_ENCODING_ISO_8859_2;
else if ([string isEqual: @"iso-8859-3"] ||
[string isEqual: @"iso_8859-3"])
encoding = OF_STRING_ENCODING_ISO_8859_3;
else if ([string isEqual: @"iso-8859-15"] ||
[string isEqual: @"iso_8859-15"])
encoding = OF_STRING_ENCODING_ISO_8859_15;
else if ([string isEqual: @"windows-1251"] ||
[string isEqual: @"cp1251"] || [string isEqual: @"cp-1251"] ||
[string isEqual: @"1251"])
encoding = OF_STRING_ENCODING_WINDOWS_1251;
else if ([string isEqual: @"windows-1252"] ||
[string isEqual: @"cp1252"] || [string isEqual: @"cp-1252"] ||
[string isEqual: @"1252"])
encoding = OF_STRING_ENCODING_WINDOWS_1252;
else if ([string isEqual: @"cp437"] || [string isEqual: @"cp-437"] ||
[string isEqual: @"ibm437"] || [string isEqual: @"437"])
encoding = OF_STRING_ENCODING_CODEPAGE_437;
else if ([string isEqual: @"cp850"] || [string isEqual: @"cp-850"] ||
[string isEqual: @"ibm850"] || [string isEqual: @"850"])
encoding = OF_STRING_ENCODING_CODEPAGE_850;
else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] ||
[string isEqual: @"ibm858"] || [string isEqual: @"858"])
encoding = OF_STRING_ENCODING_CODEPAGE_858;
else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"])
encoding = OF_STRING_ENCODING_MAC_ROMAN;
else if ([string isEqual: @"koi8-r"])
encoding = OF_STRING_ENCODING_KOI8_R;
else if ([string isEqual: @"koi8-u"])
encoding = OF_STRING_ENCODING_KOI8_U;
else
@throw [OFInvalidArgumentException exception];
objc_autoreleasePoolPop(pool);
return encoding;
}
OFString *
of_string_name_of_encoding(of_string_encoding_t encoding)
{
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:
return @"UTF-8";
case OF_STRING_ENCODING_ASCII:
return @"ASCII";
case OF_STRING_ENCODING_ISO_8859_1:
return @"ISO 8859-1";
case OF_STRING_ENCODING_ISO_8859_2:
return @"ISO 8859-2";
case OF_STRING_ENCODING_ISO_8859_3:
return @"ISO 8859-3";
case OF_STRING_ENCODING_ISO_8859_15:
return @"ISO 8859-15";
case OF_STRING_ENCODING_WINDOWS_1251:
return @"Windows-1251";
case OF_STRING_ENCODING_WINDOWS_1252:
return @"Windows-1252";
case OF_STRING_ENCODING_CODEPAGE_437:
return @"Codepage 437";
case OF_STRING_ENCODING_CODEPAGE_850:
return @"Codepage 850";
case OF_STRING_ENCODING_CODEPAGE_858:
return @"Codepage 858";
case OF_STRING_ENCODING_MAC_ROMAN:
return @"Mac Roman";
case OF_STRING_ENCODING_KOI8_R:
return @"KOI8-R";
case OF_STRING_ENCODING_KOI8_U:
return @"KOI8-U";
case OF_STRING_ENCODING_AUTODETECT:
return @"autodetect";
}
return nil;
}
size_t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141
142
143
144
145
146
147
148
149
150
151
152
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
void
_reference_to_OFConstantString(void)
{
[OFConstantString class];
}
OFStringEncoding
OFParseStringEncodingName(OFString *string)
{
void *pool = objc_autoreleasePoolPush();
OFStringEncoding encoding;
string = string.lowercaseString;
if ([string isEqual: @"utf8"] || [string isEqual: @"utf-8"])
encoding = OFStringEncodingUTF8;
else if ([string isEqual: @"ascii"] || [string isEqual: @"us-ascii"])
encoding = OFStringEncodingASCII;
else if ([string isEqual: @"iso-8859-1"] ||
[string isEqual: @"iso_8859-1"])
encoding = OFStringEncodingISO8859_1;
else if ([string isEqual: @"iso-8859-2"] ||
[string isEqual: @"iso_8859-2"])
encoding = OFStringEncodingISO8859_2;
else if ([string isEqual: @"iso-8859-3"] ||
[string isEqual: @"iso_8859-3"])
encoding = OFStringEncodingISO8859_3;
else if ([string isEqual: @"iso-8859-15"] ||
[string isEqual: @"iso_8859-15"])
encoding = OFStringEncodingISO8859_15;
else if ([string isEqual: @"windows-1251"] ||
[string isEqual: @"cp1251"] || [string isEqual: @"cp-1251"] ||
[string isEqual: @"1251"])
encoding = OFStringEncodingWindows1251;
else if ([string isEqual: @"windows-1252"] ||
[string isEqual: @"cp1252"] || [string isEqual: @"cp-1252"] ||
[string isEqual: @"1252"])
encoding = OFStringEncodingWindows1252;
else if ([string isEqual: @"cp437"] || [string isEqual: @"cp-437"] ||
[string isEqual: @"ibm437"] || [string isEqual: @"437"])
encoding = OFStringEncodingCodepage437;
else if ([string isEqual: @"cp850"] || [string isEqual: @"cp-850"] ||
[string isEqual: @"ibm850"] || [string isEqual: @"850"])
encoding = OFStringEncodingCodepage850;
else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] ||
[string isEqual: @"ibm858"] || [string isEqual: @"858"])
encoding = OFStringEncodingCodepage858;
else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"])
encoding = OFStringEncodingMacRoman;
else if ([string isEqual: @"koi8-r"])
encoding = OFStringEncodingKOI8R;
else if ([string isEqual: @"koi8-u"])
encoding = OFStringEncodingKOI8U;
else
@throw [OFInvalidArgumentException exception];
objc_autoreleasePoolPop(pool);
return encoding;
}
OFString *
OFStringEncodingName(OFStringEncoding encoding)
{
switch (encoding) {
case OFStringEncodingUTF8:
return @"UTF-8";
case OFStringEncodingASCII:
return @"ASCII";
case OFStringEncodingISO8859_1:
return @"ISO 8859-1";
case OFStringEncodingISO8859_2:
return @"ISO 8859-2";
case OFStringEncodingISO8859_3:
return @"ISO 8859-3";
case OFStringEncodingISO8859_15:
return @"ISO 8859-15";
case OFStringEncodingWindows1251:
return @"Windows-1251";
case OFStringEncodingWindows1252:
return @"Windows-1252";
case OFStringEncodingCodepage437:
return @"Codepage 437";
case OFStringEncodingCodepage850:
return @"Codepage 850";
case OFStringEncodingCodepage858:
return @"Codepage 858";
case OFStringEncodingMacRoman:
return @"Mac Roman";
case OFStringEncodingKOI8R:
return @"KOI8-R";
case OFStringEncodingKOI8U:
return @"KOI8-U";
case OFStringEncodingAutodetect:
return @"autodetect";
}
return nil;
}
size_t
|
︙ | | | ︙ | |
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
461
462
463
464
465
466
467
468
469
470
471
472
473
|
return (id)[[OFUTF8String alloc]
initWithUTF8StringNoCopy: UTF8String
length: UTF8StringLength
freeWhenDone: freeWhenDone];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
{
if (encoding == OF_STRING_ENCODING_UTF_8) {
OFUTF8String *string;
size_t length;
void *storage;
length = strlen(cString);
string = of_alloc_object([OFUTF8String class], length + 1, 1,
&storage);
return (id)[string of_initWithUTF8String: cString
length: length
storage: storage];
}
return (id)[[OFUTF8String alloc] initWithCString: cString
encoding: encoding];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength
{
if (encoding == OF_STRING_ENCODING_UTF_8) {
OFUTF8String *string;
void *storage;
string = of_alloc_object([OFUTF8String class],
cStringLength + 1, 1, &storage);
return (id)[string of_initWithUTF8String: cString
length: cStringLength
storage: storage];
}
return (id)[[OFUTF8String alloc] initWithCString: cString
encoding: encoding
length: cStringLength];
}
- (instancetype)initWithData: (OFData *)data
encoding: (of_string_encoding_t)encoding
{
return (id)[[OFUTF8String alloc] initWithData: data
encoding: encoding];
}
- (instancetype)initWithString: (OFString *)string
{
|
|
|
|
|
|
|
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
461
462
463
464
465
466
467
468
469
470
471
472
473
|
return (id)[[OFUTF8String alloc]
initWithUTF8StringNoCopy: UTF8String
length: UTF8StringLength
freeWhenDone: freeWhenDone];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
{
if (encoding == OFStringEncodingUTF8) {
OFUTF8String *string;
size_t length;
void *storage;
length = strlen(cString);
string = of_alloc_object([OFUTF8String class], length + 1, 1,
&storage);
return (id)[string of_initWithUTF8String: cString
length: length
storage: storage];
}
return (id)[[OFUTF8String alloc] initWithCString: cString
encoding: encoding];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
if (encoding == OFStringEncodingUTF8) {
OFUTF8String *string;
void *storage;
string = of_alloc_object([OFUTF8String class],
cStringLength + 1, 1, &storage);
return (id)[string of_initWithUTF8String: cString
length: cStringLength
storage: storage];
}
return (id)[[OFUTF8String alloc] initWithCString: cString
encoding: encoding
length: cStringLength];
}
- (instancetype)initWithData: (OFData *)data
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithData: data
encoding: encoding];
}
- (instancetype)initWithString: (OFString *)string
{
|
︙ | | | ︙ | |
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (of_string_encoding_t)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (of_string_encoding_t)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL
encoding: encoding];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
|
|
|
|
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL
encoding: encoding];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
|
︙ | | | ︙ | |
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
return [[[self alloc]
initWithUTF8StringNoCopy: UTF8String
length: UTF8StringLength
freeWhenDone: freeWhenDone] autorelease];
}
+ (instancetype)stringWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
{
return [[[self alloc] initWithCString: cString
encoding: encoding] autorelease];
}
+ (instancetype)stringWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength
{
return [[[self alloc] initWithCString: cString
encoding: encoding
length: cStringLength] autorelease];
}
+ (instancetype)stringWithData: (OFData *)data
encoding: (of_string_encoding_t)encoding
{
return [[[self alloc] initWithData: data
encoding: encoding] autorelease];
}
+ (instancetype)stringWithString: (OFString *)string
{
|
|
|
|
|
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
return [[[self alloc]
initWithUTF8StringNoCopy: UTF8String
length: UTF8StringLength
freeWhenDone: freeWhenDone] autorelease];
}
+ (instancetype)stringWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithCString: cString
encoding: encoding] autorelease];
}
+ (instancetype)stringWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
return [[[self alloc] initWithCString: cString
encoding: encoding
length: cStringLength] autorelease];
}
+ (instancetype)stringWithData: (OFData *)data
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithData: data
encoding: encoding] autorelease];
}
+ (instancetype)stringWithString: (OFString *)string
{
|
︙ | | | ︙ | |
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
|
#ifdef OF_HAVE_FILES
+ (instancetype)stringWithContentsOfFile: (OFString *)path
{
return [[[self alloc] initWithContentsOfFile: path] autorelease];
}
+ (instancetype)stringWithContentsOfFile: (OFString *)path
encoding: (of_string_encoding_t)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
{
return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
encoding: (of_string_encoding_t)encoding
{
return [[[self alloc] initWithContentsOfURL: URL
encoding: encoding] autorelease];
}
- (instancetype)init
{
|
|
|
|
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
|
#ifdef OF_HAVE_FILES
+ (instancetype)stringWithContentsOfFile: (OFString *)path
{
return [[[self alloc] initWithContentsOfFile: path] autorelease];
}
+ (instancetype)stringWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
{
return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfURL: URL
encoding: encoding] autorelease];
}
- (instancetype)init
{
|
︙ | | | ︙ | |
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
return [super init];
}
- (instancetype)initWithUTF8String: (const char *)UTF8String
{
return [self initWithCString: UTF8String
encoding: OF_STRING_ENCODING_UTF_8
length: strlen(UTF8String)];
}
- (instancetype)initWithUTF8String: (const char *)UTF8String
length: (size_t)UTF8StringLength
{
return [self initWithCString: UTF8String
encoding: OF_STRING_ENCODING_UTF_8
length: UTF8StringLength];
}
- (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String
freeWhenDone: (bool)freeWhenDone
{
id ret = [self initWithUTF8String: UTF8String];
|
|
|
|
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
return [super init];
}
- (instancetype)initWithUTF8String: (const char *)UTF8String
{
return [self initWithCString: UTF8String
encoding: OFStringEncodingUTF8
length: strlen(UTF8String)];
}
- (instancetype)initWithUTF8String: (const char *)UTF8String
length: (size_t)UTF8StringLength
{
return [self initWithCString: UTF8String
encoding: OFStringEncodingUTF8
length: UTF8StringLength];
}
- (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String
freeWhenDone: (bool)freeWhenDone
{
id ret = [self initWithUTF8String: UTF8String];
|
︙ | | | ︙ | |
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
if (freeWhenDone)
free(UTF8String);
return ret;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
{
return [self initWithCString: cString
encoding: encoding
length: strlen(cString)];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithData: (OFData *)data
encoding: (of_string_encoding_t)encoding
{
@try {
if (data.itemSize != 1)
@throw [OFInvalidArgumentException exception];
} @catch (id e) {
[self release];
@throw e;
|
|
|
|
|
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
if (freeWhenDone)
free(UTF8String);
return ret;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
{
return [self initWithCString: cString
encoding: encoding
length: strlen(cString)];
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithData: (OFData *)data
encoding: (OFStringEncoding)encoding
{
@try {
if (data.itemSize != 1)
@throw [OFInvalidArgumentException exception];
} @catch (id e) {
[self release];
@throw e;
|
︙ | | | ︙ | |
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
|
OF_INVALID_INIT_METHOD
}
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
return [self initWithContentsOfFile: path
encoding: OF_STRING_ENCODING_UTF_8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (of_string_encoding_t)encoding
{
char *tmp;
unsigned long long fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *file = nil;
|
|
|
|
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
|
OF_INVALID_INIT_METHOD
}
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
return [self initWithContentsOfFile: path
encoding: OFStringEncodingUTF8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
char *tmp;
unsigned long long fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *file = nil;
|
︙ | | | ︙ | |
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
|
tmp[(size_t)fileSize] = '\0';
} @catch (id e) {
[self release];
@throw e;
}
if (encoding == OF_STRING_ENCODING_UTF_8) {
@try {
self = [self initWithUTF8StringNoCopy: tmp
length: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
free(tmp);
@throw e;
|
|
|
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
|
tmp[(size_t)fileSize] = '\0';
} @catch (id e) {
[self release];
@throw e;
}
if (encoding == OFStringEncodingUTF8) {
@try {
self = [self initWithUTF8StringNoCopy: tmp
length: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
free(tmp);
@throw e;
|
︙ | | | ︙ | |
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
return self;
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
{
return [self initWithContentsOfURL: URL
encoding: OF_STRING_ENCODING_AUTODETECT];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
data = [OFData dataWithContentsOfURL: URL];
} @catch (id e) {
|
|
|
|
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
return self;
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
{
return [self initWithContentsOfURL: URL
encoding: OFStringEncodingAutodetect];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
data = [OFData dataWithContentsOfURL: URL];
} @catch (id e) {
|
︙ | | | ︙ | |
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
objc_autoreleasePoolPop(pool);
return self;
}
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding
lossy: (bool)lossy
{
const OFUnichar *characters = self.characters;
size_t i, length = self.length;
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:;
size_t j = 0;
for (i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode(characters[i],
buffer);
|
|
|
|
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
objc_autoreleasePoolPop(pool);
return self;
}
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
lossy: (bool)lossy
{
const OFUnichar *characters = self.characters;
size_t i, length = self.length;
switch (encoding) {
case OFStringEncodingUTF8:;
size_t j = 0;
for (i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode(characters[i],
buffer);
|
︙ | | | ︙ | |
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
|
break;
}
}
cString[j] = '\0';
return j;
case OF_STRING_ENCODING_ASCII:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
for (i = 0; i < length; i++) {
if OF_UNLIKELY (characters[i] > 0x80) {
if (lossy)
cString[i] = '?';
else
@throw [OFInvalidEncodingException
exception];
} else
cString[i] = (unsigned char)characters[i];
}
cString[i] = '\0';
return length;
case OF_STRING_ENCODING_ISO_8859_1:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
for (i = 0; i < length; i++) {
if OF_UNLIKELY (characters[i] > 0xFF) {
if (lossy)
cString[i] = '?';
else
@throw [OFInvalidEncodingException
exception];
} else
cString[i] = (unsigned char)characters[i];
}
cString[i] = '\0';
return length;
#ifdef HAVE_ISO_8859_2
case OF_STRING_ENCODING_ISO_8859_2:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_2(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_ISO_8859_3
case OF_STRING_ENCODING_ISO_8859_3:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_3(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_ISO_8859_15
case OF_STRING_ENCODING_ISO_8859_15:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_15(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_WINDOWS_1251
case OF_STRING_ENCODING_WINDOWS_1251:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_windows_1251(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_WINDOWS_1252
case OF_STRING_ENCODING_WINDOWS_1252:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_windows_1252(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_437
case OF_STRING_ENCODING_CODEPAGE_437:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_437(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_850
case OF_STRING_ENCODING_CODEPAGE_850:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_850(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_858
case OF_STRING_ENCODING_CODEPAGE_858:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_858(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_MAC_ROMAN
case OF_STRING_ENCODING_MAC_ROMAN:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_mac_roman(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_KOI8_R
case OF_STRING_ENCODING_KOI8_R:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_koi8_r(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_KOI8_U
case OF_STRING_ENCODING_KOI8_U:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_koi8_u(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
default:
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
}
}
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding
{
return [self of_getCString: cString
maxLength: maxLength
encoding: encoding
lossy: false];
}
- (size_t)getLossyCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding
{
return [self of_getCString: cString
maxLength: maxLength
encoding: encoding
lossy: true];
}
- (const char *)of_cStringWithEncoding: (of_string_encoding_t)encoding
lossy: (bool)lossy
{
size_t length = self.length;
char *cString;
size_t cStringLength;
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:
cString = of_alloc((length * 4) + 1, 1);
@try {
cStringLength = [self
of_getCString: cString
maxLength: (length * 4) + 1
encoding: OF_STRING_ENCODING_UTF_8
lossy: lossy];
} @catch (id e) {
free(cString);
@throw e;
}
@try {
cString = of_realloc(cString, cStringLength + 1, 1);
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
break;
case OF_STRING_ENCODING_ASCII:
case OF_STRING_ENCODING_ISO_8859_1:
case OF_STRING_ENCODING_ISO_8859_2:
case OF_STRING_ENCODING_ISO_8859_3:
case OF_STRING_ENCODING_ISO_8859_15:
case OF_STRING_ENCODING_WINDOWS_1251:
case OF_STRING_ENCODING_WINDOWS_1252:
case OF_STRING_ENCODING_CODEPAGE_437:
case OF_STRING_ENCODING_CODEPAGE_850:
case OF_STRING_ENCODING_CODEPAGE_858:
case OF_STRING_ENCODING_MAC_ROMAN:
case OF_STRING_ENCODING_KOI8_R:
case OF_STRING_ENCODING_KOI8_U:
cString = of_alloc(length + 1, 1);
@try {
cStringLength = [self of_getCString: cString
maxLength: length + 1
encoding: encoding
lossy: lossy];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
|
break;
}
}
cString[j] = '\0';
return j;
case OFStringEncodingASCII:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
for (i = 0; i < length; i++) {
if OF_UNLIKELY (characters[i] > 0x80) {
if (lossy)
cString[i] = '?';
else
@throw [OFInvalidEncodingException
exception];
} else
cString[i] = (unsigned char)characters[i];
}
cString[i] = '\0';
return length;
case OFStringEncodingISO8859_1:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
for (i = 0; i < length; i++) {
if OF_UNLIKELY (characters[i] > 0xFF) {
if (lossy)
cString[i] = '?';
else
@throw [OFInvalidEncodingException
exception];
} else
cString[i] = (unsigned char)characters[i];
}
cString[i] = '\0';
return length;
#ifdef HAVE_ISO_8859_2
case OFStringEncodingISO8859_2:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_2(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_ISO_8859_3
case OFStringEncodingISO8859_3:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_3(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_ISO_8859_15
case OFStringEncodingISO8859_15:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_iso_8859_15(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_WINDOWS_1251
case OFStringEncodingWindows1251:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_windows_1251(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_WINDOWS_1252
case OFStringEncodingWindows1252:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_windows_1252(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_437
case OFStringEncodingCodepage437:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_437(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_850
case OFStringEncodingCodepage850:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_850(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_CODEPAGE_858
case OFStringEncodingCodepage858:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_codepage_858(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_MAC_ROMAN
case OFStringEncodingMacRoman:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_mac_roman(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_KOI8_R
case OFStringEncodingKOI8R:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_koi8_r(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
#ifdef HAVE_KOI8_U
case OFStringEncodingKOI8U:
if (length + 1 > maxLength)
@throw [OFOutOfRangeException exception];
if (!of_unicode_to_koi8_u(characters,
(unsigned char *)cString, length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
default:
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
}
}
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
{
return [self of_getCString: cString
maxLength: maxLength
encoding: encoding
lossy: false];
}
- (size_t)getLossyCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
{
return [self of_getCString: cString
maxLength: maxLength
encoding: encoding
lossy: true];
}
- (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding
lossy: (bool)lossy
{
size_t length = self.length;
char *cString;
size_t cStringLength;
switch (encoding) {
case OFStringEncodingUTF8:
cString = of_alloc((length * 4) + 1, 1);
@try {
cStringLength = [self
of_getCString: cString
maxLength: (length * 4) + 1
encoding: OFStringEncodingUTF8
lossy: lossy];
} @catch (id e) {
free(cString);
@throw e;
}
@try {
cString = of_realloc(cString, cStringLength + 1, 1);
} @catch (OFOutOfMemoryException *e) {
/* We don't care, as we only tried to make it smaller */
}
break;
case OFStringEncodingASCII:
case OFStringEncodingISO8859_1:
case OFStringEncodingISO8859_2:
case OFStringEncodingISO8859_3:
case OFStringEncodingISO8859_15:
case OFStringEncodingWindows1251:
case OFStringEncodingWindows1252:
case OFStringEncodingCodepage437:
case OFStringEncodingCodepage850:
case OFStringEncodingCodepage858:
case OFStringEncodingMacRoman:
case OFStringEncodingKOI8R:
case OFStringEncodingKOI8U:
cString = of_alloc(length + 1, 1);
@try {
cStringLength = [self of_getCString: cString
maxLength: length + 1
encoding: encoding
lossy: lossy];
|
︙ | | | ︙ | |
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
|
freeWhenDone: true] items];
} @catch (id e) {
free(cString);
@throw e;
}
}
- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding
{
return [self of_cStringWithEncoding: encoding lossy: false];
}
- (const char *)lossyCStringWithEncoding: (of_string_encoding_t)encoding
{
return [self of_cStringWithEncoding: encoding lossy: true];
}
- (const char *)UTF8String
{
return [self cStringWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (size_t)length
{
OF_UNRECOGNIZED_SELECTOR
}
- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:;
const OFUnichar *characters;
size_t length, UTF8StringLength = 0;
characters = self.characters;
length = self.length;
for (size_t i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode(characters[i],
buffer);
if (len == 0)
@throw [OFInvalidEncodingException exception];
UTF8StringLength += len;
}
return UTF8StringLength;
case OF_STRING_ENCODING_ASCII:
case OF_STRING_ENCODING_ISO_8859_1:
case OF_STRING_ENCODING_ISO_8859_2:
case OF_STRING_ENCODING_ISO_8859_3:
case OF_STRING_ENCODING_ISO_8859_15:
case OF_STRING_ENCODING_WINDOWS_1251:
case OF_STRING_ENCODING_WINDOWS_1252:
case OF_STRING_ENCODING_CODEPAGE_437:
case OF_STRING_ENCODING_CODEPAGE_850:
case OF_STRING_ENCODING_CODEPAGE_858:
case OF_STRING_ENCODING_MAC_ROMAN:
case OF_STRING_ENCODING_KOI8_R:
case OF_STRING_ENCODING_KOI8_U:
return self.length;
default:
@throw [OFInvalidEncodingException exception];
}
}
- (size_t)UTF8StringLength
{
return [self cStringLengthWithEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFUnichar)characterAtIndex: (size_t)idx
{
OF_UNRECOGNIZED_SELECTOR
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
|
freeWhenDone: true] items];
} @catch (id e) {
free(cString);
@throw e;
}
}
- (const char *)cStringWithEncoding: (OFStringEncoding)encoding
{
return [self of_cStringWithEncoding: encoding lossy: false];
}
- (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding
{
return [self of_cStringWithEncoding: encoding lossy: true];
}
- (const char *)UTF8String
{
return [self cStringWithEncoding: OFStringEncodingUTF8];
}
- (size_t)length
{
OF_UNRECOGNIZED_SELECTOR
}
- (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding
{
switch (encoding) {
case OFStringEncodingUTF8:;
const OFUnichar *characters;
size_t length, UTF8StringLength = 0;
characters = self.characters;
length = self.length;
for (size_t i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode(characters[i],
buffer);
if (len == 0)
@throw [OFInvalidEncodingException exception];
UTF8StringLength += len;
}
return UTF8StringLength;
case OFStringEncodingASCII:
case OFStringEncodingISO8859_1:
case OFStringEncodingISO8859_2:
case OFStringEncodingISO8859_3:
case OFStringEncodingISO8859_15:
case OFStringEncodingWindows1251:
case OFStringEncodingWindows1252:
case OFStringEncodingCodepage437:
case OFStringEncodingCodepage850:
case OFStringEncodingCodepage858:
case OFStringEncodingMacRoman:
case OFStringEncodingKOI8R:
case OFStringEncodingKOI8U:
return self.length;
default:
@throw [OFInvalidEncodingException exception];
}
}
- (size_t)UTF8StringLength
{
return [self cStringLengthWithEncoding: OFStringEncodingUTF8];
}
- (OFUnichar)characterAtIndex: (size_t)idx
{
OF_UNRECOGNIZED_SELECTOR
}
|
︙ | | | ︙ | |
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
|
freeWhenDone: true] items];
} @catch (id e) {
free(buffer);
@throw e;
}
}
- (OFData *)dataWithEncoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data =
[OFData dataWithItems: [self cStringWithEncoding: encoding]
count: [self cStringLengthWithEncoding: encoding]];
[data retain];
|
|
|
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
|
freeWhenDone: true] items];
} @catch (id e) {
free(buffer);
@throw e;
}
}
- (OFData *)dataWithEncoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data =
[OFData dataWithItems: [self cStringWithEncoding: encoding]
count: [self cStringLengthWithEncoding: encoding]];
[data retain];
|
︙ | | | ︙ | |
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
|
if ((length = ExpandEnvironmentStringsW(self.UTF16String,
buffer, sizeof(buffer))) == 0)
return self;
return [OFString stringWithUTF16String: buffer
length: length - 1];
} else {
of_string_encoding_t encoding = [OFLocale encoding];
char buffer[512];
size_t length;
if ((length = ExpandEnvironmentStringsA(
[self cStringWithEncoding: encoding], buffer,
sizeof(buffer))) == 0)
return self;
return [OFString stringWithCString: buffer
encoding: encoding
length: length - 1];
}
}
#endif
#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
[self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8];
}
- (void)writeToFile: (OFString *)path encoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToURL: (OFURL *)URL
{
[self writeToURL: URL encoding: OF_STRING_ENCODING_UTF_8];
}
- (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding
{
void *pool = objc_autoreleasePoolPush();
OFURLHandler *URLHandler;
OFStream *stream;
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
|
|
|
|
|
|
|
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
|
if ((length = ExpandEnvironmentStringsW(self.UTF16String,
buffer, sizeof(buffer))) == 0)
return self;
return [OFString stringWithUTF16String: buffer
length: length - 1];
} else {
OFStringEncoding encoding = [OFLocale encoding];
char buffer[512];
size_t length;
if ((length = ExpandEnvironmentStringsA(
[self cStringWithEncoding: encoding], buffer,
sizeof(buffer))) == 0)
return self;
return [OFString stringWithCString: buffer
encoding: encoding
length: length - 1];
}
}
#endif
#ifdef OF_HAVE_FILES
- (void)writeToFile: (OFString *)path
{
[self writeToFile: path encoding: OFStringEncodingUTF8];
}
- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToURL: (OFURL *)URL
{
[self writeToURL: URL encoding: OFStringEncodingUTF8];
}
- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFURLHandler *URLHandler;
OFStream *stream;
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFStream.h"
#import "OFString.h"
#import "OFOutOfRangeException.h"
static OFString *
stringFromBuffer(const unsigned char *buffer, size_t length,
of_string_encoding_t encoding)
{
for (size_t i = 0; i < length; i++)
if (buffer[i] == '\0')
length = i;
return [OFString stringWithCString: (const char *)buffer
encoding: encoding
length: length];
}
static void
stringToBuffer(unsigned char *buffer, OFString *string, size_t length,
of_string_encoding_t encoding)
{
size_t cStringLength = [string cStringLengthWithEncoding: encoding];
if (cStringLength > length)
@throw [OFOutOfRangeException exception];
memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength);
|
|
|
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#import "OFStream.h"
#import "OFString.h"
#import "OFOutOfRangeException.h"
static OFString *
stringFromBuffer(const unsigned char *buffer, size_t length,
OFStringEncoding encoding)
{
for (size_t i = 0; i < length; i++)
if (buffer[i] == '\0')
length = i;
return [OFString stringWithCString: (const char *)buffer
encoding: encoding
length: length];
}
static void
stringToBuffer(unsigned char *buffer, OFString *string, size_t length,
OFStringEncoding encoding)
{
size_t cStringLength = [string cStringLengthWithEncoding: encoding];
if (cStringLength > length)
@throw [OFOutOfRangeException exception];
memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength);
|
︙ | | | ︙ | |
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
88
89
90
91
92
93
94
95
|
return 0;
if (buffer[0] == 0x80) {
for (size_t i = 1; i < length; i++)
value = (value << 8) | buffer[i];
} else
value = [stringFromBuffer(buffer, length,
OF_STRING_ENCODING_ASCII) unsignedLongLongValueWithBase: 8];
if (value > max)
@throw [OFOutOfRangeException exception];
return value;
}
@implementation OFTarArchiveEntry
+ (instancetype)entryWithFileName: (OFString *)fileName
{
return [[[self alloc] initWithFileName: fileName] autorelease];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)of_initWithHeader: (unsigned char [512])header
encoding: (of_string_encoding_t)encoding
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
OFString *targetFileName;
|
|
|
|
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
88
89
90
91
92
93
94
95
|
return 0;
if (buffer[0] == 0x80) {
for (size_t i = 1; i < length; i++)
value = (value << 8) | buffer[i];
} else
value = [stringFromBuffer(buffer, length,
OFStringEncodingASCII) unsignedLongLongValueWithBase: 8];
if (value > max)
@throw [OFOutOfRangeException exception];
return value;
}
@implementation OFTarArchiveEntry
+ (instancetype)entryWithFileName: (OFString *)fileName
{
return [[[self alloc] initWithFileName: fileName] autorelease];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)of_initWithHeader: (unsigned char [512])header
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
OFString *targetFileName;
|
︙ | | | ︙ | |
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
338
339
340
341
342
343
344
345
346
347
|
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
- (void)of_writeToStream: (OFStream *)stream
encoding: (of_string_encoding_t)encoding
{
unsigned char buffer[512];
unsigned long long modificationDate;
uint16_t checksum = 0;
stringToBuffer(buffer, _fileName, 100, encoding);
stringToBuffer(buffer + 100,
[OFString stringWithFormat: @"%06" PRIo16 " ", _mode], 8,
OF_STRING_ENCODING_ASCII);
stringToBuffer(buffer + 108,
[OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8,
OF_STRING_ENCODING_ASCII);
stringToBuffer(buffer + 116,
[OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8,
OF_STRING_ENCODING_ASCII);
stringToBuffer(buffer + 124,
[OFString stringWithFormat: @"%011" PRIo64 " ", _size], 12,
OF_STRING_ENCODING_ASCII);
modificationDate = _modificationDate.timeIntervalSince1970;
stringToBuffer(buffer + 136,
[OFString stringWithFormat: @"%011llo", modificationDate],
12, OF_STRING_ENCODING_ASCII);
/*
* During checksumming, the checksum field is expected to be set to 8
* spaces.
*/
memset(buffer + 148, ' ', 8);
buffer[156] = _type;
stringToBuffer(buffer + 157, _targetFileName, 100, encoding);
/* ustar */
memcpy(buffer + 257, "ustar\0" "00", 8);
stringToBuffer(buffer + 265, _owner, 32, encoding);
stringToBuffer(buffer + 297, _group, 32, encoding);
stringToBuffer(buffer + 329,
[OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8,
OF_STRING_ENCODING_ASCII);
stringToBuffer(buffer + 337,
[OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8,
OF_STRING_ENCODING_ASCII);
memset(buffer + 345, '\0', 155 + 12);
/* Fill in the checksum */
for (size_t i = 0; i < 500; i++)
checksum += buffer[i];
stringToBuffer(buffer + 148,
[OFString stringWithFormat: @"%06" PRIo16, checksum], 7,
OF_STRING_ENCODING_ASCII);
[stream writeBuffer: buffer length: sizeof(buffer)];
}
@end
|
|
|
|
|
|
|
|
|
|
|
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
338
339
340
341
342
343
344
345
346
347
|
objc_autoreleasePoolPop(pool);
return [ret autorelease];
}
- (void)of_writeToStream: (OFStream *)stream
encoding: (OFStringEncoding)encoding
{
unsigned char buffer[512];
unsigned long long modificationDate;
uint16_t checksum = 0;
stringToBuffer(buffer, _fileName, 100, encoding);
stringToBuffer(buffer + 100,
[OFString stringWithFormat: @"%06" PRIo16 " ", _mode], 8,
OFStringEncodingASCII);
stringToBuffer(buffer + 108,
[OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8,
OFStringEncodingASCII);
stringToBuffer(buffer + 116,
[OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8,
OFStringEncodingASCII);
stringToBuffer(buffer + 124,
[OFString stringWithFormat: @"%011" PRIo64 " ", _size], 12,
OFStringEncodingASCII);
modificationDate = _modificationDate.timeIntervalSince1970;
stringToBuffer(buffer + 136,
[OFString stringWithFormat: @"%011llo", modificationDate],
12, OFStringEncodingASCII);
/*
* During checksumming, the checksum field is expected to be set to 8
* spaces.
*/
memset(buffer + 148, ' ', 8);
buffer[156] = _type;
stringToBuffer(buffer + 157, _targetFileName, 100, encoding);
/* ustar */
memcpy(buffer + 257, "ustar\0" "00", 8);
stringToBuffer(buffer + 265, _owner, 32, encoding);
stringToBuffer(buffer + 297, _group, 32, encoding);
stringToBuffer(buffer + 329,
[OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8,
OFStringEncodingASCII);
stringToBuffer(buffer + 337,
[OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8,
OFStringEncodingASCII);
memset(buffer + 345, '\0', 155 + 12);
/* Fill in the checksum */
for (size_t i = 0; i < 500; i++)
checksum += buffer[i];
stringToBuffer(buffer + 148,
[OFString stringWithFormat: @"%06" PRIo16, checksum], 7,
OFStringEncodingASCII);
[stream writeBuffer: buffer length: sizeof(buffer)];
}
@end
|
︙ | | | ︙ | |
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
@throw e;
}
return self;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)cStringLength
{
self = [super init];
@try {
const OFChar16 *table;
size_t tableOffset, j;
if (encoding == OF_STRING_ENCODING_UTF_8 &&
cStringLength >= 3 &&
memcmp(cString, "\xEF\xBB\xBF", 3) == 0) {
cString += 3;
cStringLength -= 3;
}
_s = &_storage;
_s->cString = of_alloc(cStringLength + 1, 1);
_s->cStringLength = cStringLength;
_s->freeWhenDone = true;
if (encoding == OF_STRING_ENCODING_UTF_8 ||
encoding == OF_STRING_ENCODING_ASCII) {
switch (of_string_utf8_check(cString, cStringLength,
&_s->length)) {
case 1:
if (encoding == OF_STRING_ENCODING_ASCII)
@throw [OFInvalidEncodingException
exception];
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
memcpy(_s->cString, cString, cStringLength);
_s->cString[cStringLength] = 0;
return self;
}
/* All other encodings we support are single byte encodings */
_s->length = cStringLength;
if (encoding == OF_STRING_ENCODING_ISO_8859_1) {
j = 0;
for (size_t i = 0; i < cStringLength; i++) {
char buffer[4];
size_t bytes;
if (!(cString[i] & 0x80)) {
_s->cString[j++] = cString[i];
|
|
|
|
|
|
|
|
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
@throw e;
}
return self;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
self = [super init];
@try {
const OFChar16 *table;
size_t tableOffset, j;
if (encoding == OFStringEncodingUTF8 &&
cStringLength >= 3 &&
memcmp(cString, "\xEF\xBB\xBF", 3) == 0) {
cString += 3;
cStringLength -= 3;
}
_s = &_storage;
_s->cString = of_alloc(cStringLength + 1, 1);
_s->cStringLength = cStringLength;
_s->freeWhenDone = true;
if (encoding == OFStringEncodingUTF8 ||
encoding == OFStringEncodingASCII) {
switch (of_string_utf8_check(cString, cStringLength,
&_s->length)) {
case 1:
if (encoding == OFStringEncodingASCII)
@throw [OFInvalidEncodingException
exception];
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
memcpy(_s->cString, cString, cStringLength);
_s->cString[cStringLength] = 0;
return self;
}
/* All other encodings we support are single byte encodings */
_s->length = cStringLength;
if (encoding == OFStringEncodingISO8859_1) {
j = 0;
for (size_t i = 0; i < cStringLength; i++) {
char buffer[4];
size_t bytes;
if (!(cString[i] & 0x80)) {
_s->cString[j++] = cString[i];
|
︙ | | | ︙ | |
308
309
310
311
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
switch (encoding) {
#define CASE(encoding, var) \
case encoding: \
table = var; \
tableOffset = var##_offset; \
break;
#ifdef HAVE_ISO_8859_2
CASE(OF_STRING_ENCODING_ISO_8859_2, of_iso_8859_2_table)
#endif
#ifdef HAVE_ISO_8859_3
CASE(OF_STRING_ENCODING_ISO_8859_3, of_iso_8859_3_table)
#endif
#ifdef HAVE_ISO_8859_15
CASE(OF_STRING_ENCODING_ISO_8859_15, of_iso_8859_15_table)
#endif
#ifdef HAVE_WINDOWS_1251
CASE(OF_STRING_ENCODING_WINDOWS_1251, of_windows_1251_table)
#endif
#ifdef HAVE_WINDOWS_1252
CASE(OF_STRING_ENCODING_WINDOWS_1252, of_windows_1252_table)
#endif
#ifdef HAVE_CODEPAGE_437
CASE(OF_STRING_ENCODING_CODEPAGE_437, of_codepage_437_table)
#endif
#ifdef HAVE_CODEPAGE_850
CASE(OF_STRING_ENCODING_CODEPAGE_850, of_codepage_850_table)
#endif
#ifdef HAVE_CODEPAGE_858
CASE(OF_STRING_ENCODING_CODEPAGE_858, of_codepage_858_table)
#endif
#ifdef HAVE_MAC_ROMAN
CASE(OF_STRING_ENCODING_MAC_ROMAN, of_mac_roman_table)
#endif
#ifdef HAVE_KOI8_R
CASE(OF_STRING_ENCODING_KOI8_R, of_koi8_r_table)
#endif
#ifdef HAVE_KOI8_U
CASE(OF_STRING_ENCODING_KOI8_U, of_koi8_u_table)
#endif
#undef CASE
default:
@throw [OFInvalidEncodingException exception];
}
j = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
308
309
310
311
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
switch (encoding) {
#define CASE(encoding, var) \
case encoding: \
table = var; \
tableOffset = var##_offset; \
break;
#ifdef HAVE_ISO_8859_2
CASE(OFStringEncodingISO8859_2, of_iso_8859_2_table)
#endif
#ifdef HAVE_ISO_8859_3
CASE(OFStringEncodingISO8859_3, of_iso_8859_3_table)
#endif
#ifdef HAVE_ISO_8859_15
CASE(OFStringEncodingISO8859_15, of_iso_8859_15_table)
#endif
#ifdef HAVE_WINDOWS_1251
CASE(OFStringEncodingWindows1251, of_windows_1251_table)
#endif
#ifdef HAVE_WINDOWS_1252
CASE(OFStringEncodingWindows1252, of_windows_1252_table)
#endif
#ifdef HAVE_CODEPAGE_437
CASE(OFStringEncodingCodepage437, of_codepage_437_table)
#endif
#ifdef HAVE_CODEPAGE_850
CASE(OFStringEncodingCodepage850, of_codepage_850_table)
#endif
#ifdef HAVE_CODEPAGE_858
CASE(OFStringEncodingCodepage858, of_codepage_858_table)
#endif
#ifdef HAVE_MAC_ROMAN
CASE(OFStringEncodingMacRoman, of_mac_roman_table)
#endif
#ifdef HAVE_KOI8_R
CASE(OFStringEncodingKOI8R, of_koi8_r_table)
#endif
#ifdef HAVE_KOI8_U
CASE(OFStringEncodingKOI8U, of_koi8_u_table)
#endif
#undef CASE
default:
@throw [OFInvalidEncodingException exception];
}
j = 0;
|
︙ | | | ︙ | |
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
|
free(_s->cString);
[super dealloc];
}
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (of_string_encoding_t)encoding
{
switch (encoding) {
case OF_STRING_ENCODING_ASCII:
if (_s->isUTF8)
@throw [OFInvalidEncodingException exception];
/* intentional fall-through */
case OF_STRING_ENCODING_UTF_8:
if (_s->cStringLength + 1 > maxLength)
@throw [OFOutOfRangeException exception];
memcpy(cString, _s->cString, _s->cStringLength + 1);
return _s->cStringLength;
default:
return [super getCString: cString
maxLength: maxLength
encoding: encoding];
}
}
- (const char *)cStringWithEncoding: (of_string_encoding_t)encoding
{
switch (encoding) {
case OF_STRING_ENCODING_ASCII:
if (_s->isUTF8)
@throw [OFInvalidEncodingException exception];
/* intentional fall-through */
case OF_STRING_ENCODING_UTF_8:
return _s->cString;
default:
return [super cStringWithEncoding: encoding];
}
}
- (const char *)UTF8String
{
return _s->cString;
}
- (size_t)length
{
return _s->length;
}
- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:
case OF_STRING_ENCODING_ASCII:
return _s->cStringLength;
default:
return [super cStringLengthWithEncoding: encoding];
}
}
- (size_t)UTF8StringLength
|
|
|
|
|
|
|
|
|
|
|
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
|
free(_s->cString);
[super dealloc];
}
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
{
switch (encoding) {
case OFStringEncodingASCII:
if (_s->isUTF8)
@throw [OFInvalidEncodingException exception];
/* intentional fall-through */
case OFStringEncodingUTF8:
if (_s->cStringLength + 1 > maxLength)
@throw [OFOutOfRangeException exception];
memcpy(cString, _s->cString, _s->cStringLength + 1);
return _s->cStringLength;
default:
return [super getCString: cString
maxLength: maxLength
encoding: encoding];
}
}
- (const char *)cStringWithEncoding: (OFStringEncoding)encoding
{
switch (encoding) {
case OFStringEncodingASCII:
if (_s->isUTF8)
@throw [OFInvalidEncodingException exception];
/* intentional fall-through */
case OFStringEncodingUTF8:
return _s->cString;
default:
return [super cStringWithEncoding: encoding];
}
}
- (const char *)UTF8String
{
return _s->cString;
}
- (size_t)length
{
return _s->length;
}
- (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding
{
switch (encoding) {
case OFStringEncodingUTF8:
case OFStringEncodingASCII:
return _s->cStringLength;
default:
return [super cStringLengthWithEncoding: encoding];
}
}
- (size_t)UTF8StringLength
|
︙ | | | ︙ | |
︙ | | | ︙ | |
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#import "OFInvalidEncodingException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
static of_string_encoding_t
codepageToEncoding(UINT codepage)
{
switch (codepage) {
case 437:
return OF_STRING_ENCODING_CODEPAGE_437;
case 850:
return OF_STRING_ENCODING_CODEPAGE_850;
case 858:
return OF_STRING_ENCODING_CODEPAGE_858;
case 1251:
return OF_STRING_ENCODING_WINDOWS_1251;
case 1252:
return OF_STRING_ENCODING_WINDOWS_1252;
default:
@throw [OFInvalidEncodingException exception];
}
}
@implementation OFWin32ConsoleStdIOStream
+ (void)load
|
|
|
|
|
|
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#import "OFInvalidEncodingException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"
#include <windows.h>
static OFStringEncoding
codepageToEncoding(UINT codepage)
{
switch (codepage) {
case 437:
return OFStringEncodingCodepage437;
case 850:
return OFStringEncodingCodepage850;
case 858:
return OFStringEncodingCodepage858;
case 1251:
return OFStringEncodingWindows1251;
case 1252:
return OFStringEncodingWindows1252;
default:
@throw [OFInvalidEncodingException exception];
}
}
@implementation OFWin32ConsoleStdIOStream
+ (void)load
|
︙ | | | ︙ | |
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
if (!ReadConsoleW(_handle, UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2
errNo: EIO];
} else {
of_string_encoding_t encoding;
OFString *string;
size_t stringLen;
if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
|
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
if (!ReadConsoleW(_handle, UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length * 2
errNo: EIO];
} else {
OFStringEncoding encoding;
OFString *string;
size_t stringLen;
if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length,
&UTF16Len, NULL))
@throw [OFReadFailedException
exceptionWithObject: self
|
︙ | | | ︙ | |
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString
stringWithUTF16String: UTF16
length: UTF16Len];
of_string_encoding_t encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString
stringWithUTF16String: UTF16
length: UTF16Len];
OFStringEncoding encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
︙ | | | ︙ | |
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
requestedLength: j * 2
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString stringWithUTF16String: tmp
length: j];
of_string_encoding_t encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
requestedLength: j * 2
bytesWritten: bytesWritten * 2
errNo: EIO];
} else {
void *pool = objc_autoreleasePoolPush();
OFString *string = [OFString stringWithUTF16String: tmp
length: j];
OFStringEncoding encoding =
codepageToEncoding(GetConsoleOutputCP());
size_t nativeLen = [string
cStringLengthWithEncoding: encoding];
if (nativeLen > UINT32_MAX)
@throw [OFOutOfRangeException exception];
|
︙ | | | ︙ | |
︙ | | | ︙ | |
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
@throw e;
}
return self;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (of_string_encoding_t)encoding
length: (size_t)length
{
self = [super init];
@try {
_string = [[OFMutableString alloc] initWithCString: cString
encoding: encoding
|
|
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
@throw e;
}
return self;
}
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)length
{
self = [super init];
@try {
_string = [[OFMutableString alloc] initWithCString: cString
encoding: encoding
|
︙ | | | ︙ | |
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
[is isEqual: @"fööbär🀺"] &&
(is = [stringClass stringWithUTF32String: sucstr]) &&
[is isEqual: @"fööbär🀺"])
#ifdef OF_HAVE_FILES
TEST(@"+[stringWithContentsOfFile:encoding]", (is = [stringClass
stringWithContentsOfFile: @"testfile.txt"
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[is isEqual: @"testäöü"])
TEST(@"+[stringWithContentsOfURL:encoding]", (is = [stringClass
stringWithContentsOfURL: [OFURL fileURLWithPath: @"testfile.txt"]
encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
[is isEqual: @"testäöü"])
#endif
TEST(@"-[appendUTFString:length:]",
R([s[0] appendUTF8String: "\xEF\xBB\xBF" "barqux" length: 6]) &&
[s[0] isEqual: @"foobar"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
OFInvalidEncodingException,
[stringClass stringWithUTF8String: "\xE0\x80"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",
OFInvalidEncodingException,
[stringClass stringWithUTF8String: "\xF0\x80\x80\xC0"])
TEST(@"Conversion of ISO 8859-1 to Unicode",
[[stringClass stringWithCString: "\xE4\xF6\xFC"
encoding: OF_STRING_ENCODING_ISO_8859_1]
isEqual: @"äöü"])
#ifdef HAVE_ISO_8859_15
TEST(@"Conversion of ISO 8859-15 to Unicode",
[[stringClass stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
encoding: OF_STRING_ENCODING_ISO_8859_15]
isEqual: @"€ŠšŽžŒœŸ"])
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Conversion of Windows 1252 to Unicode",
[[stringClass stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88"
"\x89\x8A\x8B\x8C\x8E\x91\x92\x93"
"\x94\x95\x96\x97\x98\x99\x9A\x9B"
"\x9C\x9E\x9F"
encoding: OF_STRING_ENCODING_WINDOWS_1252]
isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Conversion of Codepage 437 to Unicode",
[[stringClass stringWithCString: "\xB0\xB1\xB2\xDB"
encoding: OF_STRING_ENCODING_CODEPAGE_437]
isEqual: @"░▒▓█"])
#endif
TEST(@"Conversion of Unicode to ASCII #1",
!strcmp([C(@"This is a test") cStringWithEncoding:
OF_STRING_ENCODING_ASCII], "This is a test"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ASCII #2",
OFInvalidEncodingException,
[C(@"This is a tést")
cStringWithEncoding: OF_STRING_ENCODING_ASCII])
TEST(@"Conversion of Unicode to ISO-8859-1 #1",
!strcmp([C(@"This is ä test") cStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_1], "This is \xE4 test"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-1 #2",
OFInvalidEncodingException,
[C(@"This is ä t€st") cStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_1])
#ifdef HAVE_ISO_8859_15
TEST(@"Conversion of Unicode to ISO-8859-15 #1",
!strcmp([C(@"This is ä t€st") cStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-15 #2",
OFInvalidEncodingException,
[C(@"This is ä t€st…") cStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_15])
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Conversion of Unicode to Windows-1252 #1",
!strcmp([C(@"This is ä t€st…") cStringWithEncoding:
OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85"))
EXPECT_EXCEPTION(@"Conversion of Unicode to Windows-1252 #2",
OFInvalidEncodingException, [C(@"This is ä t€st…‼")
cStringWithEncoding: OF_STRING_ENCODING_WINDOWS_1252])
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Conversion of Unicode to Codepage 437 #1",
!strcmp([C(@"Tést strîng ░▒▓") cStringWithEncoding:
OF_STRING_ENCODING_CODEPAGE_437], "T\x82st str\x8Cng \xB0\xB1\xB2"))
EXPECT_EXCEPTION(@"Conversion of Unicode to Codepage 437 #2",
OFInvalidEncodingException, [C(@"T€st strîng ░▒▓")
cStringWithEncoding: OF_STRING_ENCODING_CODEPAGE_437])
#endif
TEST(@"Lossy conversion of Unicode to ASCII",
!strcmp([C(@"This is a tést") lossyCStringWithEncoding:
OF_STRING_ENCODING_ASCII], "This is a t?st"))
TEST(@"Lossy conversion of Unicode to ISO-8859-1",
!strcmp([C(@"This is ä t€st") lossyCStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_1], "This is \xE4 t?st"))
#ifdef HAVE_ISO_8859_15
TEST(@"Lossy conversion of Unicode to ISO-8859-15",
!strcmp([C(@"This is ä t€st…") lossyCStringWithEncoding:
OF_STRING_ENCODING_ISO_8859_15], "This is \xE4 t\xA4st?"))
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Lossy conversion of Unicode to Windows-1252",
!strcmp([C(@"This is ä t€st…‼") lossyCStringWithEncoding:
OF_STRING_ENCODING_WINDOWS_1252], "This is \xE4 t\x80st\x85?"))
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Lossy conversion of Unicode to Codepage 437",
!strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding:
OF_STRING_ENCODING_CODEPAGE_437], "T?st str\x8Cng \xB0\xB1\xB2"))
#endif
TEST(@"+[stringWithFormat:]",
[(s[0] = [mutableStringClass stringWithFormat: @"%@:%d", @"test",
123])
isEqual: @"test:123"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
[is isEqual: @"fööbär🀺"] &&
(is = [stringClass stringWithUTF32String: sucstr]) &&
[is isEqual: @"fööbär🀺"])
#ifdef OF_HAVE_FILES
TEST(@"+[stringWithContentsOfFile:encoding]", (is = [stringClass
stringWithContentsOfFile: @"testfile.txt"
encoding: OFStringEncodingISO8859_1]) &&
[is isEqual: @"testäöü"])
TEST(@"+[stringWithContentsOfURL:encoding]", (is = [stringClass
stringWithContentsOfURL: [OFURL fileURLWithPath: @"testfile.txt"]
encoding: OFStringEncodingISO8859_1]) &&
[is isEqual: @"testäöü"])
#endif
TEST(@"-[appendUTFString:length:]",
R([s[0] appendUTF8String: "\xEF\xBB\xBF" "barqux" length: 6]) &&
[s[0] isEqual: @"foobar"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
OFInvalidEncodingException,
[stringClass stringWithUTF8String: "\xE0\x80"])
EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",
OFInvalidEncodingException,
[stringClass stringWithUTF8String: "\xF0\x80\x80\xC0"])
TEST(@"Conversion of ISO 8859-1 to Unicode",
[[stringClass stringWithCString: "\xE4\xF6\xFC"
encoding: OFStringEncodingISO8859_1]
isEqual: @"äöü"])
#ifdef HAVE_ISO_8859_15
TEST(@"Conversion of ISO 8859-15 to Unicode",
[[stringClass stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"
encoding: OFStringEncodingISO8859_15]
isEqual: @"€ŠšŽžŒœŸ"])
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Conversion of Windows 1252 to Unicode",
[[stringClass stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88"
"\x89\x8A\x8B\x8C\x8E\x91\x92\x93"
"\x94\x95\x96\x97\x98\x99\x9A\x9B"
"\x9C\x9E\x9F"
encoding: OFStringEncodingWindows1252]
isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Conversion of Codepage 437 to Unicode",
[[stringClass stringWithCString: "\xB0\xB1\xB2\xDB"
encoding: OFStringEncodingCodepage437]
isEqual: @"░▒▓█"])
#endif
TEST(@"Conversion of Unicode to ASCII #1",
!strcmp([C(@"This is a test") cStringWithEncoding:
OFStringEncodingASCII], "This is a test"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ASCII #2",
OFInvalidEncodingException,
[C(@"This is a tést")
cStringWithEncoding: OFStringEncodingASCII])
TEST(@"Conversion of Unicode to ISO-8859-1 #1",
!strcmp([C(@"This is ä test") cStringWithEncoding:
OFStringEncodingISO8859_1], "This is \xE4 test"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-1 #2",
OFInvalidEncodingException,
[C(@"This is ä t€st") cStringWithEncoding:
OFStringEncodingISO8859_1])
#ifdef HAVE_ISO_8859_15
TEST(@"Conversion of Unicode to ISO-8859-15 #1",
!strcmp([C(@"This is ä t€st") cStringWithEncoding:
OFStringEncodingISO8859_15], "This is \xE4 t\xA4st"))
EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-15 #2",
OFInvalidEncodingException,
[C(@"This is ä t€st…") cStringWithEncoding:
OFStringEncodingISO8859_15])
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Conversion of Unicode to Windows-1252 #1",
!strcmp([C(@"This is ä t€st…") cStringWithEncoding:
OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85"))
EXPECT_EXCEPTION(@"Conversion of Unicode to Windows-1252 #2",
OFInvalidEncodingException, [C(@"This is ä t€st…‼")
cStringWithEncoding: OFStringEncodingWindows1252])
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Conversion of Unicode to Codepage 437 #1",
!strcmp([C(@"Tést strîng ░▒▓") cStringWithEncoding:
OFStringEncodingCodepage437], "T\x82st str\x8Cng \xB0\xB1\xB2"))
EXPECT_EXCEPTION(@"Conversion of Unicode to Codepage 437 #2",
OFInvalidEncodingException, [C(@"T€st strîng ░▒▓")
cStringWithEncoding: OFStringEncodingCodepage437])
#endif
TEST(@"Lossy conversion of Unicode to ASCII",
!strcmp([C(@"This is a tést") lossyCStringWithEncoding:
OFStringEncodingASCII], "This is a t?st"))
TEST(@"Lossy conversion of Unicode to ISO-8859-1",
!strcmp([C(@"This is ä t€st") lossyCStringWithEncoding:
OFStringEncodingISO8859_1], "This is \xE4 t?st"))
#ifdef HAVE_ISO_8859_15
TEST(@"Lossy conversion of Unicode to ISO-8859-15",
!strcmp([C(@"This is ä t€st…") lossyCStringWithEncoding:
OFStringEncodingISO8859_15], "This is \xE4 t\xA4st?"))
#endif
#ifdef HAVE_WINDOWS_1252
TEST(@"Lossy conversion of Unicode to Windows-1252",
!strcmp([C(@"This is ä t€st…‼") lossyCStringWithEncoding:
OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85?"))
#endif
#ifdef HAVE_CODEPAGE_437
TEST(@"Lossy conversion of Unicode to Codepage 437",
!strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding:
OFStringEncodingCodepage437], "T?st str\x8Cng \xB0\xB1\xB2"))
#endif
TEST(@"+[stringWithFormat:]",
[(s[0] = [mutableStringClass stringWithFormat: @"%@:%d", @"test",
123])
isEqual: @"test:123"])
|
︙ | | | ︙ | |
︙ | | | ︙ | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
{ 'q', @"quiet", 0, NULL, NULL },
{ 't', @"type", 1, NULL, &type },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFUnichar option, mode = '\0';
of_string_encoding_t encoding = OF_STRING_ENCODING_AUTODETECT;
OFOptionsParser *optionsParser;
OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
id <Archive> archive;
#ifdef OF_HAVE_SANDBOX
OFSandbox *sandbox = [OFSandbox sandbox];
sandbox.allowsStdIO = true;
|
|
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
{ 'q', @"quiet", 0, NULL, NULL },
{ 't', @"type", 1, NULL, &type },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFUnichar option, mode = '\0';
OFStringEncoding encoding = OFStringEncodingAutodetect;
OFOptionsParser *optionsParser;
OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
id <Archive> archive;
#ifdef OF_HAVE_SANDBOX
OFSandbox *sandbox = [OFSandbox sandbox];
sandbox.allowsStdIO = true;
|
︙ | | | ︙ | |
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
[OFApplication terminateWithStatus: 1];
break;
}
}
@try {
if (encodingString != nil)
encoding = of_string_parse_encoding(encodingString);
} @catch (OFInvalidArgumentException *e) {
[of_stderr writeLine: OF_LOCALIZED(
@"invalid_encoding",
@"%[prog]: Invalid encoding: %[encoding]",
@"prog", [OFApplication programName],
@"encoding", encodingString)];
|
|
|
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
[OFApplication terminateWithStatus: 1];
break;
}
}
@try {
if (encodingString != nil)
encoding = OFParseStringEncodingName(encodingString);
} @catch (OFInvalidArgumentException *e) {
[of_stderr writeLine: OF_LOCALIZED(
@"invalid_encoding",
@"%[prog]: Invalid encoding: %[encoding]",
@"prog", [OFApplication programName],
@"encoding", encodingString)];
|
︙ | | | ︙ | |
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
[OFApplication terminateWithStatus: _exitStatus];
}
- (id <Archive>)openArchiveWithPath: (OFString *)path
type: (OFString *)type
mode: (char)mode
encoding: (of_string_encoding_t)encoding
{
OFString *modeString, *fileModeString;
OFStream *file = nil;
id <Archive> archive = nil;
[_archivePath release];
_archivePath = [path copy];
|
|
|
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
[OFApplication terminateWithStatus: _exitStatus];
}
- (id <Archive>)openArchiveWithPath: (OFString *)path
type: (OFString *)type
mode: (char)mode
encoding: (OFStringEncoding)encoding
{
OFString *modeString, *fileModeString;
OFStream *file = nil;
id <Archive> archive = nil;
[_archivePath release];
_archivePath = [path copy];
|
︙ | | | ︙ | |