ObjFW  Check-in [c6299422a1]

Overview
Comment:Add -[OFString isAbsolutePath]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c6299422a17fc50a0f71d3806d58971d75e9bb68c33c7fe7750c0903d9c587bc
User & Date: js on 2018-03-11 21:43:54
Other Links: manifest | tags
Context
2018-03-11
21:59
Clean up -[OFURL initFileURLWithPath:isDirectory:] check-in: 88d0ccf804 user: js tags: trunk
21:43
Add -[OFString isAbsolutePath] check-in: c6299422a1 user: js tags: trunk
20:47
ofhttp: Allow insecure redirects with --insecure check-in: 38ccb06dff user: js tags: trunk
Changes

Modified src/OFString+PathAdditions.h from [9ffc17fae1] to [4fb51bf901].

24
25
26
27
28
29
30





31
32
33
34
35
36
37
#endif
extern int _OFString_PathAdditions_reference;
#ifdef __cplusplus
}
#endif

@interface OFString (PathAdditions)





/*!
 * @brief The components of the string when interpreted as a path.
 */
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents;

/*!
 * @brief The last path component of the string when interpreted as a path.







>
>
>
>
>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#endif
extern int _OFString_PathAdditions_reference;
#ifdef __cplusplus
}
#endif

@interface OFString (PathAdditions)
/*!
 * @brief Whether the path is an absolute path.
 */
@property (readonly, nonatomic, getter=isAbsolutePath) bool absolutePath;

/*!
 * @brief The components of the string when interpreted as a path.
 */
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents;

/*!
 * @brief The last path component of the string when interpreted as a path.

Modified src/OFString+PathAdditions_DOS.m from [1563d49b31] to [466313d925].

25
26
27
28
29
30
31













32
33
34
35
36
37
38
int _OFString_PathAdditions_reference;

@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
	return [components componentsJoinedByString: @"\\"];
}














- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = [self UTF8String];
	size_t i, last = 0, pathCStringLength = [self UTF8StringLength];







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







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
int _OFString_PathAdditions_reference;

@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
	return [components componentsJoinedByString: @"\\"];
}

- (bool)isAbsolutePath
{
	void *pool = objc_autoreleasePoolPush();
	const char *UTF8String = [self UTF8String];
	size_t UTF8StringLength = [self UTF8StringLength];
	bool ret = (UTF8StringLength >= 3 && UTF8String[1] == ':' &&
	    (UTF8String[2] == '\\' || UTF8String[2] == '/'));

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = [self UTF8String];
	size_t i, last = 0, pathCStringLength = [self UTF8StringLength];

Modified src/OFString+PathAdditions_UNIX.m from [12cda0c8c7] to [223d3e3c81].

25
26
27
28
29
30
31





32
33
34
35
36
37
38
int _OFString_PathAdditions_reference;

@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
	return [components componentsJoinedByString: @"/"];
}






- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = [self UTF8String];
	size_t i, last = 0, pathCStringLength = [self UTF8StringLength];







>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
int _OFString_PathAdditions_reference;

@implementation OFString (PathAdditions)
+ (OFString *)pathWithComponents: (OFArray *)components
{
	return [components componentsJoinedByString: @"/"];
}

- (bool)isAbsolutePath
{
	return [self hasPrefix: @"/"];
}

- (OFArray *)pathComponents
{
	OFMutableArray OF_GENERIC(OFString *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	const char *cString = [self UTF8String];
	size_t i, last = 0, pathCStringLength = [self UTF8StringLength];

Modified tests/OFStringTests.m from [bb51e4a860] to [067d094bf5].

548
549
550
551
552
553
554










555
556
557
558
559
560
561
	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#ifdef OF_HAVE_FILES










	s[0] = [mutableStringClass stringWithString: @"foo"];
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	[s[0] appendString: @"\\"];
# else
	[s[0] appendString: @"/"];
# endif
	[s[0] appendString: @"bar"];







>
>
>
>
>
>
>
>
>
>







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#ifdef OF_HAVE_FILES
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	TEST(@"-[isAbsolutePath]",
	    [C(@"C:\\foo") isAbsolutePath] && [C(@"a:/foo") isAbsolutePath] &&
	    ![C(@"foo") isAbsolutePath] && ![C(@"b:foo") isAbsolutePath])
# else
	TEST(@"-[isAbsolutePath]",
	    [C(@"/foo") isAbsolutePath] && [C(@"/foo/bar") isAbsolutePath] &&
	    ![C(@"foo/bar") isAbsolutePath] && ![C(@"foo") isAbsolutePath])
# endif

	s[0] = [mutableStringClass stringWithString: @"foo"];
# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	[s[0] appendString: @"\\"];
# else
	[s[0] appendString: @"/"];
# endif
	[s[0] appendString: @"bar"];