︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options
depth: (size_t)depth;
@end
@interface OFStringPlaceholder: OFString
@end
extern bool of_unicode_to_iso_8859_2(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToISO8859_2(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_iso_8859_3(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToISO8859_3(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_iso_8859_15(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToISO8859_15(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_windows_1251(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToWindows1251(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_windows_1252(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToWindows1252(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_codepage_437(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToCodepage437(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_codepage_850(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToCodepage850(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_codepage_858(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToCodepage858(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_mac_roman(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToMacRoman(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_koi8_r(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToKOI8R(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool of_unicode_to_koi8_u(const OFUnichar *, unsigned char *,
extern bool OFUnicodeToKOI8U(const OFUnichar *, unsigned char *,
size_t, bool);
/* References for static linking */
void
_references_to_categories_of_OFString(void)
{
_OFString_CryptographicHashing_reference = 1;
|
︙ | | |
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
-
+
|
return @"autodetect";
}
return nil;
}
size_t
of_string_utf8_encode(OFUnichar character, char *buffer)
OFUTF8StringEncode(OFUnichar character, char *buffer)
{
if (character < 0x80) {
buffer[0] = character;
return 1;
} else if (character < 0x800) {
buffer[0] = 0xC0 | (character >> 6);
buffer[1] = 0x80 | (character & 0x3F);
|
︙ | | |
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
-
+
|
return 4;
}
return 0;
}
ssize_t
of_string_utf8_decode(const char *buffer_, size_t length, OFUnichar *ret)
OFUTF8StringDecode(const char *buffer_, size_t length, OFUnichar *ret)
{
const unsigned char *buffer = (const unsigned char *)buffer_;
if (!(*buffer & 0x80)) {
*ret = buffer[0];
return 1;
}
|
︙ | | |
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
|
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
|
-
+
-
+
|
return 4;
}
return 0;
}
size_t
of_string_utf16_length(const OFChar16 *string)
OFUTF16StringLength(const OFChar16 *string)
{
size_t length = 0;
while (*string++ != 0)
length++;
return length;
}
size_t
of_string_utf32_length(const OFChar32 *string)
OFUTF32StringLength(const OFChar32 *string)
{
size_t length = 0;
while (*string++ != 0)
length++;
return length;
|
︙ | | |
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
|
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
|
-
+
-
+
-
+
-
+
|
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithUTF16String: (const OFChar16 *)string
{
return [self initWithUTF16String: string
length: of_string_utf16_length(string)
length: OFUTF16StringLength(string)
byteOrder: OFByteOrderNative];
}
- (instancetype)initWithUTF16String: (const OFChar16 *)string
length: (size_t)length
{
return [self initWithUTF16String: string
length: length
byteOrder: OFByteOrderNative];
}
- (instancetype)initWithUTF16String: (const OFChar16 *)string
byteOrder: (OFByteOrder)byteOrder
{
return [self initWithUTF16String: string
length: of_string_utf16_length(string)
length: OFUTF16StringLength(string)
byteOrder: byteOrder];
}
- (instancetype)initWithUTF16String: (const OFChar16 *)string
length: (size_t)length
byteOrder: (OFByteOrder)byteOrder
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithUTF32String: (const OFChar32 *)string
{
return [self initWithUTF32String: string
length: of_string_utf32_length(string)
length: OFUTF32StringLength(string)
byteOrder: OFByteOrderNative];
}
- (instancetype)initWithUTF32String: (const OFChar32 *)string
length: (size_t)length
{
return [self initWithUTF32String: string
length: length
byteOrder: OFByteOrderNative];
}
- (instancetype)initWithUTF32String: (const OFChar32 *)string
byteOrder: (OFByteOrder)byteOrder
{
return [self initWithUTF32String: string
length: of_string_utf32_length(string)
length: OFUTF32StringLength(string)
byteOrder: byteOrder];
}
- (instancetype)initWithUTF32String: (const OFChar32 *)string
length: (size_t)length
byteOrder: (OFByteOrder)byteOrder
{
|
︙ | | |
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
|
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
|
-
+
-
|
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],
size_t len = OFUTF8StringEncode(characters[i], buffer);
buffer);
/*
* Check for one more than the current index, as we
* need one for the terminating zero.
*/
if (j + len >= maxLength)
@throw [OFOutOfRangeException exception];
|
︙ | | |
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
|
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
|
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
|
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))
if (!OFUnicodeToISO8859_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))
if (!OFUnicodeToISO8859_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))
if (!OFUnicodeToISO8859_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,
if (!OFUnicodeToWindows1251(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,
if (!OFUnicodeToWindows1252(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,
if (!OFUnicodeToCodepage437(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,
if (!OFUnicodeToCodepage850(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,
if (!OFUnicodeToCodepage858(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))
if (!OFUnicodeToMacRoman(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))
if (!OFUnicodeToKOI8R(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))
if (!OFUnicodeToKOI8U(characters, (unsigned char *)cString,
length, lossy))
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
default:
|
︙ | | |
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
|
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
|
-
+
-
|
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],
size_t len = OFUTF8StringEncode(characters[i], buffer);
buffer);
if (len == 0)
@throw [OFInvalidEncodingException exception];
UTF8StringLength += len;
}
|
︙ | | |
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
|
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
|
-
+
-
+
-
+
-
+
|
minimumLength = (length > otherLength ? otherLength : length);
for (size_t i = 0; i < minimumLength; i++) {
OFUnichar c = characters[i];
OFUnichar oc = otherCharacters[i];
#ifdef OF_HAVE_UNICODE_TABLES
if (c >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
if (c >> 8 < OFUnicodeCaseFoldingTableSize) {
OFUnichar tc =
of_unicode_casefolding_table[c >> 8][c & 0xFF];
OFUnicodeCaseFoldingTable[c >> 8][c & 0xFF];
if (tc)
c = tc;
}
if (oc >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
if (oc >> 8 < OFUnicodeCaseFoldingTableSize) {
OFUnichar tc =
of_unicode_casefolding_table[oc >> 8][oc & 0xFF];
OFUnicodeCaseFoldingTable[oc >> 8][oc & 0xFF];
if (tc)
oc = tc;
}
#else
c = OFASCIIToUpper(c);
oc = OFASCIIToUpper(oc);
|
︙ | | |
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
|
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
|
-
-
+
+
-
-
+
+
|
return [data autorelease];
}
#ifdef OF_HAVE_UNICODE_TABLES
- (OFString *)decomposedStringWithCanonicalMapping
{
return decomposedString(self, of_unicode_decomposition_table,
OF_UNICODE_DECOMPOSITION_TABLE_SIZE);
return decomposedString(self, OFUnicodeDecompositionTable,
OFUnicodeDecompositionTableSize);
}
- (OFString *)decomposedStringWithCompatibilityMapping
{
return decomposedString(self, of_unicode_decomposition_compat_table,
OF_UNICODE_DECOMPOSITION_COMPAT_TABLE_SIZE);
return decomposedString(self, OFUnicodeDecompositionCompatTable,
OFUnicodeDecompositionCompatTableSize);
}
#endif
#ifdef OF_WINDOWS
- (OFString *)stringByExpandingWindowsEnvironmentStrings
{
if ([OFSystemInfo isWindowsNT]) {
|
︙ | | |
︙ | | |
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
70
|
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
70
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "unicode.h"
extern const OFChar16 of_iso_8859_2_table[];
extern const size_t of_iso_8859_2_table_offset;
extern const OFChar16 of_iso_8859_3_table[];
extern const size_t of_iso_8859_3_table_offset;
extern const OFChar16 of_iso_8859_15_table[];
extern const size_t of_iso_8859_15_table_offset;
extern const OFChar16 of_windows_1251_table[];
extern const size_t of_windows_1251_table_offset;
extern const OFChar16 of_windows_1252_table[];
extern const size_t of_windows_1252_table_offset;
extern const OFChar16 of_codepage_437_table[];
extern const size_t of_codepage_437_table_offset;
extern const OFChar16 of_codepage_850_table[];
extern const size_t of_codepage_850_table_offset;
extern const OFChar16 of_codepage_858_table[];
extern const size_t of_codepage_858_table_offset;
extern const OFChar16 of_mac_roman_table[];
extern const size_t of_mac_roman_table_offset;
extern const OFChar16 of_koi8_r_table[];
extern const size_t of_koi8_r_table_offset;
extern const OFChar16 of_koi8_u_table[];
extern const size_t of_koi8_u_table_offset;
extern const OFChar16 OFISO8859_2Table[];
extern const size_t OFISO8859_2TableOffset;
extern const OFChar16 OFISO8859_3Table[];
extern const size_t OFISO8859_3TableOffset;
extern const OFChar16 OFISO8859_15Table[];
extern const size_t OFISO8859_15TableOffset;
extern const OFChar16 OFWindows1251Table[];
extern const size_t OFWindows1251TableOffset;
extern const OFChar16 OFWindows1252Table[];
extern const size_t OFWindows1252TableOffset;
extern const OFChar16 OFCodepage437Table[];
extern const size_t OFCodepage437TableOffset;
extern const OFChar16 OFCodepage850Table[];
extern const size_t OFCodepage850TableOffset;
extern const OFChar16 OFCodepage858Table[];
extern const size_t OFCodepage858TableOffset;
extern const OFChar16 OFMacRomanTable[];
extern const size_t OFMacRomanTableOffset;
extern const OFChar16 OFKOI8RTable[];
extern const size_t OFKOI8RTableOffset;
extern const OFChar16 OFKOI8UTable[];
extern const size_t OFKOI8UTableOffset;
static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
for (size_t i = 0; i < length; i++) {
unsigned char f = first[i];
unsigned char s = second[i];
|
︙ | | |
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
-
+
|
return OFOrderedAscending;
}
return OFOrderedSame;
}
int
of_string_utf8_check(const char *UTF8String, size_t UTF8Length, size_t *length)
OFUTF8StringCheck(const char *UTF8String, size_t UTF8Length, size_t *length)
{
size_t tmpLength = UTF8Length;
int isUTF8 = 0;
for (size_t i = 0; i < UTF8Length; i++) {
/* No sign of UTF-8 here */
if OF_LIKELY (!(UTF8String[i] & 0x80))
|
︙ | | |
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
|
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
|
-
+
-
+
|
if (length != NULL)
*length = tmpLength;
return isUTF8;
}
size_t
of_string_utf8_get_index(const char *string, size_t position)
positionToIndex(const char *string, size_t position)
{
size_t idx = position;
for (size_t i = 0; i < position; i++)
if OF_UNLIKELY ((string[i] & 0xC0) == 0x80)
idx--;
return idx;
}
size_t
of_string_utf8_get_position(const char *string, size_t idx, size_t length)
OFUTF8StringIndexToPosition(const char *string, size_t idx, size_t length)
{
for (size_t i = 0; i <= idx; i++)
if OF_UNLIKELY ((string[i] & 0xC0) == 0x80)
if (++idx > length)
@throw [OFInvalidFormatException exception];
return idx;
|
︙ | | |
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
-
+
|
}
_s = &_storage;
_s->cString = storage;
_s->cStringLength = UTF8StringLength;
switch (of_string_utf8_check(UTF8String, UTF8StringLength,
switch (OFUTF8StringCheck(UTF8String, UTF8StringLength,
&_s->length)) {
case 1:
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
|
︙ | | |
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
-
+
|
_s->cString = OFAllocMemory(cStringLength + 1, 1);
_s->cStringLength = cStringLength;
_s->freeWhenDone = true;
if (encoding == OFStringEncodingUTF8 ||
encoding == OFStringEncodingASCII) {
switch (of_string_utf8_check(cString, cStringLength,
switch (OFUTF8StringCheck(cString, cStringLength,
&_s->length)) {
case 1:
if (encoding == OFStringEncodingASCII)
@throw [OFInvalidEncodingException
exception];
_s->isUTF8 = true;
|
︙ | | |
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
-
+
|
if (!(cString[i] & 0x80)) {
_s->cString[j++] = cString[i];
continue;
}
_s->isUTF8 = true;
bytes = of_string_utf8_encode(
bytes = OFUTF8StringEncode(
(uint8_t)cString[i], buffer);
if (bytes == 0)
@throw [OFInvalidEncodingException
exception];
_s->cStringLength += bytes - 1;
|
︙ | | |
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
348
349
350
351
352
|
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
348
349
350
351
352
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
return self;
}
switch (encoding) {
#define CASE(encoding, var) \
case encoding: \
table = var; \
tableOffset = var##_offset; \
tableOffset = var##Offset; \
break;
#ifdef HAVE_ISO_8859_2
CASE(OFStringEncodingISO8859_2, of_iso_8859_2_table)
CASE(OFStringEncodingISO8859_2, OFISO8859_2Table)
#endif
#ifdef HAVE_ISO_8859_3
CASE(OFStringEncodingISO8859_3, of_iso_8859_3_table)
CASE(OFStringEncodingISO8859_3, OFISO8859_3Table)
#endif
#ifdef HAVE_ISO_8859_15
CASE(OFStringEncodingISO8859_15, of_iso_8859_15_table)
CASE(OFStringEncodingISO8859_15, OFISO8859_15Table)
#endif
#ifdef HAVE_WINDOWS_1251
CASE(OFStringEncodingWindows1251, of_windows_1251_table)
CASE(OFStringEncodingWindows1251, OFWindows1251Table)
#endif
#ifdef HAVE_WINDOWS_1252
CASE(OFStringEncodingWindows1252, of_windows_1252_table)
CASE(OFStringEncodingWindows1252, OFWindows1252Table)
#endif
#ifdef HAVE_CODEPAGE_437
CASE(OFStringEncodingCodepage437, of_codepage_437_table)
CASE(OFStringEncodingCodepage437, OFCodepage437Table)
#endif
#ifdef HAVE_CODEPAGE_850
CASE(OFStringEncodingCodepage850, of_codepage_850_table)
CASE(OFStringEncodingCodepage850, OFCodepage850Table)
#endif
#ifdef HAVE_CODEPAGE_858
CASE(OFStringEncodingCodepage858, of_codepage_858_table)
CASE(OFStringEncodingCodepage858, OFCodepage858Table)
#endif
#ifdef HAVE_MAC_ROMAN
CASE(OFStringEncodingMacRoman, of_mac_roman_table)
CASE(OFStringEncodingMacRoman, OFMacRomanTable)
#endif
#ifdef HAVE_KOI8_R
CASE(OFStringEncodingKOI8R, of_koi8_r_table)
CASE(OFStringEncodingKOI8R, OFKOI8RTable)
#endif
#ifdef HAVE_KOI8_U
CASE(OFStringEncodingKOI8U, of_koi8_u_table)
CASE(OFStringEncodingKOI8U, OFKOI8UTable)
#endif
#undef CASE
default:
@throw [OFInvalidEncodingException exception];
}
j = 0;
|
︙ | | |
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
-
+
|
unichar = table[character - tableOffset];
if (unichar == 0xFFFF)
@throw [OFInvalidEncodingException exception];
_s->isUTF8 = true;
byteLength = of_string_utf8_encode(unichar, buffer);
byteLength = OFUTF8StringEncode(unichar, buffer);
if (byteLength == 0)
@throw [OFInvalidEncodingException exception];
_s->cStringLength += byteLength - 1;
_s->cString = OFResizeMemory(_s->cString,
_s->cStringLength + 1, 1);
|
︙ | | |
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
-
+
|
if (UTF8StringLength >= 3 &&
memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) {
UTF8String += 3;
UTF8StringLength -= 3;
}
switch (of_string_utf8_check(UTF8String, UTF8StringLength,
switch (OFUTF8StringCheck(UTF8String, UTF8StringLength,
&_s->length)) {
case 1:
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
|
︙ | | |
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
-
+
|
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
size_t len = of_string_utf8_encode(characters[i],
size_t len = OFUTF8StringEncode(characters[i],
_s->cString + j);
if (len == 0)
@throw [OFInvalidEncodingException exception];
if (len > 1)
_s->isUTF8 = true;
|
︙ | | |
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
-
+
|
character = (((character & 0x3FF) << 10) |
(nextCharacter & 0x3FF)) + 0x10000;
i++;
_s->length--;
}
len = of_string_utf8_encode(character, _s->cString + j);
len = OFUTF8StringEncode(character, _s->cString + j);
if (len == 0)
@throw [OFInvalidEncodingException exception];
if (len > 1)
_s->isUTF8 = true;
|
︙ | | |
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
|
-
+
|
_s->cString = OFAllocMemory((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
char buffer[4];
size_t len = of_string_utf8_encode((swap
size_t len = OFUTF8StringEncode((swap
? OFByteSwap32(characters[i])
: characters[i]),
buffer);
switch (len) {
case 1:
_s->cString[j++] = buffer[0];
|
︙ | | |
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
-
+
|
if ((cStringLength = OFVASPrintF(&tmp, format.UTF8String,
arguments)) == -1)
@throw [OFInvalidFormatException exception];
_s->cStringLength = cStringLength;
@try {
switch (of_string_utf8_check(tmp, cStringLength,
switch (OFUTF8StringCheck(tmp, cStringLength,
&_s->length)) {
case 1:
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
|
︙ | | |
869
870
871
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
|
869
870
871
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
|
-
+
-
+
-
+
-
+
-
+
-
+
|
i = j = 0;
while (i < _s->cStringLength && j < otherCStringLength) {
OFUnichar c1, c2;
ssize_t l1, l2;
l1 = of_string_utf8_decode(_s->cString + i,
l1 = OFUTF8StringDecode(_s->cString + i,
_s->cStringLength - i, &c1);
l2 = of_string_utf8_decode(otherCString + j,
l2 = OFUTF8StringDecode(otherCString + j,
otherCStringLength - j, &c2);
if (l1 <= 0 || l2 <= 0 || c1 > 0x10FFFF || c2 > 0x10FFFF)
@throw [OFInvalidEncodingException exception];
if (c1 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
if (c1 >> 8 < OFUnicodeCaseFoldingTableSize) {
OFUnichar tc =
of_unicode_casefolding_table[c1 >> 8][c1 & 0xFF];
OFUnicodeCaseFoldingTable[c1 >> 8][c1 & 0xFF];
if (tc)
c1 = tc;
}
if (c2 >> 8 < OF_UNICODE_CASEFOLDING_TABLE_SIZE) {
if (c2 >> 8 < OFUnicodeCaseFoldingTableSize) {
OFUnichar tc =
of_unicode_casefolding_table[c2 >> 8][c2 & 0xFF];
OFUnicodeCaseFoldingTable[c2 >> 8][c2 & 0xFF];
if (tc)
c2 = tc;
}
if (c1 > c2)
return OFOrderedDescending;
|
︙ | | |
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
|
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
|
-
+
|
OFHashInit(&hash);
for (size_t i = 0; i < _s->cStringLength; i++) {
OFUnichar c;
ssize_t length;
if ((length = of_string_utf8_decode(_s->cString + i,
if ((length = OFUTF8StringDecode(_s->cString + i,
_s->cStringLength - i, &c)) <= 0)
@throw [OFInvalidEncodingException exception];
OFHashAdd(&hash, (c & 0xFF0000) >> 16);
OFHashAdd(&hash, (c & 0x00FF00) >> 8);
OFHashAdd(&hash, c & 0x0000FF);
|
︙ | | |
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
|
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
|
-
+
-
-
+
+
|
if (idx >= _s->length)
@throw [OFOutOfRangeException exception];
if (!_s->isUTF8)
return _s->cString[idx];
idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength);
idx = OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength);
if (of_string_utf8_decode(_s->cString + idx,
_s->cStringLength - idx, &character) <= 0)
if (OFUTF8StringDecode(_s->cString + idx, _s->cStringLength - idx,
&character) <= 0)
@throw [OFInvalidEncodingException exception];
return character;
}
- (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range
{
|
︙ | | |
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
|
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
|
-
+
-
+
-
+
-
+
|
size_t rangeLocation, rangeLength;
if (range.length > SIZE_MAX - range.location ||
range.location + range.length > _s->length)
@throw [OFOutOfRangeException exception];
if (_s->isUTF8) {
rangeLocation = of_string_utf8_get_position(
rangeLocation = OFUTF8StringIndexToPosition(
_s->cString, range.location, _s->cStringLength);
rangeLength = of_string_utf8_get_position(
rangeLength = OFUTF8StringIndexToPosition(
_s->cString + rangeLocation, range.length,
_s->cStringLength - rangeLocation);
} else {
rangeLocation = range.location;
rangeLength = range.length;
}
if (cStringLength == 0)
return OFRangeMake(0, 0);
if (cStringLength > rangeLength)
return OFRangeMake(OFNotFound, 0);
if (options & OFStringSearchBackwards) {
for (size_t i = rangeLength - cStringLength;; i--) {
if (memcmp(_s->cString + rangeLocation + i, cString,
cStringLength) == 0) {
range.location += of_string_utf8_get_index(
range.location += positionToIndex(
_s->cString + rangeLocation, i);
range.length = string.length;
return range;
}
/* Did not match and we're at the last char */
if (i == 0)
return OFRangeMake(OFNotFound, 0);
}
} else {
for (size_t i = 0; i <= rangeLength - cStringLength; i++) {
if (memcmp(_s->cString + rangeLocation + i, cString,
cStringLength) == 0) {
range.location += of_string_utf8_get_index(
range.location += positionToIndex(
_s->cString + rangeLocation, i);
range.length = string.length;
return range;
}
}
}
|
︙ | | |
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
|
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
|
-
+
-
+
|
size_t start = range.location;
size_t end = range.location + range.length;
if (range.length > SIZE_MAX - range.location || end > _s->length)
@throw [OFOutOfRangeException exception];
if (_s->isUTF8) {
start = of_string_utf8_get_position(_s->cString, start,
start = OFUTF8StringIndexToPosition(_s->cString, start,
_s->cStringLength);
end = of_string_utf8_get_position(_s->cString, end,
end = OFUTF8StringIndexToPosition(_s->cString, end,
_s->cStringLength);
}
return [OFString stringWithUTF8String: _s->cString + start
length: end - start];
}
|
︙ | | |
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
|
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
|
-
+
|
OFUnichar *buffer = OFAllocMemory(_s->length, sizeof(OFUnichar));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
OFUnichar c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
cLen = OFUTF8StringDecode(_s->cString + i,
_s->cStringLength - i, &c);
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
|
︙ | | |
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
|
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
|
-
+
|
OFChar32 *buffer = OFAllocMemory(_s->length + 1, sizeof(OFChar32));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
OFChar32 c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
cLen = OFUTF8StringDecode(_s->cString + i,
_s->cStringLength - i, &c);
if (cLen <= 0 || c > 0x10FFFF) {
OFFreeMemory(buffer);
@throw [OFInvalidEncodingException exception];
}
|
︙ | | |
︙ | | |
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
|
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
|
-
+
|
4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319,
4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327,
4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335,
4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343,
4344, 4345, 4346, 0, 0, 4349, 4350, 4351,
};
static const OFUnichar casefoldingPage0[0x100] = {
static const OFUnichar caseFoldingPage0[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
|
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
|
-
+
|
248, 249, 250, 251, 252, 253, 254, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
static const OFUnichar casefoldingPage1[0x100] = {
static const OFUnichar caseFoldingPage1[0x100] = {
257, 0, 259, 0, 261, 0, 263, 0,
265, 0, 267, 0, 269, 0, 271, 0,
273, 0, 275, 0, 277, 0, 279, 0,
281, 0, 283, 0, 285, 0, 287, 0,
289, 0, 291, 0, 293, 0, 295, 0,
297, 0, 299, 0, 301, 0, 303, 0,
0, 0, 307, 0, 309, 0, 311, 0,
|
︙ | | |
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
|
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
|
-
+
|
0, 474, 0, 476, 0, 0, 479, 0,
481, 0, 483, 0, 485, 0, 487, 0,
489, 0, 491, 0, 493, 0, 495, 0,
0, 499, 499, 0, 501, 0, 405, 447,
505, 0, 507, 0, 509, 0, 511, 0,
};
static const OFUnichar casefoldingPage3[0x100] = {
static const OFUnichar caseFoldingPage3[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
|
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
|
-
+
|
985, 0, 987, 0, 989, 0, 991, 0,
993, 0, 995, 0, 997, 0, 999, 0,
1001, 0, 1003, 0, 1005, 0, 1007, 0,
954, 961, 0, 0, 952, 949, 0, 1016,
0, 1010, 1019, 0, 0, 891, 892, 893,
};
static const OFUnichar casefoldingPage19[0x100] = {
static const OFUnichar caseFoldingPage19[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
|
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
|
-
+
|
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
5104, 5105, 5106, 5107, 5108, 5109, 0, 0,
};
static const OFUnichar casefoldingPage28[0x100] = {
static const OFUnichar caseFoldingPage28[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
|
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
|
-
+
|
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
static const OFUnichar casefoldingPage30[0x100] = {
static const OFUnichar caseFoldingPage30[0x100] = {
7681, 0, 7683, 0, 7685, 0, 7687, 0,
7689, 0, 7691, 0, 7693, 0, 7695, 0,
7697, 0, 7699, 0, 7701, 0, 7703, 0,
7705, 0, 7707, 0, 7709, 0, 7711, 0,
7713, 0, 7715, 0, 7717, 0, 7719, 0,
7721, 0, 7723, 0, 7725, 0, 7727, 0,
7729, 0, 7731, 0, 7733, 0, 7735, 0,
|
︙ | | |
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
|
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
|
-
+
|
7897, 0, 7899, 0, 7901, 0, 7903, 0,
7905, 0, 7907, 0, 7909, 0, 7911, 0,
7913, 0, 7915, 0, 7917, 0, 7919, 0,
7921, 0, 7923, 0, 7925, 0, 7927, 0,
7929, 0, 7931, 0, 7933, 0, 7935, 0,
};
static const OFUnichar casefoldingPage31[0x100] = {
static const OFUnichar caseFoldingPage31[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943,
0, 0, 0, 0, 0, 0, 0, 0,
7952, 7953, 7954, 7955, 7956, 7957, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
|
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
|
-
+
|
8144, 8145, 8054, 8055, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8160, 8161, 8058, 8059, 8165, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8056, 8057, 8060, 8061, 8179, 0, 0, 0,
};
static const OFUnichar casefoldingPage171[0x100] = {
static const OFUnichar caseFoldingPage171[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
|
︙ | | |
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
|
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
|
-
+
|
"\x36", "\x37",
"\x38", "\x39",
NULL, NULL,
NULL, NULL,
NULL, NULL,
};
const OFUnichar *const of_unicode_uppercase_table[0x1EA] = {
const OFUnichar *const OFUnicodeUppercaseTable[0x1EA] = {
uppercasePage0, uppercasePage1, uppercasePage2, uppercasePage3,
uppercasePage4, uppercasePage5, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
uppercasePage16, emptyPage, emptyPage, uppercasePage19,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
|
︙ | | |
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
|
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
|
-
+
|
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, uppercasePage489
};
const OFUnichar *const of_unicode_lowercase_table[0x1EA] = {
const OFUnichar *const OFUnicodeLowercaseTable[0x1EA] = {
lowercasePage0, lowercasePage1, lowercasePage2, lowercasePage3,
lowercasePage4, lowercasePage5, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
lowercasePage16, emptyPage, emptyPage, lowercasePage19,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
|
︙ | | |
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
|
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
|
-
+
|
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, lowercasePage489
};
const OFUnichar *const of_unicode_titlecase_table[0x1EA] = {
const OFUnichar *const OFUnicodeTitlecaseTable[0x1EA] = {
uppercasePage0, titlecasePage1, uppercasePage2, uppercasePage3,
uppercasePage4, uppercasePage5, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
titlecasePage16, emptyPage, emptyPage, uppercasePage19,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
|
︙ | | |
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
|
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
|
-
-
-
+
+
+
-
+
-
-
+
+
|
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage, emptyPage,
emptyPage, uppercasePage489
};
const OFUnichar *const of_unicode_casefolding_table[0x1EA] = {
casefoldingPage0, casefoldingPage1, lowercasePage2,
casefoldingPage3, lowercasePage4, lowercasePage5,
const OFUnichar *const OFUnicodeCaseFoldingTable[0x1EA] = {
caseFoldingPage0, caseFoldingPage1, lowercasePage2,
caseFoldingPage3, lowercasePage4, lowercasePage5,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, lowercasePage16, emptyPage,
emptyPage, casefoldingPage19, emptyPage,
emptyPage, caseFoldingPage19, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, casefoldingPage28, emptyPage,
casefoldingPage30, casefoldingPage31, emptyPage,
emptyPage, caseFoldingPage28, emptyPage,
caseFoldingPage30, caseFoldingPage31, emptyPage,
lowercasePage33, emptyPage, emptyPage,
lowercasePage36, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, lowercasePage44,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
|
︙ | | |
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
|
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
|
-
+
|
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, lowercasePage166, lowercasePage167,
emptyPage, emptyPage, emptyPage,
casefoldingPage171, emptyPage, emptyPage,
caseFoldingPage171, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
|
︙ | | |
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
|
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
|
-
+
|
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
emptyPage, emptyPage, emptyPage,
lowercasePage489
};
const char *const *of_unicode_decomposition_table[0x2FB] = {
const char *const *OFUnicodeDecompositionTable[0x2FB] = {
decompositionPage0, decompositionPage1, decompositionPage2,
decompositionPage3, decompositionPage4, emptyDecompositionPage,
decompositionPage6, emptyDecompositionPage, emptyDecompositionPage,
decompositionPage9, decompositionPage10, decompositionPage11,
decompositionPage12, decompositionPage13, emptyDecompositionPage,
decompositionPage15, decompositionPage16, emptyDecompositionPage,
emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage,
|
︙ | | |
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
|
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
|
-
+
|
emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage,
emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage,
emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage,
emptyDecompositionPage, decompositionPage760, decompositionPage761,
decompositionPage762
};
const char *const *of_unicode_decomposition_compat_table[0x2FB] = {
const char *const *OFUnicodeDecompositionCompatTable[0x2FB] = {
decompCompatPage0, decompCompatPage1, decompCompatPage2,
decompCompatPage3, decompositionPage4, decompCompatPage5,
decompCompatPage6, emptyDecompositionPage, emptyDecompositionPage,
decompositionPage9, decompositionPage10, decompositionPage11,
decompCompatPage12, decompCompatPage13, decompCompatPage14,
decompCompatPage15, decompCompatPage16, emptyDecompositionPage,
emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage,
|
︙ | | |
︙ | | |
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
-
+
|
OFUnichar shortOption2, OFString *longOption2)
{
OFString *shortOption1Str = [OFString stringWithFormat: @"%C",
shortOption1];
OFString *shortOption2Str = [OFString stringWithFormat: @"%C",
shortOption2];
[of_stderr writeLine: OF_LOCALIZED(@"2_options_mutually_exclusive",
[OFStdErr writeLine: OF_LOCALIZED(@"2_options_mutually_exclusive",
@"Error: -%[shortopt1] / --%[longopt1] and "
@"-%[shortopt2] / --%[longopt2] "
@"are mutually exclusive!",
@"shortopt1", shortOption1Str,
@"longopt1", longOption1,
@"shortopt2", shortOption2Str,
@"longopt2", longOption2)];
|
︙ | | |
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
-
+
-
+
|
OFString *shortOption3Str = [OFString stringWithFormat: @"%C",
shortOption3];
OFString *shortOption4Str = [OFString stringWithFormat: @"%C",
shortOption4];
OFString *shortOption5Str = [OFString stringWithFormat: @"%C",
shortOption5];
[of_stderr writeLine: OF_LOCALIZED(@"5_options_mutually_exclusive",
[OFStdErr writeLine: OF_LOCALIZED(@"5_options_mutually_exclusive",
@"Error: -%[shortopt1] / --%[longopt1], "
@"-%[shortopt2] / --%[longopt2], -%[shortopt3] / --%[longopt3], "
@"-%[shortopt4] / --%[longopt4] and\n"
@" -%[shortopt5] / --%[longopt5] are mutually exclusive!",
@"shortopt1", shortOption1Str,
@"longopt1", longOption1,
@"shortopt2", shortOption2Str,
@"longopt2", longOption2,
@"shortopt3", shortOption3Str,
@"longopt3", longOption3,
@"shortopt4", shortOption4Str,
@"longopt4", longOption4,
@"shortopt5", shortOption5Str,
@"longopt5", longOption5)];
[OFApplication terminateWithStatus: 1];
}
static void
writingNotSupported(OFString *type)
{
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"writing_not_supported",
@"Writing archives of type %[type] is not (yet) supported!",
@"type", type)];
}
@implementation OFArc
- (void)applicationDidFinishLaunching
|
︙ | | |
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
284
285
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
|
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
284
285
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
'l', @"list",
'p', @"print",
'x', @"extract");
mode = option;
break;
case 'h':
help(of_stdout, true, 0);
help(OFStdOut, true, 0);
break;
case '=':
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"option_takes_no_argument",
@"%[prog]: Option --%[opt] takes no argument",
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
[OFApplication terminateWithStatus: 1];
break;
case ':':
if (optionsParser.lastLongOption != nil)
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"long_option_requires_argument",
@"%[prog]: Option --%[opt] requires an "
@"argument",
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
else {
OFString *optStr = [OFString
stringWithFormat: @"%C",
optionsParser.lastOption];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"option_requires_argument",
@"%[prog]: Option -%[opt] requires an "
@"argument",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
break;
case '?':
if (optionsParser.lastLongOption != nil)
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"unknown_long_option",
@"%[prog]: Unknown option: --%[opt]",
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
else {
OFString *optStr = [OFString
stringWithFormat: @"%C",
optionsParser.lastOption];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"unknown_option",
@"%[prog]: Unknown option: -%[opt]",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
break;
}
}
@try {
if (encodingString != nil)
encoding = OFStringEncodingParseName(encodingString);
} @catch (OFInvalidArgumentException *e) {
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"invalid_encoding",
@"%[prog]: Invalid encoding: %[encoding]",
@"prog", [OFApplication programName],
@"encoding", encodingString)];
[OFApplication terminateWithStatus: 1];
}
remainingArguments = optionsParser.remainingArguments;
switch (mode) {
case 'a':
case 'c':
if (remainingArguments.count < 1)
help(of_stderr, false, 1);
help(OFStdErr, false, 1);
files = [remainingArguments objectsInRange:
OFRangeMake(1, remainingArguments.count - 1)];
#ifdef OF_HAVE_SANDBOX
if (![remainingArguments.firstObject isEqual: @"-"])
[sandbox unveilPath: remainingArguments.firstObject
|
︙ | | |
336
337
338
339
340
341
342
343
344
345
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
|
336
337
338
339
340
341
342
343
344
345
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
|
-
+
-
+
|
mode: mode
encoding: encoding];
[archive addFiles: files];
break;
case 'l':
if (remainingArguments.count != 1)
help(of_stderr, false, 1);
help(OFStdErr, false, 1);
#ifdef OF_HAVE_SANDBOX
if (![remainingArguments.firstObject isEqual: @"-"])
[sandbox unveilPath: remainingArguments.firstObject
permissions: @"r"];
sandbox.allowsUnveil = false;
[OFApplication of_activateSandbox: sandbox];
#endif
archive = [self
openArchiveWithPath: remainingArguments.firstObject
type: type
mode: mode
encoding: encoding];
[archive listFiles];
break;
case 'p':
if (remainingArguments.count < 1)
help(of_stderr, false, 1);
help(OFStdErr, false, 1);
#ifdef OF_HAVE_SANDBOX
if (![remainingArguments.firstObject isEqual: @"-"])
[sandbox unveilPath: remainingArguments.firstObject
permissions: @"r"];
sandbox.allowsUnveil = false;
|
︙ | | |
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
-
+
|
mode: mode
encoding: encoding];
[archive printFiles: files];
break;
case 'x':
if (remainingArguments.count < 1)
help(of_stderr, false, 1);
help(OFStdErr, false, 1);
files = [remainingArguments objectsInRange:
OFRangeMake(1, remainingArguments.count - 1)];
#ifdef OF_HAVE_SANDBOX
if (![remainingArguments.firstObject isEqual: @"-"])
[sandbox unveilPath: remainingArguments.firstObject
|
︙ | | |
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
|
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
|
-
-
+
+
-
-
+
+
-
+
|
@try {
[archive extractFiles: files];
} @catch (OFCreateDirectoryFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeString: @"\r"];
[OFStdErr writeLine: OF_LOCALIZED(
@"failed_to_create_directory",
@"Failed to create directory %[dir]: %[error]",
@"dir", e.URL.fileSystemRepresentation,
@"error", error)];
_exitStatus = 1;
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeString: @"\r"];
[OFStdErr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", e.path,
@"error", error)];
_exitStatus = 1;
}
break;
default:
help(of_stderr, true, 1);
help(OFStdErr, true, 1);
break;
}
[OFApplication terminateWithStatus: _exitStatus];
}
- (id <Archive>)openArchiveWithPath: (OFString *)path
|
︙ | | |
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
-
+
-
+
-
-
+
+
|
@throw [OFInvalidArgumentException exception];
}
if ([path isEqual: @"-"]) {
switch (mode) {
case 'a':
case 'c':
file = of_stdout;
file = OFStdOut;
break;
case 'l':
case 'p':
case 'x':
file = of_stdin;
file = OFStdIn;
break;
default:
@throw [OFInvalidArgumentException exception];
}
} else {
@try {
file = [OFFile fileWithPath: path mode: fileModeString];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stderr writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeString: @"\r"];
[OFStdErr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", e.path,
@"error", error)];
[OFApplication terminateWithStatus: 1];
}
}
|
︙ | | |
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
-
+
-
+
-
+
-
+
|
mode: modeString
encoding: encoding];
} else if ([type isEqual: @"zip"])
archive = [ZIPArchive archiveWithStream: file
mode: modeString
encoding: encoding];
else {
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"unknown_archive_type",
@"Unknown archive type: %[type]",
@"type", type)];
goto error;
}
} @catch (OFNotImplementedException *e) {
if ((mode == 'a' || mode == 'c') && sel_isEqual(e.selector,
@selector(initWithStream:mode:))) {
writingNotSupported(type);
goto error;
}
@throw e;
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
[OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFSeekFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file",
[OFStdErr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file",
@"Failed to seek in file %[file]: %[error]",
@"file", path,
@"error", error)];
goto error;
} @catch (OFInvalidFormatException *e) {
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"file_is_not_a_valid_archive",
@"File %[file] is not a valid archive!",
@"file", path)];
goto error;
}
if ((mode == 'a' || mode == 'c') &&
|
︙ | | |
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
653
654
655
656
657
658
659
660
661
662
663
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
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
653
654
655
656
657
658
659
660
661
662
663
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
|
if (_overwrite == 1 ||
![[OFFileManager defaultManager] fileExistsAtPath: outFileName])
return true;
if (_overwrite == -1) {
if (_outputLevel >= 0) {
[of_stdout writeString: @" "];
[of_stdout writeLine:
[OFStdOut writeString: @" "];
[OFStdOut writeLine:
OF_LOCALIZED(@"file_skipped", @"skipped")];
}
return false;
}
do {
[of_stderr writeString: @"\r"];
[of_stderr writeString: OF_LOCALIZED(@"ask_overwrite",
[OFStdErr writeString: @"\r"];
[OFStdErr writeString: OF_LOCALIZED(@"ask_overwrite",
@"Overwrite %[file]? [ynAN?]",
@"file", fileName)];
[of_stderr writeString: @" "];
[OFStdErr writeString: @" "];
line = [of_stdin readLine];
line = [OFStdIn readLine];
if ([line isEqual: @"?"])
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"ask_overwrite_help",
@" y: yes\n"
@" n: no\n"
@" A: always\n"
@" N: never")];
} while (![line isEqual: @"y"] && ![line isEqual: @"n"] &&
![line isEqual: @"N"] && ![line isEqual: @"A"]);
if ([line isEqual: @"A"])
_overwrite = 1;
else if ([line isEqual: @"N"])
_overwrite = -1;
if ([line isEqual: @"n"] || [line isEqual: @"N"]) {
if (_outputLevel >= 0)
[of_stdout writeLine: OF_LOCALIZED(@"skipping_file",
[OFStdOut writeLine: OF_LOCALIZED(@"skipping_file",
@"Skipping %[file]...",
@"file", fileName)];
return false;
}
if (_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"extracting_file",
[OFStdOut writeString: OF_LOCALIZED(@"extracting_file",
@"Extracting %[file]...",
@"file", fileName)];
return true;
}
- (ssize_t)copyBlockFromStream: (OFStream *)input
toStream: (OFStream *)output
fileName: (OFString *)fileName
{
char buffer[BUFFER_SIZE];
size_t length;
@try {
length = [input readIntoBuffer: buffer length: BUFFER_SIZE];
} @catch (OFReadFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_read_file",
[OFStdOut writeString: @"\r"];
[OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file",
@"Failed to read file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
@try {
[output writeBuffer: buffer length: length];
} @catch (OFWriteFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[of_stdout writeString: @"\r"];
[of_stderr writeLine: OF_LOCALIZED(@"failed_to_write_file",
[OFStdOut writeString: @"\r"];
[OFStdErr writeLine: OF_LOCALIZED(@"failed_to_write_file",
@"Failed to write file %[file]: %[error]",
@"file", fileName,
@"error", error)];
return -1;
}
return length;
|
︙ | | |
︙ | | |
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
-
+
|
@end
OF_APPLICATION_DELEGATE(OFHTTP)
static void
help(OFStream *stream, bool full, int status)
{
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"usage",
@"Usage: %[prog] -[cehHmoOPqv] url1 [url2 ...]",
@"prog", [OFApplication programName])];
if (full) {
[stream writeString: @"\n"];
[stream writeLine: OF_LOCALIZED(@"full_usage",
|
︙ | | |
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
-
+
|
#ifdef OF_HAVE_PLUGINS
+ (void)initialize
{
if (self != [OFHTTP class])
return;
/* Opportunistically try loading ObjOpenSSL and ignore any errors. */
OFDlopen(@LIB_PREFIX @"objopenssl" @LIB_SUFFIX, OF_RTLD_LAZY);
OFDlOpen(@LIB_PREFIX @"objopenssl" @LIB_SUFFIX, OF_RTLD_LAZY);
}
#endif
- (instancetype)init
{
self = [super init];
|
︙ | | |
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
-
+
|
- (void)addHeader: (OFString *)header
{
size_t pos = [header rangeOfString: @":"].location;
OFString *name, *value;
if (pos == OFNotFound) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_header",
[OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_header",
@"%[prog]: Headers must to be in format name:value!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
name = [header substringToIndex: pos]
.stringByDeletingEnclosingWhitespaces;
|
︙ | | |
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
-
+
|
{
OFString *contentLength = nil;
[_body release];
_body = nil;
if ([path isEqual: @"-"])
_body = [of_stdin copy];
_body = [OFStdIn copy];
else {
_body = [[OFFile alloc] initWithPath: path mode: @"r"];
@try {
unsigned long long fileSize =
[[OFFileManager defaultManager]
attributesOfItemAtPath: path].fileSize;
|
︙ | | |
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
-
+
|
void *pool = objc_autoreleasePoolPush();
method = method.uppercaseString;
@try {
_method = OFHTTPRequestMethodParseName(method);
} @catch (OFInvalidArgumentException *e) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method",
[OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_method",
@"%[prog]: Invalid request method %[method]!",
@"prog", [OFApplication programName],
@"method", method)];
[OFApplication terminateWithStatus: 1];
}
objc_autoreleasePoolPop(pool);
|
︙ | | |
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
-
+
|
if (port > UINT16_MAX)
@throw [OFOutOfRangeException exception];
[OFTCPSocket setSOCKS5Host: host];
[OFTCPSocket setSOCKS5Port: (uint16_t)port];
} @catch (OFInvalidFormatException *e) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_proxy",
[OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_proxy",
@"%[prog]: Proxy must to be in format host:port!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
}
- (void)applicationDidFinishLaunching
|
︙ | | |
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
-
+
-
+
-
+
-
+
-
+
-
+
|
optionsParser = [OFOptionsParser parserWithOptions: options];
while ((option = [optionsParser nextOption]) != '\0') {
switch (option) {
case 'b':
[self setBody: optionsParser.argument];
break;
case 'h':
help(of_stdout, true, 0);
help(OFStdOut, true, 0);
break;
case 'H':
[self addHeader: optionsParser.argument];
break;
case 'm':
[self setMethod: optionsParser.argument];
break;
case 'P':
[self setProxy: optionsParser.argument];
break;
case ':':
if (optionsParser.lastLongOption != nil)
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"long_argument_missing",
@"%[prog]: Argument for option --%[opt] "
@"missing"
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
else {
OFString *optStr = [OFString
stringWithFormat: @"%c",
optionsParser.lastOption];
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"argument_missing",
@"%[prog]: Argument for option -%[opt] "
@"missing",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
break;
case '=':
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"option_takes_no_argument",
@"%[prog]: Option --%[opt] takes no argument",
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
[OFApplication terminateWithStatus: 1];
break;
case '?':
if (optionsParser.lastLongOption != nil)
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"unknown_long_option",
@"%[prog]: Unknown option: --%[opt]",
@"prog", [OFApplication programName],
@"opt", optionsParser.lastLongOption)];
else {
OFString *optStr = [OFString
stringWithFormat: @"%c",
optionsParser.lastOption];
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"unknown_option",
@"%[prog]: Unknown option: -%[opt]",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
|
︙ | | |
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
-
+
-
+
-
+
-
+
|
[OFApplication of_activateSandbox: sandbox];
#endif
_outputPath = [outputPath copy];
_URLs = [optionsParser.remainingArguments copy];
if (_URLs.count < 1)
help(of_stderr, false, 1);
help(OFStdErr, false, 1);
if (_quiet && _verbose) {
[of_stderr writeLine: OF_LOCALIZED(@"quiet_xor_verbose",
[OFStdErr writeLine: OF_LOCALIZED(@"quiet_xor_verbose",
@"%[prog]: -q / --quiet and -v / --verbose are mutually "
@"exclusive!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
if (_outputPath != nil && _detectFileName) {
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"output_xor_detect_filename",
@"%[prog]: -o / --output and -O / --detect-filename are "
@"mutually exclusive!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
if (_outputPath != nil && _URLs.count > 1) {
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"output_only_with_one_url",
@"%[prog]: Cannot use -o / --output when more than one URL "
@"has been specified!",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
|
︙ | | |
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
-
+
-
+
-
+
|
response.headers;
OFEnumerator *keyEnumerator = [headers keyEnumerator];
OFEnumerator *objectEnumerator = [headers objectEnumerator];
OFString *key, *object;
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil)
[of_stdout writeFormat: @" %@: %@\n", key, object];
[OFStdOut writeFormat: @" %@: %@\n", key, object];
objc_autoreleasePoolPop(pool);
}
if (!_quiet) {
if (_useUnicode)
[of_stdout writeFormat: @"☇ %@", URL.string];
[OFStdOut writeFormat: @"☇ %@", URL.string];
else
[of_stdout writeFormat: @"< %@", URL.string];
[OFStdOut writeFormat: @"< %@", URL.string];
}
_length = 0;
return true;
}
|
︙ | | |
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
-
-
+
+
-
+
|
[_progressBar stop];
[_progressBar draw];
[_progressBar release];
_progressBar = nil;
if (!_quiet) {
[of_stdout writeString: @"\n "];
[of_stdout writeLine: OF_LOCALIZED(@"download_error",
[OFStdOut writeString: @"\n "];
[OFStdOut writeLine: OF_LOCALIZED(@"download_error",
@"Error!")];
}
URL = [_URLs objectAtIndex: _URLIndex - 1];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"download_failed_exception",
@"%[prog]: Failed to download <%[url]>!\n"
@" %[exception]",
@"prog", [OFApplication programName],
@"url", URL,
@"exception", exception)];
|
︙ | | |
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
-
-
+
+
|
if (response.atEndOfStream) {
[_progressBar stop];
[_progressBar draw];
[_progressBar release];
_progressBar = nil;
if (!_quiet) {
[of_stdout writeString: @"\n "];
[of_stdout writeLine:
[OFStdOut writeString: @"\n "];
[OFStdOut writeLine:
OF_LOCALIZED(@"download_done", @"Done!")];
}
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
return false;
}
|
︙ | | |
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
-
+
-
+
|
if (!_quiet) {
OFString *lengthString =
[headers objectForKey: @"Content-Length"];
OFString *type = [headers objectForKey: @"Content-Type"];
if (_useUnicode)
[of_stdout writeFormat: @" ➜ %hd\n", statusCode];
[OFStdOut writeFormat: @" ➜ %hd\n", statusCode];
else
[of_stdout writeFormat: @" -> %hd\n", statusCode];
[OFStdOut writeFormat: @" -> %hd\n", statusCode];
if (type == nil)
type = OF_LOCALIZED(@"type_unknown", @"unknown");
if (lengthString != nil) {
_length = lengthString.unsignedLongLongValue;
|
︙ | | |
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
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
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
|
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
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
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
|
-
-
+
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
OFEnumerator OF_GENERIC(OFString *) *keyEnumerator =
[headers keyEnumerator];
OFEnumerator OF_GENERIC(OFString *) *objectEnumerator =
[headers objectEnumerator];
OFString *key, *object;
if (statusCode / 100 == 2 && _currentFileName != nil) {
[of_stdout writeString: @" "];
[of_stdout writeLine: OF_LOCALIZED(
[OFStdOut writeString: @" "];
[OFStdOut writeLine: OF_LOCALIZED(
@"info_name_unaligned",
@"Name: %[name]",
@"name", _currentFileName)];
}
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil)
[of_stdout writeFormat: @" %@: %@\n",
key, object];
[OFStdOut writeFormat: @" %@: %@\n",
key, object];
objc_autoreleasePoolPop(pool);
} else if (statusCode / 100 == 2 && !_detectFileNameRequest) {
[of_stdout writeString: @" "];
[OFStdOut writeString: @" "];
if (_currentFileName != nil)
[of_stdout writeLine: OF_LOCALIZED(@"info_name",
[OFStdOut writeLine: OF_LOCALIZED(@"info_name",
@"Name: %[name]",
@"name", _currentFileName)];
[of_stdout writeString: @" "];
[of_stdout writeLine: OF_LOCALIZED(@"info_type",
[OFStdOut writeString: @" "];
[OFStdOut writeLine: OF_LOCALIZED(@"info_type",
@"Type: %[type]",
@"type", type)];
[of_stdout writeString: @" "];
[of_stdout writeLine: OF_LOCALIZED(@"info_size",
[OFStdOut writeString: @" "];
[OFStdOut writeLine: OF_LOCALIZED(@"info_size",
@"Size: %[size]",
@"size", lengthString)];
}
}
}
- (void)client: (OFHTTPClient *)client
didPerformRequest: (OFHTTPRequest *)request
response: (OFHTTPResponse *)response
exception: (id)exception
{
if (exception != nil) {
if ([exception isKindOfClass:
[OFResolveHostFailedException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[OFStdOut writeString: @"\n"];
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"download_resolve_host_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" Failed to resolve host: %[exception]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"exception", exception)];
} else if ([exception isKindOfClass:
[OFConnectionFailedException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[OFStdOut writeString: @"\n"];
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"download_failed_connection_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" Connection failed: %[exception]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"exception", exception)];
} else if ([exception isKindOfClass:
[OFInvalidServerReplyException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[OFStdOut writeString: @"\n"];
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"download_failed_invalid_server_reply",
@"%[prog]: Failed to download <%[url]>!\n"
@" Invalid server reply!",
@"prog", [OFApplication programName],
@"url", request.URL.string)];
} else if ([exception isKindOfClass:
[OFUnsupportedProtocolException class]]) {
if (!_quiet)
[of_stdout writeString: @"\n"];
[OFStdOut writeString: @"\n"];
[of_stderr writeLine: OF_LOCALIZED(@"no_ssl_library",
[OFStdErr writeLine: OF_LOCALIZED(@"no_ssl_library",
@"%[prog]: No TLS library loaded!\n"
@" In order to download via https, you need to "
@"preload an TLS library for ObjFW\n"
@" such as ObjOpenSSL!",
@"prog", [OFApplication programName])];
} else if ([exception isKindOfClass:
[OFReadOrWriteFailedException class]]) {
OFString *error = OF_LOCALIZED(
@"download_failed_read_or_write_failed_any",
@"Read or write failed");
if (!_quiet)
[of_stdout writeString: @"\n"];
[OFStdOut writeString: @"\n"];
if ([exception isKindOfClass:
[OFReadFailedException class]])
error = OF_LOCALIZED(
@"download_failed_read_or_write_failed_"
@"read",
@"Read failed");
else if ([exception isKindOfClass:
[OFWriteFailedException class]])
error = OF_LOCALIZED(
@"download_failed_read_or_write_failed_"
@"write",
@"Write failed");
[of_stderr writeLine: OF_LOCALIZED(
[OFStdErr writeLine: OF_LOCALIZED(
@"download_failed_read_or_write_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" %[error]: %[exception]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"error", error,
@"exception", exception)];
} else if ([exception isKindOfClass:
[OFHTTPRequestFailedException class]]) {
short statusCode;
OFString *codeString;
if (_ignoreStatus) {
exception = nil;
goto after_exception_handling;
}
statusCode = response.statusCode;
codeString = [OFString stringWithFormat: @"%hd %@",
statusCode, OFHTTPStatusCodeString(statusCode)];
[of_stderr writeLine: OF_LOCALIZED(@"download_failed",
[OFStdErr writeLine: OF_LOCALIZED(@"download_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" HTTP status code: %[code]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"code", codeString)];
} else
@throw exception;
|
︙ | | |
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
|
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
|
-
+
-
+
-
+
|
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
return;
}
if ([_outputPath isEqual: @"-"])
_output = of_stdout;
_output = [OFStdOut copy];
else {
if (!_continue && !_force && [[OFFileManager defaultManager]
fileExistsAtPath: _currentFileName]) {
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"output_already_exists",
@"%[prog]: File %[filename] already exists!",
@"prog", [OFApplication programName],
@"filename", _currentFileName)];
_errorCode = 1;
goto next;
}
@try {
OFString *mode =
(response.statusCode == 206 ? @"a" : @"w");
_output = [[OFFile alloc] initWithPath: _currentFileName
mode: mode];
} @catch (OFOpenItemFailedException *e) {
[of_stderr writeLine:
[OFStdErr writeLine:
OF_LOCALIZED(@"failed_to_open_output",
@"%[prog]: Failed to open file %[filename]: "
@"%[exception]",
@"prog", [OFApplication programName],
@"filename", _currentFileName,
@"exception", e)];
|
︙ | | |
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
|
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
|
-
+
-
+
-
+
-
+
-
+
|
OFString *URLString = nil;
OFURL *URL;
OFMutableDictionary *clientHeaders;
OFHTTPRequest *request;
_received = _length = _resumedFrom = 0;
if (_output != of_stdout)
if (_output != OFStdOut)
[_output release];
_output = nil;
if (_URLIndex >= _URLs.count)
[OFApplication terminateWithStatus: _errorCode];
@try {
URLString = [_URLs objectAtIndex: _URLIndex++];
URL = [OFURL URLWithString: URLString];
} @catch (OFInvalidFormatException *e) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_url",
[OFStdErr writeLine: OF_LOCALIZED(@"invalid_url",
@"%[prog]: Invalid URL: <%[url]>!",
@"prog", [OFApplication programName],
@"url", URLString)];
_errorCode = 1;
goto next;
}
if (![URL.scheme isEqual: @"http"] && ![URL.scheme isEqual: @"https"]) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_scheme",
[OFStdErr writeLine: OF_LOCALIZED(@"invalid_scheme",
@"%[prog]: Invalid scheme: <%[url]>!",
@"prog", [OFApplication programName],
@"url", URLString)];
_errorCode = 1;
goto next;
}
clientHeaders = [[_clientHeaders mutableCopy] autorelease];
if (_detectFileName && !_detectedFileName) {
if (!_quiet) {
if (_useUnicode)
[of_stdout writeFormat: @"⠒ %@", URL.string];
[OFStdOut writeFormat: @"⠒ %@", URL.string];
else
[of_stdout writeFormat: @"? %@", URL.string];
[OFStdOut writeFormat: @"? %@", URL.string];
}
request = [OFHTTPRequest requestWithURL: URL];
request.headers = clientHeaders;
request.method = OFHTTPRequestMethodHead;
_detectFileNameRequest = true;
|
︙ | | |
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
-
+
-
+
|
[clientHeaders setObject: range forKey: @"Range"];
} @catch (OFRetrieveItemAttributesFailedException *e) {
}
}
if (!_quiet) {
if (_useUnicode)
[of_stdout writeFormat: @"⇣ %@", URL.string];
[OFStdOut writeFormat: @"⇣ %@", URL.string];
else
[of_stdout writeFormat: @"< %@", URL.string];
[OFStdOut writeFormat: @"< %@", URL.string];
}
request = [OFHTTPRequest requestWithURL: URL];
request.headers = clientHeaders;
request.method = _method;
_detectFileNameRequest = false;
|
︙ | | |