︙ | | |
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
|
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
|
-
+
-
-
+
+
-
+
|
return [self readTillDelimiter: delimiter
withEncoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString*)readTillDelimiter: (OFString*)delimiter
withEncoding: (of_string_encoding_t)encoding
{
const char *delimiterCString;
const char *delimiterUTF8String;
size_t i, j, delimiterLength, bufferLength, retLength;
char *retCString, *buffer, *newCache;
OFString *ret;
/* FIXME: Convert delimiter to specified charset */
delimiterCString = [delimiter cString];
delimiterLength = [delimiter cStringLength];
delimiterUTF8String = [delimiter UTF8String];
delimiterLength = [delimiter UTF8StringLength];
j = 0;
if (delimiterLength == 0)
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
/* Look if there's something in our cache */
if (cache != NULL) {
for (i = 0; i < cacheLength; i++) {
if (cache[i] != delimiterCString[j++])
if (cache[i] != delimiterUTF8String[j++])
j = 0;
if (j == delimiterLength || cache[i] == '\0') {
if (cache[i] == '\0')
delimiterLength = 1;
ret = [OFString
|
︙ | | |
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
-
+
|
}
bufferLength = [self _readNBytes: of_pagesize
intoBuffer: buffer];
/* Look if there's the delimiter or \0 */
for (i = 0; i < bufferLength; i++) {
if (buffer[i] != delimiterCString[j++])
if (buffer[i] != delimiterUTF8String[j++])
j = 0;
if (j == delimiterLength || buffer[i] == '\0') {
if (buffer[i] == '\0')
delimiterLength = 1;
retLength = cacheLength + i + 1 -
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
fromBuffer: [dataArray cArray]];
return [dataArray count] * [dataArray itemSize];
}
- (size_t)writeString: (OFString*)string
{
size_t length = [string cStringLength];
size_t length = [string UTF8StringLength];
[self writeNBytes: length
fromBuffer: [string cString]];
fromBuffer: [string UTF8String]];
return length;
}
- (size_t)writeLine: (OFString*)string
{
size_t stringLength = [string cStringLength];
size_t stringLength = [string UTF8StringLength];
char *buffer;
buffer = [self allocMemoryWithSize: stringLength + 1];
@try {
memcpy(buffer, [string cString], stringLength);
memcpy(buffer, [string UTF8String], stringLength);
buffer[stringLength] = '\n';
[self writeNBytes: stringLength + 1
fromBuffer: buffer];
} @finally {
[self freeMemory: buffer];
}
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
|
return ret;
}
- (size_t)writeFormat: (OFConstantString*)format
withArguments: (va_list)arguments
{
char *cString;
char *UTF8String;
int length;
if (format == nil)
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
if ((length = of_vasprintf(&cString, [format cString],
if ((length = of_vasprintf(&UTF8String, [format UTF8String],
arguments)) == -1)
@throw [OFInvalidFormatException newWithClass: isa];
@try {
[self writeNBytes: length
fromBuffer: cString];
fromBuffer: UTF8String];
} @finally {
free(cString);
free(UTF8String);
}
return length;
}
- (size_t)pendingBytes
{
|
︙ | | |