︙ | | |
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
|
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
|
-
-
+
+
+
-
|
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFLocale.h"
#import "OFStream.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURLHandler.h"
#import "OFURI.h"
#import "OFURIHandler.h"
#import "OFUTF8String.h"
#import "OFUTF8String+Private.h"
#import "OFXMLElement.h"
#import "OFGetItemAttributesFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFRetrieveItemAttributesFailedException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
#import "unicode.h"
/*
* It seems strtod is buggy on Win32.
|
︙ | | |
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
+
-
|
_references_to_categories_of_OFString(void)
{
_OFString_CryptographicHashing_reference = 1;
_OFString_JSONParsing_reference = 1;
#ifdef OF_HAVE_FILES
_OFString_PathAdditions_reference = 1;
#endif
_OFString_PercentEncoding_reference = 1;
_OFString_PropertyListParsing_reference = 1;
_OFString_Serialization_reference = 1;
_OFString_URLEncoding_reference = 1;
_OFString_XMLEscaping_reference = 1;
_OFString_XMLUnescaping_reference = 1;
}
void
_reference_to_OFConstantString(void)
{
|
︙ | | |
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
-
+
-
+
-
+
-
+
|
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL];
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI
encoding: encoding];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
return (id)[[OFUTF8String alloc] initWithSerialization: element];
}
|
︙ | | |
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
|
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
|
-
+
-
+
-
+
-
+
|
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
{
return [[[self alloc] initWithContentsOfURL: URL] autorelease];
return [[[self alloc] initWithContentsOfURI: URI] autorelease];
}
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfURL: URL
return [[[self alloc] initWithContentsOfURI: URI
encoding: encoding] autorelease];
}
- (instancetype)init
{
if ([self isMemberOfClass: [OFString class]]) {
@try {
|
︙ | | |
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
|
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
|
-
+
|
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *file = nil;
@try {
fileSize = [[OFFileManager defaultManager]
attributesOfItemAtPath: path].fileSize;
} @catch (OFRetrieveItemAttributesFailedException *e) {
} @catch (OFGetItemAttributesFailedException *e) {
@throw [OFOpenItemFailedException
exceptionWithPath: path
mode: @"r"
errNo: e.errNo];
}
objc_autoreleasePoolPop(pool);
|
︙ | | |
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
1090
1091
1092
1093
|
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
1090
1091
1092
1093
1094
1095
1096
1097
|
-
+
-
+
-
+
-
+
+
+
+
+
|
}
}
return self;
}
#endif
- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
return [self initWithContentsOfURL: URL
return [self initWithContentsOfURI: URI
encoding: OFStringEncodingAutodetect];
}
- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
data = [OFData dataWithContentsOfURL: URL];
data = [OFData dataWithContentsOfURI: URI];
} @catch (id e) {
[self release];
@throw e;
}
/* FIXME: Detect encoding where we can. */
if (encoding == OFStringEncodingAutodetect)
encoding = OFStringEncodingUTF8;
self = [self initWithCString: data.items
encoding: encoding
length: data.count * data.itemSize];
objc_autoreleasePoolPop(pool);
|
︙ | | |
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
|
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
|
-
+
-
|
@throw [OFInvalidEncodingException exception];
cString[length] = '\0';
return length;
#endif
default:
@throw [OFNotImplementedException exceptionWithSelector: _cmd
@throw [OFInvalidArgumentException exception];
object: self];
}
}
- (size_t)getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
{
|
︙ | | |
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
|
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
|
-
+
|
} @catch (id e) {
OFFreeMemory(cString);
@throw e;
}
break;
default:
@throw [OFInvalidEncodingException exception];
@throw [OFInvalidArgumentException exception];
}
@try {
ret = [[OFData dataWithItemsNoCopy: cString
count: cStringLength + 1
freeWhenDone: true] items];
} @catch (id e) {
|
︙ | | |
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
|
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
|
-
+
|
case OFStringEncodingCodepage850:
case OFStringEncodingCodepage858:
case OFStringEncodingMacRoman:
case OFStringEncodingKOI8R:
case OFStringEncodingKOI8U:
return self.length;
default:
@throw [OFInvalidEncodingException exception];
@throw [OFInvalidArgumentException exception];
}
}
- (size_t)UTF8StringLength
{
return [self cStringLengthWithEncoding: OFStringEncodingUTF8];
}
|
︙ | | |
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
|
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
|
-
-
-
+
+
+
|
unsigned long hash;
OFHashInit(&hash);
for (size_t i = 0; i < length; i++) {
const OFUnichar c = characters[i];
OFHashAdd(&hash, (c & 0xFF0000) >> 16);
OFHashAdd(&hash, (c & 0x00FF00) >> 8);
OFHashAdd(&hash, c & 0x0000FF);
OFHashAddByte(&hash, (c & 0xFF0000) >> 16);
OFHashAddByte(&hash, (c & 0x00FF00) >> 8);
OFHashAddByte(&hash, c & 0x0000FF);
}
OFHashFinalize(&hash);
return hash;
}
|
︙ | | |
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
|
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
|
-
+
-
+
-
+
|
if (options & OFJSONRepresentationOptionIsIdentifier) {
const char *cString = self.UTF8String;
if ((!OFASCIIIsAlpha(cString[0]) &&
cString[0] != '_' && cString[0] != '$') ||
strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) {
[JSON prependString: @"\""];
[JSON insertString: @"\"" atIndex: 0];
[JSON appendString: @"\""];
}
} else {
[JSON prependString: @"\""];
[JSON insertString: @"\"" atIndex: 0];
[JSON appendString: @"\""];
}
} else {
[JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"];
[JSON prependString: @"\""];
[JSON insertString: @"\"" atIndex: 0];
[JSON appendString: @"\""];
}
[JSON makeImmutable];
return JSON;
}
|
︙ | | |
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
|
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
return data;
}
- (OFRange)rangeOfString: (OFString *)string
{
return [self rangeOfString: string
options: 0
range: OFRangeMake(0, self.length)];
range: OFMakeRange(0, self.length)];
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
{
return [self rangeOfString: string
options: options
range: OFRangeMake(0, self.length)];
range: OFMakeRange(0, self.length)];
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
range: (OFRange)range
{
void *pool;
const OFUnichar *searchCharacters;
OFUnichar *characters;
size_t searchLength;
if ((searchLength = string.length) == 0)
return OFRangeMake(0, 0);
return OFMakeRange(0, 0);
if (searchLength > range.length)
return OFRangeMake(OFNotFound, 0);
return OFMakeRange(OFNotFound, 0);
if (range.length > SIZE_MAX / sizeof(OFUnichar))
@throw [OFOutOfRangeException exception];
pool = objc_autoreleasePoolPush();
searchCharacters = string.characters;
characters = OFAllocMemory(range.length, sizeof(OFUnichar));
@try {
[self getCharacters: characters inRange: range];
if (options & OFStringSearchBackwards) {
for (size_t i = range.length - searchLength;; i--) {
if (memcmp(characters + i, searchCharacters,
searchLength * sizeof(OFUnichar)) == 0) {
objc_autoreleasePoolPop(pool);
return OFRangeMake(range.location + i,
return OFMakeRange(range.location + i,
searchLength);
}
/* No match and we're at the last character */
if (i == 0)
break;
}
} else {
for (size_t i = 0;
i <= range.length - searchLength; i++) {
if (memcmp(characters + i, searchCharacters,
searchLength * sizeof(OFUnichar)) == 0) {
objc_autoreleasePoolPop(pool);
return OFRangeMake(range.location + i,
return OFMakeRange(range.location + i,
searchLength);
}
}
}
} @finally {
OFFreeMemory(characters);
}
objc_autoreleasePoolPop(pool);
return OFRangeMake(OFNotFound, 0);
return OFMakeRange(OFNotFound, 0);
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
{
return [self indexOfCharacterFromSet: characterSet
options: 0
range: OFRangeMake(0, self.length)];
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
{
return [self indexOfCharacterFromSet: characterSet
options: options
range: OFRangeMake(0, self.length)];
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
range: (OFRange)range
{
bool (*characterIsMember)(id, SEL, OFUnichar) =
|
︙ | | |
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
|
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
|
-
+
-
+
|
objc_autoreleasePoolPop(pool);
return false;
}
- (OFString *)substringFromIndex: (size_t)idx
{
return [self substringWithRange: OFRangeMake(idx, self.length - idx)];
return [self substringWithRange: OFMakeRange(idx, self.length - idx)];
}
- (OFString *)substringToIndex: (size_t)idx
{
return [self substringWithRange: OFRangeMake(0, idx)];
return [self substringWithRange: OFMakeRange(0, idx)];
}
- (OFString *)substringWithRange: (OFRange)range
{
void *pool;
OFString *ret;
|
︙ | | |
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
|
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
|
-
-
-
-
-
-
-
-
|
{
OFMutableString *new = [OFMutableString stringWithString: self];
[new appendFormat: format arguments: arguments];
[new makeImmutable];
return new;
}
- (OFString *)stringByPrependingString: (OFString *)string
{
OFMutableString *new = [[string mutableCopy] autorelease];
[new appendString: self];
[new makeImmutable];
return new;
}
- (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string
withString: (OFString *)replacement
{
OFMutableString *new = [[self mutableCopy] autorelease];
[new replaceOccurrencesOfString: string withString: replacement];
[new makeImmutable];
return new;
|
︙ | | |
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
|
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
|
-
+
|
if ((prefixLength = prefix.length) > self.length)
return false;
tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp inRange: OFRangeMake(0, prefixLength)];
[self getCharacters: tmp inRange: OFMakeRange(0, prefixLength)];
hasPrefix = (memcmp(tmp, prefix.characters,
prefixLength * sizeof(OFUnichar)) == 0);
objc_autoreleasePoolPop(pool);
} @finally {
OFFreeMemory(tmp);
|
︙ | | |
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
|
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
|
-
+
|
length = self.length;
tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar));
@try {
void *pool = objc_autoreleasePoolPush();
[self getCharacters: tmp
inRange: OFRangeMake(length - suffixLength,
inRange: OFMakeRange(length - suffixLength,
suffixLength)];
suffixCharacters = suffix.characters;
hasSuffix = (memcmp(tmp, suffixCharacters,
suffixLength * sizeof(OFUnichar)) == 0);
objc_autoreleasePoolPop(pool);
|
︙ | | |
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
|
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
|
-
+
-
+
|
last = 0;
for (size_t i = 0; i <= length - delimiterLength; i++) {
if (memcmp(characters + i, delimiterCharacters,
delimiterLength * sizeof(OFUnichar)) != 0)
continue;
component = [self substringWithRange:
OFRangeMake(last, i - last)];
OFMakeRange(last, i - last)];
if (!skipEmpty || component.length > 0)
[array addObject: component];
i += delimiterLength - 1;
last = i + 1;
}
component = [self substringWithRange: OFRangeMake(last, length - last)];
component = [self substringWithRange: OFMakeRange(last, length - last)];
if (!skipEmpty || component.length > 0)
[array addObject: component];
[array makeImmutable];
objc_autoreleasePoolPop(pool);
|
︙ | | |
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
|
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
|
-
+
-
+
-
+
|
last = 0;
for (size_t i = 0; i < length; i++) {
if (characterIsMember(characterSet,
@selector(characterIsMember:), characters[i])) {
if (!skipEmpty || i != last) {
OFString *component = [self substringWithRange:
OFRangeMake(last, i - last)];
OFMakeRange(last, i - last)];
[array addObject: component];
}
last = i + 1;
}
}
if (!skipEmpty || length != last) {
OFString *component = [self substringWithRange:
OFRangeMake(last, length - last)];
OFMakeRange(last, length - last)];
[array addObject: component];
}
[array makeImmutable];
objc_autoreleasePoolPop(pool);
return array;
}
- (long long)longLongValue
{
return [self longLongValueWithBase: 10];
}
- (long long)longLongValueWithBase: (int)base
- (long long)longLongValueWithBase: (unsigned char)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
bool negative = false;
long long value = 0;
while (OFASCIIIsSpace(*UTF8String))
|
︙ | | |
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
|
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
|
-
+
|
}
- (unsigned long long)unsignedLongLongValue
{
return [self unsignedLongLongValueWithBase: 10];
}
- (unsigned long long)unsignedLongLongValueWithBase: (int)base
- (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = self.UTF8String;
unsigned long long value = 0;
while (OFASCIIIsSpace(*UTF8String))
UTF8String++;
|
︙ | | |
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
|
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
|
-
+
-
+
|
#ifdef HAVE_STRTOF_L
const char *UTF8String = self.UTF8String;
#else
/*
* If we have no strtof_l, we have no other choice but to replace "."
* with the locale's decimal point.
*/
OFString *decimalPoint = [OFLocale decimalPoint];
OFString *decimalSeparator = [OFLocale decimalSeparator];
const char *UTF8String = [self
stringByReplacingOccurrencesOfString: @"."
withString: decimalPoint].UTF8String;
withString: decimalSeparator].UTF8String;
#endif
char *endPtr = NULL;
float value;
errno = 0;
#ifdef HAVE_STRTOF_L
value = strtof_l(UTF8String, &endPtr, cLocale);
|
︙ | | |
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
|
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
|
-
+
-
+
|
#ifdef HAVE_STRTOD_L
const char *UTF8String = self.UTF8String;
#else
/*
* If we have no strtod_l, we have no other choice but to replace "."
* with the locale's decimal point.
*/
OFString *decimalPoint = [OFLocale decimalPoint];
OFString *decimalSeparator = [OFLocale decimalSeparator];
const char *UTF8String = [self
stringByReplacingOccurrencesOfString: @"."
withString: decimalPoint].UTF8String;
withString: decimalSeparator].UTF8String;
#endif
char *endPtr = NULL;
double value;
errno = 0;
#ifdef HAVE_STRTOD_L
value = strtod_l(UTF8String, &endPtr, cLocale);
|
︙ | | |
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
|
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
|
-
+
|
{
size_t length = self.length;
OFUnichar *buffer;
const OFUnichar *ret;
buffer = OFAllocMemory(length, sizeof(OFUnichar));
@try {
[self getCharacters: buffer inRange: OFRangeMake(0, length)];
[self getCharacters: buffer inRange: OFMakeRange(0, length)];
ret = [[OFData dataWithItemsNoCopy: buffer
count: length
itemSize: sizeof(OFUnichar)
freeWhenDone: true] items];
} @catch (id e) {
OFFreeMemory(buffer);
|
︙ | | |
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
|
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
|
-
+
|
{
size_t length = self.length;
OFChar32 *buffer;
const OFChar32 *ret;
buffer = OFAllocMemory(length + 1, sizeof(OFChar32));
@try {
[self getCharacters: buffer inRange: OFRangeMake(0, length)];
[self getCharacters: buffer inRange: OFMakeRange(0, length)];
buffer[length] = 0;
if (byteOrder != OFByteOrderNative)
for (size_t i = 0; i < length; i++)
buffer[i] = OFByteSwap32(buffer[i]);
ret = [[OFData dataWithItemsNoCopy: buffer
|
︙ | | |
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
|
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
|
-
+
-
+
-
+
-
-
-
-
-
+
|
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToURL: (OFURL *)URL
- (void)writeToURI: (OFURI *)URI
{
[self writeToURL: URL encoding: OFStringEncodingUTF8];
[self writeToURI: URI encoding: OFStringEncodingUTF8];
}
- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFURLHandler *URLHandler;
OFStream *stream;
if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
stream = [URLHandler openItemAtURL: URL mode: @"w"];
stream = [OFURIHandler openItemAtURI: URI mode: @"w"];
[stream writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
|
︙ | | |
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
|
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
|
-
+
-
+
|
continue;
}
if (characters[i] == '\n' || characters[i] == '\r') {
void *pool2 = objc_autoreleasePoolPush();
block([self substringWithRange:
OFRangeMake(last, i - last)], &stop);
OFMakeRange(last, i - last)], &stop);
last = i + 1;
objc_autoreleasePoolPop(pool2);
}
lastCarriageReturn = (characters[i] == '\r');
}
if (!stop)
block([self substringWithRange: OFRangeMake(last, i - last)],
block([self substringWithRange: OFMakeRange(last, i - last)],
&stop);
objc_autoreleasePoolPop(pool);
}
#endif
@end
|