ObjFW  Check-in [773997d072]

Overview
Comment:Add +[OFURL fileURLWithPath:isDirectory:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 773997d0720206b221fe52fb54db00724b317078b33541cb7faa02b2671394f3
User & Date: js on 2017-10-29 11:25:05
Other Links: manifest | tags
Context
2017-10-29
13:37
Add -[OFURL pathComponents] check-in: 7f64141183 user: js tags: trunk
11:25
Add +[OFURL fileURLWithPath:isDirectory:] check-in: 773997d072 user: js tags: trunk
02:26
Update buildsys check-in: 94175115c3 user: js tags: trunk
Changes

Modified src/OFURL.h from [cd4f15175b] to [76db36b252].

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
131
132


























133
134
135
136
137
138
139
 */
+ (instancetype)URLWithString: (OFString *)string
		relativeToURL: (OFURL *)URL;

#ifdef OF_HAVE_FILES
/*!
 * @brief Creates a new URL with the specified local file path.



 *
 * @param path The local file path
 * @return A new, autoreleased OFURL
 */
+ (instancetype)fileURLWithPath: (OFString *)path;
#endif












- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFURL with the specified string.
 *
 * @param string A string describing a URL
 * @return An initialized OFURL
 */
- (instancetype)initWithString: (OFString *)string;

/*!
 * @brief Initializes an already allocated OFURL with the specified string and
 *	  relative URL.
 *
 * @param string A string describing a URL
 * @param URL A URL to which the string is relative
 * @return An initialized OFURL
 */
- (instancetype)initWithString: (OFString *)string
		 relativeToURL: (OFURL *)URL;



























/*!
 * @brief Returns the URL as a string.
 *
 * @return The URL as a string
 */
- (OFString *)string;







>
>
>







>
>
>
>
>
>
>
>
>
>
>




















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







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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 */
+ (instancetype)URLWithString: (OFString *)string
		relativeToURL: (OFURL *)URL;

#ifdef OF_HAVE_FILES
/*!
 * @brief Creates a new URL with the specified local file path.
 *
 * If a directory exists at the specified path, a slash is appended if there is
 * no slash yet.
 *
 * @param path The local file path
 * @return A new, autoreleased OFURL
 */
+ (instancetype)fileURLWithPath: (OFString *)path;
#endif

/*!
 * @brief Creates a new URL with the specified local file path.
 *
 * @param path The local file path
 * @param isDirectory Whether the path is a directory, in which case a slash is
 *		      appened if there is no slash yet
 * @return An Initialized OFURL
 */
- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated OFURL with the specified string.
 *
 * @param string A string describing a URL
 * @return An initialized OFURL
 */
- (instancetype)initWithString: (OFString *)string;

/*!
 * @brief Initializes an already allocated OFURL with the specified string and
 *	  relative URL.
 *
 * @param string A string describing a URL
 * @param URL A URL to which the string is relative
 * @return An initialized OFURL
 */
- (instancetype)initWithString: (OFString *)string
		 relativeToURL: (OFURL *)URL;

#ifdef OF_HAVE_FILES
/*!
 * @brief Initializes an already allocated OFURL with the specified local file
 *	  path.
 *
 * If a directory exists at the specified path, a slash is appended if there is
 * no slash yet.
 *
 * @param path The local file path
 * @return An initialized OFURL
 */
- (instancetype)initFileURLWithPath: (OFString *)path;

/*!
 * @brief Initializes an already allocated OFURL with the specified local file
 *	  path.
 *
 * @param path The local file path
 * @param isDirectory Whether the path is a directory, in which case a slash is
 *		      appened if there is no slash yet
 * @return An Initialized OFURL
 */
+ (instancetype)fileURLWithPath: (OFString *)path
		    isDirectory: (bool)isDirectory;
#endif

/*!
 * @brief Returns the URL as a string.
 *
 * @return The URL as a string
 */
- (OFString *)string;

Modified src/OFURL.m from [7016e3a6f1] to [47b11362db].

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	return [[[self alloc] initWithString: string
			       relativeToURL: URL] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)fileURLWithPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFFileManager *fileManager = [OFFileManager defaultManager];
	OFURL *currentDirectoryURL, *URL;

	if (![path hasSuffix: OF_PATH_DELIMITER_STRING] &&
	    [fileManager directoryExistsAtPath: path])
		path = [path stringByAppendingString: @"/"];

# if OF_PATH_DELIMITER != '/'
	path = [[path pathComponents] componentsJoinedByString: @"/"];
# endif

	currentDirectoryURL =
	    [[OFFileManager defaultManager] currentDirectoryURL];
	URL = [[OFURL alloc] initWithString: path
			      relativeToURL: currentDirectoryURL];

	objc_autoreleasePoolPop(pool);

	return [URL autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}







|
<
<
|
<
<
<

<
<
<
|
|
<
<
<
|
<
|
|







50
51
52
53
54
55
56
57


58



59



60
61



62

63
64
65
66
67
68
69
70
71
	return [[[self alloc] initWithString: string
			       relativeToURL: URL] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)fileURLWithPath: (OFString *)path
{
	return [[[self alloc] initFileURLWithPath: path] autorelease];


}







+ (instancetype)fileURLWithPath: (OFString *)path
		    isDirectory: (bool)isDirectory



{

	return [[[self alloc] initFileURLWithPath: path
				      isDirectory: isDirectory] autorelease];
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}
278
279
280
281
282
283
284




















































285
286
287
288
289
290
291
		@throw e;
	} @finally {
		free(UTF8String2);
	}

	return self;
}





















































- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	@try {
		void *pool = objc_autoreleasePoolPush();

		if (![[element name] isEqual: [self className]] ||







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







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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
		@throw e;
	} @finally {
		free(UTF8String2);
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initFileURLWithPath: (OFString *)path
{
	@try {
		void *pool = objc_autoreleasePoolPush();
		OFFileManager *fileManager = [OFFileManager defaultManager];
		bool isDirectory;

		isDirectory = ([path hasSuffix: OF_PATH_DELIMITER_STRING] ||
		    [fileManager directoryExistsAtPath: path]);
		self = [self initFileURLWithPath: path
				     isDirectory: isDirectory];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{
	@try {
		void *pool = objc_autoreleasePoolPush();
		OFURL *currentDirectoryURL;

# if OF_PATH_DELIMITER != '/'
		path = [[path pathComponents] componentsJoinedByString: @"/"];
# endif

		if (isDirectory && ![path hasSuffix: OF_PATH_DELIMITER_STRING])
			path = [path stringByAppendingString: @"/"];

		currentDirectoryURL =
		    [[OFFileManager defaultManager] currentDirectoryURL];

		self = [self initWithString: path
			      relativeToURL: currentDirectoryURL];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	@try {
		void *pool = objc_autoreleasePoolPush();

		if (![[element name] isEqual: [self className]] ||

Modified tests/OFURLTests.m from [26f206153b] to [0dd131c155].

13
14
15
16
17
18
19



20
21
22
23
24
25
26
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFURL.h"



#import "OFNumber.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidFormatException.h"

#import "TestsAppDelegate.h"







>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFURL.h"
#ifdef OF_HAVE_FILES
# import "OFFileManager.h"
#endif
#import "OFNumber.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidFormatException.h"

#import "TestsAppDelegate.h"
49
50
51
52
53
54
55







56
57
58
59
60
61
62
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/quux"]]
	    string] isEqual: @"http://h/qux/foo/bar?q"] &&
	    [[[OFURL URLWithString: @"foo/bar"
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/?x"]]
	    string] isEqual: @"http://h/qux/foo/bar"] &&
	    [[[OFURL URLWithString: @"http://foo/?q"
		     relativeToURL: u1] string] isEqual: @"http://foo/?q"])








	TEST(@"-[string]",
	    [[u1 string] isEqual: url_str] &&
	    [[u2 string] isEqual: @"http://foo:80"] &&
	    [[u3 string] isEqual: @"http://bar/"] &&
	    [[u4 string] isEqual: @"file:///etc/passwd"])








>
>
>
>
>
>
>







52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/quux"]]
	    string] isEqual: @"http://h/qux/foo/bar?q"] &&
	    [[[OFURL URLWithString: @"foo/bar"
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/?x"]]
	    string] isEqual: @"http://h/qux/foo/bar"] &&
	    [[[OFURL URLWithString: @"http://foo/?q"
		     relativeToURL: u1] string] isEqual: @"http://foo/?q"])

#ifdef OF_HAVE_FILES
	TEST(@"+[fileURLWithPath:isDirectory:]",
	    [[[OFURL fileURLWithPath: @"testfile.txt"] fileSystemRepresentation]
	    isEqual: [[[OFFileManager defaultManager] currentDirectoryPath]
	    stringByAppendingPathComponent: @"testfile.txt"]])
#endif

	TEST(@"-[string]",
	    [[u1 string] isEqual: url_str] &&
	    [[u2 string] isEqual: @"http://foo:80"] &&
	    [[u3 string] isEqual: @"http://bar/"] &&
	    [[u4 string] isEqual: @"file:///etc/passwd"])