︙ | | | ︙ | |
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
|
- (OFRange)rangeOfString: (OFString *)string
{
[self finishInitialization];
return [self rangeOfString: string];
}
- (OFRange)rangeOfString: (OFString *)string options: (int)options
{
[self finishInitialization];
return [self rangeOfString: string options: options];
}
- (OFRange)rangeOfString: (OFString *)string
options: (int)options
range: (OFRange)range
{
[self finishInitialization];
return [self rangeOfString: string options: options range: range];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet options: options];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options
range: (OFRange)range
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet
options: options
range: range];
}
|
|
>
|
|
|
|
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
|
- (OFRange)rangeOfString: (OFString *)string
{
[self finishInitialization];
return [self rangeOfString: string];
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
{
[self finishInitialization];
return [self rangeOfString: string options: options];
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
range: (OFRange)range
{
[self finishInitialization];
return [self rangeOfString: string options: options range: range];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet options: options];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
range: (OFRange)range
{
[self finishInitialization];
return [self indexOfCharacterFromSet: characterSet
options: options
range: range];
}
|
︙ | | | ︙ | |
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
{
[self finishInitialization];
return [self componentsSeparatedByString: delimiter];
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (int)options
{
[self finishInitialization];
return [self componentsSeparatedByString: delimiter options: options];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
{
[self finishInitialization];
return [self componentsSeparatedByCharactersInSet: characterSet];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (int)options
{
[self finishInitialization];
return [self componentsSeparatedByCharactersInSet: characterSet
options: options];
}
- (OFArray *)pathComponents
|
|
|
|
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
{
[self finishInitialization];
return [self componentsSeparatedByString: delimiter];
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (OFStringSeparationOptions)options
{
[self finishInitialization];
return [self componentsSeparatedByString: delimiter options: options];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
{
[self finishInitialization];
return [self componentsSeparatedByCharactersInSet: characterSet];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (OFStringSeparationOptions)options
{
[self finishInitialization];
return [self componentsSeparatedByCharactersInSet: characterSet
options: options];
}
- (OFArray *)pathComponents
|
︙ | | | ︙ | |
︙ | | | ︙ | |
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
pos = [line rangeOfString: @"#"].location;
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OF_STRING_SKIP_EMPTY];
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
OFMakeRange(1, components.count - 1)];
|
|
|
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
pos = [line rangeOfString: @"#"].location;
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OFStringSkipEmptyComponents];
if (components.count < 2)
continue;
address = components.firstObject;
hosts = [components objectsInRange:
OFMakeRange(1, components.count - 1)];
|
︙ | | | ︙ | |
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
pos = [line indexOfCharacterFromSet: commentCharacters];
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OF_STRING_SKIP_EMPTY];
if (components.count < 2) {
objc_autoreleasePoolPop(pool2);
continue;
}
option = components.firstObject;
|
|
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
pos = [line indexOfCharacterFromSet: commentCharacters];
if (pos != OFNotFound)
line = [line substringToIndex: pos];
components = [line
componentsSeparatedByCharactersInSet: whitespaceCharacterSet
options: OFStringSkipEmptyComponents];
if (components.count < 2) {
objc_autoreleasePoolPop(pool2);
continue;
}
option = components.firstObject;
|
︙ | | | ︙ | |
︙ | | | ︙ | |
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
OFStringEncodingKOI8R,
/** KOI8-U */
OFStringEncodingKOI8U,
/** Try to automatically detect the encoding */
OFStringEncodingAutodetect = 0xFF
} OFStringEncoding;
enum {
OF_STRING_SEARCH_BACKWARDS = 1,
OF_STRING_SKIP_EMPTY = 2
};
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block for enumerating the lines of a string.
*
* @param line The current line
* @param stop A pointer to a variable that can be set to true to stop the
|
>
>
>
>
>
|
>
|
>
|
<
>
>
>
>
>
>
>
>
>
|
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
|
OFStringEncodingKOI8R,
/** KOI8-U */
OFStringEncodingKOI8U,
/** Try to automatically detect the encoding */
OFStringEncodingAutodetect = 0xFF
} OFStringEncoding;
/**
* @brief Options for searching in strings.
*
* This is a bit mask.
*/
typedef enum OFStringSearchOptions {
/** Search backwards in the string */
OFStringSearchBackwards = 1
} OFStringSearchOptions;
/**
* @brief Options for separating strings.
*
* This is a bit mask.
*/
typedef enum OFStringSeparationOptions {
/** Skip empty components */
OFStringSkipEmptyComponents = 1
} OFStringSeparationOptions;
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block for enumerating the lines of a string.
*
* @param line The current line
* @param stop A pointer to a variable that can be set to true to stop the
|
︙ | | | ︙ | |
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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
|
*/
- (OFRange)rangeOfString: (OFString *)string;
/**
* @brief Returns the range of the string.
*
* @param string The string to search
* @param options Options modifying search behavior.@n
* Possible values are:
* Value | Description
* -----------------------------|-------------------------------
* `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string
* @return The range of the first occurrence of the string or a range with
* `OFNotFound` as start position if it was not found
*/
- (OFRange)rangeOfString: (OFString *)string options: (int)options;
/**
* @brief Returns the range of the string in the specified range.
*
* @param string The string to search
* @param options Options modifying search behaviour.@n
* Possible values are:
* Value | Description
* -----------------------------|-------------------------------
* `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string
* @param range The range in which to search
* @return The range of the first occurrence of the string or a range with
* `OFNotFound` as start position if it was not found
*/
- (OFRange)rangeOfString: (OFString *)string
options: (int)options
range: (OFRange)range;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @param options Options modifying search behaviour.@n
* Possible values are:
* Value | Description
* -----------------------------|-------------------------------
* `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @param options Options modifying search behaviour.@n
* Possible values are:
* Value | Description
* -----------------------------|-------------------------------
* `OF_STRING_SEARCH_BACKWARDS` | Search backwards in the string
* @param range The range in which to search
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options
range: (OFRange)range;
/**
* @brief Returns whether the string contains the specified string.
*
* @param string The string to search
* @return Whether the string contains the specified string
|
|
<
<
<
<
|
>
|
<
<
<
<
|
|
<
<
<
<
|
|
<
<
<
<
|
|
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
|
*/
- (OFRange)rangeOfString: (OFString *)string;
/**
* @brief Returns the range of the string.
*
* @param string The string to search
* @param options Options modifying search behavior
* @return The range of the first occurrence of the string or a range with
* `OFNotFound` as start position if it was not found
*/
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options;
/**
* @brief Returns the range of the string in the specified range.
*
* @param string The string to search
* @param options Options modifying search behaviour
* @param range The range in which to search
* @return The range of the first occurrence of the string or a range with
* `OFNotFound` as start position if it was not found
*/
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
range: (OFRange)range;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @param options Options modifying search behaviour
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options;
/**
* @brief Returns the index of the first character from the set.
*
* @param characterSet The set of characters to search for
* @param options Options modifying search behaviour
* @param range The range in which to search
* @return The index of the first occurrence of a character from the set or
* `OFNotFound` if it was not found
*/
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
range: (OFRange)range;
/**
* @brief Returns whether the string contains the specified string.
*
* @param string The string to search
* @return Whether the string contains the specified string
|
︙ | | | ︙ | |
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
|
componentsSeparatedByString: (OFString *)delimiter;
/**
* @brief Separates the string into an array of strings, split by the specified
* delimiter.
*
* @param delimiter The delimiter for separating
* @param options Options according to which the string should be separated.@n
* Possible values are:
* Value | Description
* -----------------------|----------------------
* `OF_STRING_SKIP_EMPTY` | Skip empty components
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByString: (OFString *)delimiter
options: (int)options;
/**
* @brief Separates the string into an array of strings, split by characters in
* the specified set.
*
* @param characterSet The character set for separating
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet;
/**
* @brief Separates the string into an array of strings, split by characters in
* the specified set.
*
* @param characterSet The character set for separating
* @param options Options according to which the string should be separated.@n
* Possible values are:
* Value | Description
* -----------------------|----------------------
* `OF_STRING_SKIP_EMPTY` | Skip empty components
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (int)options;
/**
* @brief Returns the string in UTF-16 encoding with the specified byte order.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
|
|
<
<
<
<
|
|
<
<
<
<
|
|
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
|
componentsSeparatedByString: (OFString *)delimiter;
/**
* @brief Separates the string into an array of strings, split by the specified
* delimiter.
*
* @param delimiter The delimiter for separating
* @param options Options according to which the string should be separated
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByString: (OFString *)delimiter
options: (OFStringSeparationOptions)options;
/**
* @brief Separates the string into an array of strings, split by characters in
* the specified set.
*
* @param characterSet The character set for separating
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet;
/**
* @brief Separates the string into an array of strings, split by characters in
* the specified set.
*
* @param characterSet The character set for separating
* @param options Options according to which the string should be separated
* @return An autoreleased OFArray with the separated string
*/
- (OFArray OF_GENERIC(OFString *) *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (OFStringSeparationOptions)options;
/**
* @brief Returns the string in UTF-16 encoding with the specified byte order.
*
* The result is valid until the autorelease pool is released. If you want to
* use the result outside the scope of the current autorelease pool, you have to
* copy it.
|
︙ | | | ︙ | |
︙ | | | ︙ | |
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
|
- (OFRange)rangeOfString: (OFString *)string
{
return [self rangeOfString: string
options: 0
range: OFMakeRange(0, self.length)];
}
- (OFRange)rangeOfString: (OFString *)string options: (int)options
{
return [self rangeOfString: string
options: options
range: OFMakeRange(0, self.length)];
}
- (OFRange)rangeOfString: (OFString *)string
options: (int)options
range: (OFRange)range
{
void *pool;
const OFUnichar *searchCharacters;
OFUnichar *characters;
size_t searchLength;
|
|
>
|
|
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
|
- (OFRange)rangeOfString: (OFString *)string
{
return [self rangeOfString: string
options: 0
range: OFMakeRange(0, self.length)];
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
{
return [self rangeOfString: string
options: options
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;
|
︙ | | | ︙ | |
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
|
searchCharacters = string.characters;
characters = of_alloc(range.length, sizeof(OFUnichar));
@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,
searchLength * sizeof(OFUnichar)) == 0) {
objc_autoreleasePoolPop(pool);
return OFMakeRange(range.location + i,
searchLength);
}
|
|
|
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
|
searchCharacters = string.characters;
characters = of_alloc(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 OFMakeRange(range.location + i,
searchLength);
}
|
︙ | | | ︙ | |
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
1912
1913
1914
1915
|
{
return [self indexOfCharacterFromSet: characterSet
options: 0
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options
{
return [self indexOfCharacterFromSet: characterSet
options: options
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (int)options
range: (OFRange)range
{
bool (*characterIsMember)(id, SEL, OFUnichar) =
(bool (*)(id, SEL, OFUnichar))[characterSet
methodForSelector: @selector(characterIsMember:)];
OFUnichar *characters;
if (range.length == 0)
return OFNotFound;
if (range.length > SIZE_MAX / sizeof(OFUnichar))
@throw [OFOutOfRangeException exception];
characters = of_alloc(range.length, sizeof(OFUnichar));
@try {
[self getCharacters: characters inRange: range];
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = range.length - 1;; i--) {
if (characterIsMember(characterSet,
@selector(characterIsMember:),
characters[i]))
return range.location + i;
/* No match and we're at the last character */
|
|
|
|
|
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
1912
1913
1914
1915
1916
|
{
return [self indexOfCharacterFromSet: characterSet
options: 0
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
{
return [self indexOfCharacterFromSet: characterSet
options: options
range: OFMakeRange(0, self.length)];
}
- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
options: (OFStringSearchOptions)options
range: (OFRange)range
{
bool (*characterIsMember)(id, SEL, OFUnichar) =
(bool (*)(id, SEL, OFUnichar))[characterSet
methodForSelector: @selector(characterIsMember:)];
OFUnichar *characters;
if (range.length == 0)
return OFNotFound;
if (range.length > SIZE_MAX / sizeof(OFUnichar))
@throw [OFOutOfRangeException exception];
characters = of_alloc(range.length, sizeof(OFUnichar));
@try {
[self getCharacters: characters inRange: range];
if (options & OFStringSearchBackwards) {
for (size_t i = range.length - 1;; i--) {
if (characterIsMember(characterSet,
@selector(characterIsMember:),
characters[i]))
return range.location + i;
/* No match and we're at the last character */
|
︙ | | | ︙ | |
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
|
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
{
return [self componentsSeparatedByString: delimiter options: 0];
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (int)options
{
void *pool;
OFMutableArray *array;
const OFUnichar *characters, *delimiterCharacters;
bool skipEmpty = (options & OF_STRING_SKIP_EMPTY);
size_t length = self.length;
size_t delimiterLength = delimiter.length;
size_t last;
OFString *component;
if (delimiter == nil)
@throw [OFInvalidArgumentException exception];
|
|
|
|
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
|
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
{
return [self componentsSeparatedByString: delimiter options: 0];
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (OFStringSeparationOptions)options
{
void *pool;
OFMutableArray *array;
const OFUnichar *characters, *delimiterCharacters;
bool skipEmpty = (options & OFStringSkipEmptyComponents);
size_t length = self.length;
size_t delimiterLength = delimiter.length;
size_t last;
OFString *component;
if (delimiter == nil)
@throw [OFInvalidArgumentException exception];
|
︙ | | | ︙ | |
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
|
{
return [self componentsSeparatedByCharactersInSet: characterSet
options: 0];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (int)options
{
OFMutableArray *array = [OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
bool skipEmpty = (options & OF_STRING_SKIP_EMPTY);
const OFUnichar *characters = self.characters;
size_t length = self.length;
bool (*characterIsMember)(id, SEL, OFUnichar) =
(bool (*)(id, SEL, OFUnichar))[characterSet
methodForSelector: @selector(characterIsMember:)];
size_t last;
|
|
|
|
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
|
{
return [self componentsSeparatedByCharactersInSet: characterSet
options: 0];
}
- (OFArray *)
componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet
options: (OFStringSeparationOptions)options
{
OFMutableArray *array = [OFMutableArray array];
void *pool = objc_autoreleasePoolPush();
bool skipEmpty = (options & OFStringSkipEmptyComponents);
const OFUnichar *characters = self.characters;
size_t length = self.length;
bool (*characterIsMember)(id, SEL, OFUnichar) =
(bool (*)(id, SEL, OFUnichar))[characterSet
methodForSelector: @selector(characterIsMember:)];
size_t last;
|
︙ | | | ︙ | |
︙ | | | ︙ | |
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
|
memcpy(buffer, characters + range.location,
range.length * sizeof(OFUnichar));
objc_autoreleasePoolPop(pool);
}
- (OFRange)rangeOfString: (OFString *)string
options: (int)options
range: (OFRange)range
{
const char *cString = string.UTF8String;
size_t cStringLength = string.UTF8StringLength;
size_t rangeLocation, rangeLength;
if (range.length > SIZE_MAX - range.location ||
|
|
|
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
|
memcpy(buffer, characters + range.location,
range.length * sizeof(OFUnichar));
objc_autoreleasePoolPop(pool);
}
- (OFRange)rangeOfString: (OFString *)string
options: (OFStringSearchOptions)options
range: (OFRange)range
{
const char *cString = string.UTF8String;
size_t cStringLength = string.UTF8StringLength;
size_t rangeLocation, rangeLength;
if (range.length > SIZE_MAX - range.location ||
|
︙ | | | ︙ | |
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
|
if (cStringLength == 0)
return OFMakeRange(0, 0);
if (cStringLength > rangeLength)
return OFMakeRange(OFNotFound, 0);
if (options & OF_STRING_SEARCH_BACKWARDS) {
for (size_t i = rangeLength - cStringLength;; i--) {
if (memcmp(_s->cString + rangeLocation + i, cString,
cStringLength) == 0) {
range.location += of_string_utf8_get_index(
_s->cString + rangeLocation, i);
range.length = string.length;
|
|
|
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
|
if (cStringLength == 0)
return OFMakeRange(0, 0);
if (cStringLength > rangeLength)
return OFMakeRange(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(
_s->cString + rangeLocation, i);
range.length = string.length;
|
︙ | | | ︙ | |
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
|
return false;
return (memcmp(_s->cString + (_s->cStringLength - cStringLength),
suffix.UTF8String, cStringLength) == 0);
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (int)options
{
void *pool;
OFMutableArray *array;
const char *cString;
size_t cStringLength;
bool skipEmpty = (options & OF_STRING_SKIP_EMPTY);
size_t last;
OFString *component;
if (delimiter == nil)
@throw [OFInvalidArgumentException exception];
if (delimiter.length == 0)
|
|
|
|
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
|
return false;
return (memcmp(_s->cString + (_s->cStringLength - cStringLength),
suffix.UTF8String, cStringLength) == 0);
}
- (OFArray *)componentsSeparatedByString: (OFString *)delimiter
options: (OFStringSeparationOptions)options
{
void *pool;
OFMutableArray *array;
const char *cString;
size_t cStringLength;
bool skipEmpty = (options & OFStringSkipEmptyComponents);
size_t last;
OFString *component;
if (delimiter == nil)
@throw [OFInvalidArgumentException exception];
if (delimiter.length == 0)
|
︙ | | | ︙ | |
︙ | | | ︙ | |
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
|
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
︙ | | | ︙ | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
|
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
︙ | | | ︙ | |
︙ | | | ︙ | |
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
|
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
︙ | | | ︙ | |
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
|
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
︙ | | | ︙ | |
︙ | | | ︙ | |
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
|
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
︙ | | | ︙ | |
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: [components count] - 1
|
|
|
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: [components count] - 1
|
︙ | | | ︙ | |
︙ | | | ︙ | |
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
|
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
{
void *pool = objc_autoreleasePoolPush();
OFString *ret, *fileName;
size_t pos;
fileName = self.lastPathComponent;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return @"";
}
ret = [fileName substringFromIndex: pos + 1];
|
︙ | | | ︙ | |
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OF_STRING_SEARCH_BACKWARDS].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
|
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
return [[self copy] autorelease];
pool = objc_autoreleasePoolPush();
components = [[self.pathComponents mutableCopy] autorelease];
fileName = components.lastObject;
pos = [fileName rangeOfString: @"."
options: OFStringSearchBackwards].location;
if (pos == OFNotFound || pos == 0) {
objc_autoreleasePoolPop(pool);
return [[self copy] autorelease];
}
fileName = [fileName substringToIndex: pos];
[components replaceObjectAtIndex: components.count - 1
|
︙ | | | ︙ | |
︙ | | | ︙ | |
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
|
TEST(@"-[rangeOfString:]",
[C(@"𝄞öö") rangeOfString: @"öö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound &&
[C(@"𝄞öö") rangeOfString: @"öö"
options: OF_STRING_SEARCH_BACKWARDS].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"
options: OF_STRING_SEARCH_BACKWARDS].location == 2 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"
options: OF_STRING_SEARCH_BACKWARDS].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"
options: OF_STRING_SEARCH_BACKWARDS].location == OFNotFound)
EXPECT_EXCEPTION(
@"Detect out of range in -[rangeOfString:options:range:]",
OFOutOfRangeException,
[C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFMakeRange(3, 1)])
cs = [OFCharacterSet characterSetWithCharactersInString: @"cđ"];
TEST(@"-[indexOfCharacterFromSet:]",
[C(@"abcđabcđe") indexOfCharacterFromSet: cs] == 2 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: OF_STRING_SEARCH_BACKWARDS] == 7 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: 0
range: OFMakeRange(4, 4)] == 6 &&
[C(@"abcđabcđëf")
indexOfCharacterFromSet: cs
options: 0
|
|
|
|
|
|
|
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
|
TEST(@"-[rangeOfString:]",
[C(@"𝄞öö") rangeOfString: @"öö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound &&
[C(@"𝄞öö") rangeOfString: @"öö"
options: OFStringSearchBackwards].location == 1 &&
[C(@"𝄞öö") rangeOfString: @"ö"
options: OFStringSearchBackwards].location == 2 &&
[C(@"𝄞öö") rangeOfString: @"𝄞"
options: OFStringSearchBackwards].location == 0 &&
[C(@"𝄞öö") rangeOfString: @"x"
options: OFStringSearchBackwards].location == OFNotFound)
EXPECT_EXCEPTION(
@"Detect out of range in -[rangeOfString:options:range:]",
OFOutOfRangeException,
[C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFMakeRange(3, 1)])
cs = [OFCharacterSet characterSetWithCharactersInString: @"cđ"];
TEST(@"-[indexOfCharacterFromSet:]",
[C(@"abcđabcđe") indexOfCharacterFromSet: cs] == 2 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: OFStringSearchBackwards] == 7 &&
[C(@"abcđabcđë")
indexOfCharacterFromSet: cs
options: 0
range: OFMakeRange(4, 4)] == 6 &&
[C(@"abcđabcđëf")
indexOfCharacterFromSet: cs
options: 0
|
︙ | | | ︙ | |
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
[[a objectAtIndex: 0] isEqual: @"foo"] &&
a.count == 1)
i = 0;
TEST(@"-[componentsSeparatedByString:options:]",
(a = [C(@"fooXXbarXXXXbazXXXX")
componentsSeparatedByString: @"XX"
options: OF_STRING_SKIP_EMPTY]) &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"] &&
a.count == i)
cs = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"];
|
|
|
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
[[a objectAtIndex: 0] isEqual: @"foo"] &&
a.count == 1)
i = 0;
TEST(@"-[componentsSeparatedByString:options:]",
(a = [C(@"fooXXbarXXXXbazXXXX")
componentsSeparatedByString: @"XX"
options: OFStringSkipEmptyComponents]) &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"] &&
a.count == i)
cs = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"];
|
︙ | | | ︙ | |
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
[[a objectAtIndex: i++] isEqual: @"x"] &&
a.count == i)
i = 0;
TEST(@"-[componentsSeparatedByCharactersInSet:options:]",
(a = [C(@"fooXYbarXYZXbazXYXZ")
componentsSeparatedByCharactersInSet: cs
options: OF_STRING_SKIP_EMPTY]) &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"] &&
a.count == i)
#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS)
|
|
|
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
[[a objectAtIndex: i++] isEqual: @"x"] &&
a.count == i)
i = 0;
TEST(@"-[componentsSeparatedByCharactersInSet:options:]",
(a = [C(@"fooXYbarXYZXbazXYXZ")
componentsSeparatedByCharactersInSet: cs
options: OFStringSkipEmptyComponents]) &&
[[a objectAtIndex: i++] isEqual: @"foo"] &&
[[a objectAtIndex: i++] isEqual: @"bar"] &&
[[a objectAtIndex: i++] isEqual: @"baz"] &&
a.count == i)
#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS)
|
︙ | | | ︙ | |