ObjFW  Check-in [a6c5af136b]

Overview
Comment:Add -[containsString:] to OFString.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a6c5af136b871e608279dc2493f89e54217a23f7f18430d55476050200dc9567
User & Date: js on 2011-02-09 09:37:54
Other Links: manifest | tags
Context
2011-02-09
12:33
Add support for relative URLs to OFURL. check-in: ddd3a6683f user: js tags: trunk
09:37
Add -[containsString:] to OFString. check-in: a6c5af136b user: js tags: trunk
09:19
Check for NSObject.h instead of Foundation.h. Really speeds things up. check-in: 550c482466 user: js tags: trunk
Changes

Modified src/OFString.h from [6f22d22dfa] to [6e3ed07eb5].

303
304
305
306
307
308
309






310
311
312
313
314
315
316
/**
 * \param str The string to search
 * \return The index of the last occurrence of the string or SIZE_MAX if it
 *	   was not found
 */
- (size_t)indexOfLastOccurrenceOfString: (OFString*)str;







/**
 * \param start The index where the substring starts
 * \param end The index where the substring ends.
 *	      This points BEHIND the last character!
 * \return The substring as a new autoreleased OFString
 */
- (OFString*)substringFromIndex: (size_t)start







>
>
>
>
>
>







303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
 * \param str The string to search
 * \return The index of the last occurrence of the string or SIZE_MAX if it
 *	   was not found
 */
- (size_t)indexOfLastOccurrenceOfString: (OFString*)str;

/**
 * \param str The string to search
 * \return Whether the string contains the specified string
 */
- (BOOL)containsString: (OFString*)str;

/**
 * \param start The index where the substring starts
 * \param end The index where the substring ends.
 *	      This points BEHIND the last character!
 * \return The substring as a new autoreleased OFString
 */
- (OFString*)substringFromIndex: (size_t)start

Modified src/OFString.m from [877ceb4ed7] to [da97386e32].

886
887
888
889
890
891
892



















893
894
895
896
897
898
899
			return of_string_position_to_index(string, i);

		/* Did not match and we're at the last char */
		if (i == 0)
			return SIZE_MAX;
	}
}




















- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{
	if ([self isUTF8]) {
		start = of_string_index_to_position(string, start, length);
		end = of_string_index_to_position(string, end, length);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
			return of_string_position_to_index(string, i);

		/* Did not match and we're at the last char */
		if (i == 0)
			return SIZE_MAX;
	}
}

- (BOOL)containsString: (OFString*)str
{
	const char *str_c = [str cString];
	size_t str_len = [str cStringLength];
	size_t i;

	if (str_len == 0)
		return YES;

	if (str_len > length)
		return NO;

	for (i = 0; i <= length - str_len; i++)
		if (!memcmp(string + i, str_c, str_len))
			return YES;

	return NO;
}

- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{
	if ([self isUTF8]) {
		start = of_string_index_to_position(string, start, length);
		end = of_string_index_to_position(string, end, length);