︙ | | | ︙ | |
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
bytesRead = [self
lowlevelReadIntoBuffer: tmp
length: MIN_READ_SIZE];
if (bytesRead > length) {
memcpy(buffer, tmp, length);
readBuffer = of_malloc(bytesRead - length, 1);
memcpy(readBuffer, tmp + length,
bytesRead - length);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bytesRead - length;
return length;
|
|
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
bytesRead = [self
lowlevelReadIntoBuffer: tmp
length: MIN_READ_SIZE];
if (bytesRead > length) {
memcpy(buffer, tmp, length);
readBuffer = of_alloc(bytesRead - length, 1);
memcpy(readBuffer, tmp + length,
bytesRead - length);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bytesRead - length;
return length;
|
︙ | | | ︙ | |
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
|
{
OFData *ret;
char *buffer;
if OF_UNLIKELY (count > SIZE_MAX / itemSize)
@throw [OFOutOfRangeException exception];
buffer = of_malloc(count, itemSize);
@try {
[self readIntoBuffer: buffer
exactLength: count * itemSize];
ret = [OFData dataWithItemsNoCopy: buffer
count: count
itemSize: itemSize
freeWhenDone: true];
} @catch (id e) {
free(buffer);
@throw e;
}
return ret;
}
- (OFData *)readDataUntilEndOfStream
{
OFMutableData *data = [OFMutableData data];
size_t pageSize = [OFSystemInfo pageSize];
char *buffer = of_malloc(1, pageSize);
@try {
while (!self.atEndOfStream) {
size_t length;
length = [self readIntoBuffer: buffer
length: pageSize];
|
|
|
|
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
|
{
OFData *ret;
char *buffer;
if OF_UNLIKELY (count > SIZE_MAX / itemSize)
@throw [OFOutOfRangeException exception];
buffer = of_alloc(count, itemSize);
@try {
[self readIntoBuffer: buffer
exactLength: count * itemSize];
ret = [OFData dataWithItemsNoCopy: buffer
count: count
itemSize: itemSize
freeWhenDone: true];
} @catch (id e) {
free(buffer);
@throw e;
}
return ret;
}
- (OFData *)readDataUntilEndOfStream
{
OFMutableData *data = [OFMutableData data];
size_t pageSize = [OFSystemInfo pageSize];
char *buffer = of_alloc(1, pageSize);
@try {
while (!self.atEndOfStream) {
size_t length;
length = [self readIntoBuffer: buffer
length: pageSize];
|
︙ | | | ︙ | |
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
encoding: OF_STRING_ENCODING_UTF_8];
}
- (OFString *)readStringWithLength: (size_t)length
encoding: (of_string_encoding_t)encoding
{
OFString *ret;
char *buffer = of_malloc(length + 1, 1);
buffer[length] = 0;
@try {
[self readIntoBuffer: buffer
exactLength: length];
ret = [OFString stringWithCString: buffer
|
|
|
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
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
|
︙ | | | ︙ | |
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
return ret;
}
}
}
/* Read and see if we got a newline or \0 */
pageSize = [OFSystemInfo pageSize];
buffer = of_malloc(1, pageSize);
@try {
if ([self lowlevelIsAtEndOfStream]) {
size_t retLength;
if (_readBuffer == NULL) {
_waitingForDelimiter = false;
|
|
|
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
return ret;
}
}
}
/* Read and see if we got a newline or \0 */
pageSize = [OFSystemInfo pageSize];
buffer = of_alloc(1, pageSize);
@try {
if ([self lowlevelIsAtEndOfStream]) {
size_t retLength;
if (_readBuffer == NULL) {
_waitingForDelimiter = false;
|
︙ | | | ︙ | |
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
length: pageSize];
/* Look if there's a newline or \0 */
for (size_t i = 0; i < bufferLength; i++) {
if OF_UNLIKELY (buffer[i] == '\n' ||
buffer[i] == '\0') {
size_t retLength = _readBufferLength + i;
char *retCString = of_malloc(retLength, 1);
if (_readBuffer != NULL)
memcpy(retCString, _readBuffer,
_readBufferLength);
memcpy(retCString + _readBufferLength,
buffer, i);
|
|
|
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
length: pageSize];
/* Look if there's a newline or \0 */
for (size_t i = 0; i < bufferLength; i++) {
if OF_UNLIKELY (buffer[i] == '\n' ||
buffer[i] == '\0') {
size_t retLength = _readBufferLength + i;
char *retCString = of_alloc(retLength, 1);
if (_readBuffer != NULL)
memcpy(retCString, _readBuffer,
_readBufferLength);
memcpy(retCString + _readBufferLength,
buffer, i);
|
︙ | | | ︙ | |
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
|
length: retLength];
} @catch (id e) {
if (bufferLength > 0) {
/*
* Append data to _readBuffer
* to prevent loss of data.
*/
readBuffer = of_malloc(
_readBufferLength +
bufferLength, 1);
memcpy(readBuffer, _readBuffer,
_readBufferLength);
memcpy(readBuffer +
_readBufferLength,
|
|
|
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
|
length: retLength];
} @catch (id e) {
if (bufferLength > 0) {
/*
* Append data to _readBuffer
* to prevent loss of data.
*/
readBuffer = of_alloc(
_readBufferLength +
bufferLength, 1);
memcpy(readBuffer, _readBuffer,
_readBufferLength);
memcpy(readBuffer +
_readBufferLength,
|
︙ | | | ︙ | |
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
|
}
@throw e;
} @finally {
free(retCString);
}
readBuffer = of_malloc(bufferLength - i - 1, 1);
if (readBuffer != NULL)
memcpy(readBuffer, buffer + i + 1,
bufferLength - i - 1);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bufferLength - i - 1;
_waitingForDelimiter = false;
return ret;
}
}
/* There was no newline or \0 */
if (bufferLength > 0) {
readBuffer = of_malloc(_readBufferLength + bufferLength,
1);
memcpy(readBuffer, _readBuffer, _readBufferLength);
memcpy(readBuffer + _readBufferLength,
buffer, bufferLength);
free(_readBufferMemory);
|
|
|
|
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
|
}
@throw e;
} @finally {
free(retCString);
}
readBuffer = of_alloc(bufferLength - i - 1, 1);
if (readBuffer != NULL)
memcpy(readBuffer, buffer + i + 1,
bufferLength - i - 1);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bufferLength - i - 1;
_waitingForDelimiter = false;
return ret;
}
}
/* There was no newline or \0 */
if (bufferLength > 0) {
readBuffer = of_alloc(_readBufferLength + bufferLength,
1);
memcpy(readBuffer, _readBuffer, _readBufferLength);
memcpy(readBuffer + _readBufferLength,
buffer, bufferLength);
free(_readBufferMemory);
|
︙ | | | ︙ | |
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
|
return ret;
}
}
}
/* Read and see if we got a delimiter or \0 */
pageSize = [OFSystemInfo pageSize];
buffer = of_malloc(1, pageSize);
@try {
if ([self lowlevelIsAtEndOfStream]) {
if (_readBuffer == NULL) {
_waitingForDelimiter = false;
return nil;
}
|
|
|
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
|
return ret;
}
}
}
/* Read and see if we got a delimiter or \0 */
pageSize = [OFSystemInfo pageSize];
buffer = of_alloc(1, pageSize);
@try {
if ([self lowlevelIsAtEndOfStream]) {
if (_readBuffer == NULL) {
_waitingForDelimiter = false;
return nil;
}
|
︙ | | | ︙ | |
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
|
char *retCString;
if (buffer[i] == '\0')
delimiterLength = 1;
retLength = _readBufferLength + i + 1 -
delimiterLength;
retCString = of_malloc(retLength, 1);
if (_readBuffer != NULL &&
_readBufferLength <= retLength)
memcpy(retCString, _readBuffer,
_readBufferLength);
else if (_readBuffer != NULL)
memcpy(retCString, _readBuffer,
|
|
|
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
|
char *retCString;
if (buffer[i] == '\0')
delimiterLength = 1;
retLength = _readBufferLength + i + 1 -
delimiterLength;
retCString = of_alloc(retLength, 1);
if (_readBuffer != NULL &&
_readBufferLength <= retLength)
memcpy(retCString, _readBuffer,
_readBufferLength);
else if (_readBuffer != NULL)
memcpy(retCString, _readBuffer,
|
︙ | | | ︙ | |
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
|
length: retLength];
} @catch (id e) {
if (bufferLength > 0) {
/*
* Append data to _readBuffer
* to prevent loss of data.
*/
readBuffer = of_malloc(
_readBufferLength +
bufferLength, 1);
memcpy(readBuffer, _readBuffer,
_readBufferLength);
memcpy(readBuffer +
_readBufferLength,
|
|
|
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
|
length: retLength];
} @catch (id e) {
if (bufferLength > 0) {
/*
* Append data to _readBuffer
* to prevent loss of data.
*/
readBuffer = of_alloc(
_readBufferLength +
bufferLength, 1);
memcpy(readBuffer, _readBuffer,
_readBufferLength);
memcpy(readBuffer +
_readBufferLength,
|
︙ | | | ︙ | |
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
}
@throw e;
} @finally {
free(retCString);
}
readBuffer = of_malloc(bufferLength - i - 1, 1);
if (readBuffer != NULL)
memcpy(readBuffer, buffer + i + 1,
bufferLength - i - 1);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bufferLength - i - 1;
_waitingForDelimiter = false;
return ret;
}
}
/* Neither the delimiter nor \0 was found */
if (bufferLength > 0) {
readBuffer = of_malloc(_readBufferLength + bufferLength,
1);
memcpy(readBuffer, _readBuffer, _readBufferLength);
memcpy(readBuffer + _readBufferLength,
buffer, bufferLength);
free(_readBufferMemory);
|
|
|
|
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
}
@throw e;
} @finally {
free(retCString);
}
readBuffer = of_alloc(bufferLength - i - 1, 1);
if (readBuffer != NULL)
memcpy(readBuffer, buffer + i + 1,
bufferLength - i - 1);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength = bufferLength - i - 1;
_waitingForDelimiter = false;
return ret;
}
}
/* Neither the delimiter nor \0 was found */
if (bufferLength > 0) {
readBuffer = of_alloc(_readBufferLength + bufferLength,
1);
memcpy(readBuffer, _readBuffer, _readBufferLength);
memcpy(readBuffer + _readBufferLength,
buffer, bufferLength);
free(_readBufferMemory);
|
︙ | | | ︙ | |
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
|
size = count * sizeof(uint16_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp = of_malloc(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP16(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
|
size = count * sizeof(uint16_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp = of_alloc(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP16(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
|
size = count * sizeof(uint32_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp = of_malloc(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP32(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
|
size = count * sizeof(uint32_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp = of_alloc(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP32(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
|
size = count * sizeof(uint64_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp = of_malloc(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP64(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
|
size = count * sizeof(uint64_t);
#ifdef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp = of_alloc(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP64(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
|
size = count * sizeof(float);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
float *tmp = of_malloc(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_FLOAT(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
|
size = count * sizeof(float);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
float *tmp = of_alloc(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_FLOAT(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
|
size = count * sizeof(double);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
double *tmp = of_malloc(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
|
size = count * sizeof(double);
#ifdef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
double *tmp = of_alloc(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
|
size = count * sizeof(uint16_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp = of_malloc(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP16(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
|
size = count * sizeof(uint16_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint16_t *tmp = of_alloc(count, sizeof(uint16_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP16(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
|
size = count * sizeof(uint32_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp = of_malloc(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP32(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
|
size = count * sizeof(uint32_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint32_t *tmp = of_alloc(count, sizeof(uint32_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP32(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
size = count * sizeof(uint64_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp = of_malloc(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP64(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
size = count * sizeof(uint64_t);
#ifndef OF_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
uint64_t *tmp = of_alloc(count, sizeof(uint64_t));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP64(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
|
size = count * sizeof(float);
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
float *tmp = of_malloc(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_FLOAT(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
|
size = count * sizeof(float);
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
float *tmp = of_alloc(count, sizeof(float));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_FLOAT(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
|
size = count * sizeof(double);
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
double *tmp = of_malloc(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);
[self writeBuffer: tmp
length: size];
|
|
|
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
|
size = count * sizeof(double);
#ifndef OF_FLOAT_BIG_ENDIAN
[self writeBuffer: buffer
length: size];
#else
double *tmp = of_alloc(count, sizeof(double));
@try {
for (size_t i = 0; i < count; i++)
tmp[i] = OF_BSWAP_DOUBLE(buffer[i]);
[self writeBuffer: tmp
length: size];
|
︙ | | | ︙ | |
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
|
- (size_t)writeLine: (OFString *)string
encoding: (of_string_encoding_t)encoding
{
size_t stringLength = [string cStringLengthWithEncoding: encoding];
char *buffer;
buffer = of_malloc(stringLength + 1, 1);
@try {
memcpy(buffer, [string cStringWithEncoding: encoding],
stringLength);
buffer[stringLength] = '\n';
[self writeBuffer: buffer
|
|
|
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
|
- (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 {
memcpy(buffer, [string cStringWithEncoding: encoding],
stringLength);
buffer[stringLength] = '\n';
[self writeBuffer: buffer
|
︙ | | | ︙ | |
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
|
length: (size_t)length
{
char *readBuffer;
if (length > SIZE_MAX - _readBufferLength)
@throw [OFOutOfRangeException exception];
readBuffer = of_malloc(_readBufferLength + length, 1);
memcpy(readBuffer, buffer, length);
memcpy(readBuffer + length, _readBuffer, _readBufferLength);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength += length;
}
|
|
|
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
|
length: (size_t)length
{
char *readBuffer;
if (length > SIZE_MAX - _readBufferLength)
@throw [OFOutOfRangeException exception];
readBuffer = of_alloc(_readBufferLength + length, 1);
memcpy(readBuffer, buffer, length);
memcpy(readBuffer + length, _readBuffer, _readBufferLength);
free(_readBufferMemory);
_readBuffer = _readBufferMemory = readBuffer;
_readBufferLength += length;
}
|
︙ | | | ︙ | |
︙ | | | ︙ | |
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
/*
* We need one extra byte for the terminating zero if we want
* to use -[initWithUTF8StringNoCopy:length:freeWhenDone:].
*/
if (SIZE_MAX - (size_t)fileSize < 1)
@throw [OFOutOfRangeException exception];
tmp = of_malloc((size_t)fileSize + 1, 1);
@try {
file = [[OFFile alloc] initWithPath: path
mode: @"r"];
[file readIntoBuffer: tmp
exactLength: (size_t)fileSize];
} @catch (id e) {
|
|
|
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
/*
* We need one extra byte for the terminating zero if we want
* to use -[initWithUTF8StringNoCopy:length:freeWhenDone:].
*/
if (SIZE_MAX - (size_t)fileSize < 1)
@throw [OFOutOfRangeException exception];
tmp = of_alloc((size_t)fileSize + 1, 1);
@try {
file = [[OFFile alloc] initWithPath: path
mode: @"r"];
[file readIntoBuffer: tmp
exactLength: (size_t)fileSize];
} @catch (id e) {
|
︙ | | | ︙ | |
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
|
{
size_t length = self.length;
char *cString;
size_t cStringLength;
switch (encoding) {
case OF_STRING_ENCODING_UTF_8:
cString = of_malloc((length * 4) + 1, 1);
@try {
cStringLength = [self
of_getCString: cString
maxLength: (length * 4) + 1
encoding: OF_STRING_ENCODING_UTF_8
lossy: lossy];
|
|
|
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
|
{
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];
|
︙ | | | ︙ | |
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
|
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_malloc(length + 1, 1);
@try {
cStringLength = [self of_getCString: cString
maxLength: length + 1
encoding: encoding
lossy: lossy];
} @catch (id e) {
|
|
|
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
|
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];
} @catch (id e) {
|
︙ | | | ︙ | |
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
|
if (range.length > SIZE_MAX / sizeof(of_unichar_t))
@throw [OFOutOfRangeException exception];
pool = objc_autoreleasePoolPush();
searchCharacters = string.characters;
characters = of_malloc(range.length, sizeof(of_unichar_t));
@try {
[self getCharacters: characters
inRange: range];
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = range.length - searchLength;; i--) {
if (memcmp(characters + i, searchCharacters,
|
|
|
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
|
if (range.length > SIZE_MAX / sizeof(of_unichar_t))
@throw [OFOutOfRangeException exception];
pool = objc_autoreleasePoolPush();
searchCharacters = string.characters;
characters = of_alloc(range.length, sizeof(of_unichar_t));
@try {
[self getCharacters: characters
inRange: range];
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = range.length - searchLength;; i--) {
if (memcmp(characters + i, searchCharacters,
|
︙ | | | ︙ | |
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
|
if (range.length == 0)
return OF_NOT_FOUND;
if (range.length > SIZE_MAX / sizeof(of_unichar_t))
@throw [OFOutOfRangeException exception];
characters = of_malloc(range.length, sizeof(of_unichar_t));
@try {
[self getCharacters: characters
inRange: range];
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = range.length - 1;; i--) {
if (characterIsMember(characterSet,
|
|
|
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
|
if (range.length == 0)
return OF_NOT_FOUND;
if (range.length > SIZE_MAX / sizeof(of_unichar_t))
@throw [OFOutOfRangeException exception];
characters = of_alloc(range.length, sizeof(of_unichar_t));
@try {
[self getCharacters: characters
inRange: range];
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = range.length - 1;; i--) {
if (characterIsMember(characterSet,
|
︙ | | | ︙ | |
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
|
of_unichar_t *tmp;
size_t prefixLength;
bool hasPrefix;
if ((prefixLength = prefix.length) > self.length)
return false;
tmp = of_malloc(prefixLength, sizeof(of_unichar_t));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp
inRange: of_range(0, prefixLength)];
hasPrefix = (memcmp(tmp, prefix.characters,
|
|
|
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
|
of_unichar_t *tmp;
size_t prefixLength;
bool hasPrefix;
if ((prefixLength = prefix.length) > self.length)
return false;
tmp = of_alloc(prefixLength, sizeof(of_unichar_t));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp
inRange: of_range(0, prefixLength)];
hasPrefix = (memcmp(tmp, prefix.characters,
|
︙ | | | ︙ | |
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
|
bool hasSuffix;
if ((suffixLength = suffix.length) > self.length)
return false;
length = self.length;
tmp = of_malloc(suffixLength, sizeof(of_unichar_t));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp
inRange: of_range(length - suffixLength,
suffixLength)];
|
|
|
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
|
bool hasSuffix;
if ((suffixLength = suffix.length) > self.length)
return false;
length = self.length;
tmp = of_alloc(suffixLength, sizeof(of_unichar_t));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp
inRange: of_range(length - suffixLength,
suffixLength)];
|
︙ | | | ︙ | |
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
|
}
- (const of_unichar_t *)characters
{
size_t length = self.length;
of_unichar_t *buffer;
buffer = of_malloc(length, sizeof(of_unichar_t));
@try {
[self getCharacters: buffer
inRange: of_range(0, length)];
return [[OFData dataWithItemsNoCopy: buffer
count: length
itemSize: sizeof(of_unichar_t)
|
|
|
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
|
}
- (const of_unichar_t *)characters
{
size_t length = self.length;
of_unichar_t *buffer;
buffer = of_alloc(length, sizeof(of_unichar_t));
@try {
[self getCharacters: buffer
inRange: of_range(0, length)];
return [[OFData dataWithItemsNoCopy: buffer
count: length
itemSize: sizeof(of_unichar_t)
|
︙ | | | ︙ | |
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
|
const of_unichar_t *characters = self.characters;
size_t length = self.length;
of_char16_t *buffer;
size_t j;
bool swap = (byteOrder != OF_BYTE_ORDER_NATIVE);
/* Allocate memory for the worst case */
buffer = of_malloc((length + 1) * 2, sizeof(of_char16_t));
j = 0;
for (size_t i = 0; i < length; i++) {
of_unichar_t c = characters[i];
if (c > 0x10FFFF) {
free(buffer);
|
|
|
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
|
const of_unichar_t *characters = self.characters;
size_t length = self.length;
of_char16_t *buffer;
size_t j;
bool swap = (byteOrder != OF_BYTE_ORDER_NATIVE);
/* Allocate memory for the worst case */
buffer = of_alloc((length + 1) * 2, sizeof(of_char16_t));
j = 0;
for (size_t i = 0; i < length; i++) {
of_unichar_t c = characters[i];
if (c > 0x10FFFF) {
free(buffer);
|
︙ | | | ︙ | |
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
|
}
- (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
size_t length = self.length;
of_char32_t *buffer;
buffer = of_malloc(length + 1, sizeof(of_char32_t));
@try {
[self getCharacters: buffer
inRange: of_range(0, length)];
buffer[length] = 0;
if (byteOrder != OF_BYTE_ORDER_NATIVE)
for (size_t i = 0; i < length; i++)
|
|
|
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
|
}
- (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
size_t length = self.length;
of_char32_t *buffer;
buffer = of_alloc(length + 1, sizeof(of_char32_t));
@try {
[self getCharacters: buffer
inRange: of_range(0, length)];
buffer[length] = 0;
if (byteOrder != OF_BYTE_ORDER_NATIVE)
for (size_t i = 0; i < length; i++)
|
︙ | | | ︙ | |
︙ | | | ︙ | |
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
- (instancetype)init
{
self = [super init];
@try {
_s = &_storage;
_s->cString = of_calloc(1, 1);
_s->freeWhenDone = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
|
|
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
- (instancetype)init
{
self = [super init];
@try {
_s = &_storage;
_s->cString = of_alloc_zeroed(1, 1);
_s->freeWhenDone = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
|
︙ | | | ︙ | |
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
memcmp(cString, "\xEF\xBB\xBF", 3) == 0) {
cString += 3;
cStringLength -= 3;
}
_s = &_storage;
_s->cString = of_malloc(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)) {
|
|
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
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)) {
|
︙ | | | ︙ | |
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
482
483
|
[string isKindOfClass: [OFMutableUTF8String class]])
_s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8;
else
_s->isUTF8 = true;
_s->length = string.length;
_s->cString = of_malloc(_s->cStringLength + 1, 1);
memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1);
_s->freeWhenDone = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithCharacters: (const of_unichar_t *)characters
length: (size_t)length
{
self = [super init];
@try {
size_t j;
_s = &_storage;
_s->cString = of_malloc((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],
_s->cString + j);
|
|
|
|
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
482
483
|
[string isKindOfClass: [OFMutableUTF8String class]])
_s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8;
else
_s->isUTF8 = true;
_s->length = string.length;
_s->cString = of_alloc(_s->cStringLength + 1, 1);
memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1);
_s->freeWhenDone = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithCharacters: (const of_unichar_t *)characters
length: (size_t)length
{
self = [super init];
@try {
size_t j;
_s = &_storage;
_s->cString = of_alloc((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],
_s->cString + j);
|
︙ | | | ︙ | |
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
string++;
length--;
} else if (byteOrder != OF_BYTE_ORDER_NATIVE)
swap = true;
_s = &_storage;
_s->cString = of_malloc((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
of_unichar_t character =
(swap ? OF_BSWAP16(string[i]) : string[i]);
|
|
|
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
string++;
length--;
} else if (byteOrder != OF_BYTE_ORDER_NATIVE)
swap = true;
_s = &_storage;
_s->cString = of_alloc((length * 4) + 1, 1);
_s->length = length;
_s->freeWhenDone = true;
j = 0;
for (size_t i = 0; i < length; i++) {
of_unichar_t character =
(swap ? OF_BSWAP16(string[i]) : string[i]);
|
︙ | | | ︙ | |
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
characters++;
length--;
} else if (byteOrder != OF_BYTE_ORDER_NATIVE)
swap = true;
_s = &_storage;
_s->cString = of_malloc((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(
|
|
|
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
characters++;
length--;
} else if (byteOrder != OF_BYTE_ORDER_NATIVE)
swap = true;
_s = &_storage;
_s->cString = of_alloc((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(
|
︙ | | | ︙ | |
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
case 1:
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
_s->cString = of_malloc(cStringLength + 1, 1);
memcpy(_s->cString, tmp, cStringLength + 1);
_s->freeWhenDone = true;
} @finally {
free(tmp);
}
} @catch (id e) {
[self release];
|
|
|
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
case 1:
_s->isUTF8 = true;
break;
case -1:
@throw [OFInvalidEncodingException exception];
}
_s->cString = of_alloc(cStringLength + 1, 1);
memcpy(_s->cString, tmp, cStringLength + 1);
_s->freeWhenDone = true;
} @finally {
free(tmp);
}
} @catch (id e) {
[self release];
|
︙ | | | ︙ | |
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
|
objc_autoreleasePoolPop(pool);
return array;
}
- (const of_unichar_t *)characters
{
of_unichar_t *buffer = of_malloc(_s->length, sizeof(of_unichar_t));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
of_unichar_t c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
|
|
|
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
|
objc_autoreleasePoolPop(pool);
return array;
}
- (const of_unichar_t *)characters
{
of_unichar_t *buffer = of_alloc(_s->length, sizeof(of_unichar_t));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
of_unichar_t c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
|
︙ | | | ︙ | |
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
|
count: _s->length
itemSize: sizeof(of_unichar_t)
freeWhenDone: true] items];
}
- (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
of_char32_t *buffer = of_malloc(_s->length + 1, sizeof(of_char32_t));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
of_char32_t c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
|
|
|
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
|
count: _s->length
itemSize: sizeof(of_unichar_t)
freeWhenDone: true] items];
}
- (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
of_char32_t *buffer = of_alloc(_s->length + 1, sizeof(of_char32_t));
size_t i = 0, j = 0;
while (i < _s->cStringLength) {
of_char32_t c;
ssize_t cLen;
cLen = of_string_utf8_decode(_s->cString + i,
|
︙ | | | ︙ | |