ObjFW  Check-in [b98fd10000]

Overview
Comment:Add -[OFString stringByStandardizing(URL)Path].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b98fd100005be8face234195f4bfe80ff01635ec60f490feec020fef4e70f614
User & Date: js on 2012-12-26 19:55:26
Other Links: manifest | tags
Context
2012-12-26
20:55
OFHTTPRequestResult -> OFHTTPRequestReply. check-in: 75f187cef5 user: js tags: trunk
19:55
Add -[OFString stringByStandardizing(URL)Path]. check-in: b98fd10000 user: js tags: trunk
19:07
OFHTTPServer: Correctly put the query in the URL. check-in: f8a7660ac7 user: js tags: trunk
Changes

Modified src/OFString.h from [4d4538878f] to [b8302b7457].

843
844
845
846
847
848
849

















850
851
852
853
854
855
856
/*!
 * @brief Returns the directory name of the path.
 *
 * @return The directory name of the path
 */
- (OFString*)stringByDeletingLastPathComponent;


















/*!
 * @brief Returns the decimal value of the string as an intmax_t.
 *
 * Leading and trailing whitespaces are ignored.
 *
 * If the string contains any non-number characters, an
 * OFInvalidEncodingException is thrown.







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







843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
/*!
 * @brief Returns the directory name of the path.
 *
 * @return The directory name of the path
 */
- (OFString*)stringByDeletingLastPathComponent;

/*!
 * @brief Returns the path with relative sub paths resolved.
 *
 * @return The path with relative sub paths resolved
 */
- (OFString*)stringByStandardizingPath;

/*!
 * @brief Returns the URL path with relative sub paths resolved.
 *
 * This works similar to @ref stringByStandardizingPath, but is intended for
 * standardization of paths that are part of a URL.
 *
 * @return The URL path with relative sub paths resolved
 */
- (OFString*)stringByStandardizingURLPath;

/*!
 * @brief Returns the decimal value of the string as an intmax_t.
 *
 * Leading and trailing whitespaces are ignored.
 *
 * If the string contains any non-number characters, an
 * OFInvalidEncodingException is thrown.

Modified src/OFString.m from [5f30990c6d] to [8288fa97d2].

51
52
53
54
55
56
57















































58
59
60
61
62
63
64
/*
 * It seems strtod is buggy on Win32.
 * However, the MinGW version __strtod seems to be ok.
 */
#ifdef _WIN32
# define strtod __strtod
#endif
















































/* References for static linking */
void _references_to_categories_of_OFString(void)
{
	_OFString_Hashing_reference = 1;
	_OFString_JSONValue_reference = 1;
	_OFString_Serialization_reference = 1;







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







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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * It seems strtod is buggy on Win32.
 * However, the MinGW version __strtod seems to be ok.
 */
#ifdef _WIN32
# define strtod __strtod
#endif

static OFString*
standardize_path(OFArray *components, OFString *currentDirectory,
    OFString *parentDirectory, OFString *joinString)
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *array;
	OFString *ret;
	BOOL done = NO;

	array = [[components mutableCopy] autorelease];

	while (!done) {
		size_t i, length = [array count];

		done = YES;

		for (i = 0; i < length; i++) {
			id object = [array objectAtIndex: i];

			if ([object isEqual: currentDirectory]) {
				[array removeObjectAtIndex: i];
				done = NO;

				break;
			}

			if ([object isEqual: parentDirectory]) {
				[array removeObjectAtIndex: i];

				if (i > 0)
					[array removeObjectAtIndex: i - 1];

				done = NO;

				break;
			}
		}
	}

	ret = [[array componentsJoinedByString: joinString] retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}


/* References for static linking */
void _references_to_categories_of_OFString(void)
{
	_OFString_Hashing_reference = 1;
	_OFString_JSONValue_reference = 1;
	_OFString_Serialization_reference = 1;
1762
1763
1764
1765
1766
1767
1768













1769
1770
1771
1772
1773
1774
1775
		return [self substringWithRange: of_range(0, 1)];
	}

	objc_autoreleasePoolPop(pool);

	return @".";
}














- (intmax_t)decimalValue
{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *string = [self unicodeString];
	size_t length = [self length];
	int i = 0;







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







1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
		return [self substringWithRange: of_range(0, 1)];
	}

	objc_autoreleasePoolPop(pool);

	return @".";
}

- (OFString*)stringByStandardizingPath
{
	return standardize_path([self pathComponents],
	    OF_PATH_CURRENT_DIRECTORY, OF_PATH_PARENT_DIRECTORY,
	    OF_PATH_DELIMITER_STRING);
}

- (OFString*)stringByStandardizingURLPath
{
	return standardize_path( [self componentsSeparatedByString: @"/"],
	    @".", @"..", @"/");
}

- (intmax_t)decimalValue
{
	void *pool = objc_autoreleasePoolPush();
	const of_unichar_t *string = [self unicodeString];
	size_t length = [self length];
	int i = 0;

Modified src/OFURL.m from [f5ee6d65c8] to [0daa5e6ab9].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
84
85
86
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"

#import "autorelease.h"
#import "macros.h"

static OF_INLINE OFString*
resolve_relative_path(OFString *path)
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *array;
	OFString *ret;
	BOOL done = NO;

	array = [[[path componentsSeparatedByString: @"/"] mutableCopy]
	    autorelease];

	while (!done) {
		id *objects = [array objects];
		size_t i, length = [array count];

		done = YES;

		for (i = 0; i < length; i++) {
			if ([objects[i] isEqual: @"."]) {
				[array removeObjectAtIndex: i];
				done = NO;

				break;
			}

			if ([objects[i] isEqual: @".."]) {
				[array removeObjectAtIndex: i];

				if (i > 0)
					[array removeObjectAtIndex: i - 1];

				done = NO;

				break;
			}
		}
	}

	ret = [[array componentsJoinedByString: @"/"] retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

@implementation OFURL
+ (instancetype)URL
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)URLWithString: (OFString*)string







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







28
29
30
31
32
33
34













































35
36
37
38
39
40
41
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"

#import "autorelease.h"
#import "macros.h"














































@implementation OFURL
+ (instancetype)URL
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)URLWithString: (OFString*)string
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
								URL->path,
								UTF8String];
			else
				s = [OFString stringWithFormat: @"%@/../%s",
								URL->path,
								UTF8String];

			path = [resolve_relative_path(s) copy];

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







|







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
								URL->path,
								UTF8String];
			else
				s = [OFString stringWithFormat: @"%@/../%s",
								URL->path,
								UTF8String];

			path = [[s stringByStandardizingURLPath] copy];

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

Modified src/macros.h from [ba733f14be] to [60645bf692].

116
117
118
119
120
121
122

123
124

125

126
127
128
129
130
131
132
133
		fprintf(stderr, "Failed to ensure condition in "	\
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}

#ifndef _WIN32
# define OF_PATH_DELIMITER '/'

#else
# define OF_PATH_DELIMITER '\\'

#endif

#define OF_PATH_PARENT_DIR @".."

extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL);
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)
#define OF_GETTER(ivar, atomic) \
	return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic);







>


>

>
|







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
		fprintf(stderr, "Failed to ensure condition in "	\
		    __FILE__ ":%d:\n" #cond "\n", __LINE__);		\
		abort();						\
	}

#ifndef _WIN32
# define OF_PATH_DELIMITER '/'
# define OF_PATH_DELIMITER_STRING @"/"
#else
# define OF_PATH_DELIMITER '\\'
# define OF_PATH_DELIMITER_STRING @"\\"
#endif
#define OF_PATH_CURRENT_DIRECTORY @"."
#define OF_PATH_PARENT_DIRECTORY @".."

extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL);
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)
#define OF_GETTER(ivar, atomic) \
	return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic);