1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
rangeLength = range.length;
}
if (cStringLength == 0)
return OFMakeRange(0, 0);
if (cStringLength > rangeLength)
return OFMakeRange(OF_NOT_FOUND, 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;
return range;
}
/* Did not match and we're at the last char */
if (i == 0)
return OFMakeRange(OF_NOT_FOUND, 0);
}
} else {
for (size_t i = 0; i <= rangeLength - cStringLength; i++) {
if (memcmp(_s->cString + rangeLocation + i, cString,
cStringLength) == 0) {
range.location += of_string_utf8_get_index(
_s->cString + rangeLocation, i);
range.length = string.length;
return range;
}
}
}
return OFMakeRange(OF_NOT_FOUND, 0);
}
- (bool)containsString: (OFString *)string
{
const char *cString = string.UTF8String;
size_t cStringLength = string.UTF8StringLength;
|
|
|
|
|
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
rangeLength = range.length;
}
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;
return range;
}
/* Did not match and we're at the last char */
if (i == 0)
return OFMakeRange(OFNotFound, 0);
}
} else {
for (size_t i = 0; i <= rangeLength - cStringLength; i++) {
if (memcmp(_s->cString + rangeLocation + i, cString,
cStringLength) == 0) {
range.location += of_string_utf8_get_index(
_s->cString + rangeLocation, i);
range.length = string.length;
return range;
}
}
}
return OFMakeRange(OFNotFound, 0);
}
- (bool)containsString: (OFString *)string
{
const char *cString = string.UTF8String;
size_t cStringLength = string.UTF8StringLength;
|