ObjFW  Check-in [379d75e1bc]

Overview
Comment:OFString: Fix standardize_path().

It still needs some more special casing for Windows.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 379d75e1bc557d7fb68fdbb51ccbd5c6251759ad903f20aec2b28de7fd3d8d9a
User & Date: js on 2013-06-17 09:36:34
Other Links: manifest | tags
Context
2013-06-18
21:37
Make more use of OF_STRING_ENCODING_NATIVE. check-in: 7c7187345a user: js tags: trunk
2013-06-17
09:36
OFString: Fix standardize_path(). check-in: 379d75e1bc user: js tags: trunk
08:54
Replace a few asserts with OF_ENSURE / OBJC_ERROR. check-in: dc17a614e8 user: js tags: trunk
Changes

Modified src/OFString.m from [250db502f2] to [efdad56a90].

171
172
173
174
175
176
177
178
179
180




181
182
183
184
185
186
187
188

189





190

191
192
193

194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209






210
211
212
213
214
215
216
static OFString*
standardize_path(OFArray *components, OFString *currentDirectory,
    OFString *parentDirectory, OFString *joinString)
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *array;
	OFString *ret;
	bool done = false;

	array = [[components mutableCopy] autorelease];





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

		done = true;

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







			if ([object isEqual: currentDirectory]) {

				[array removeObjectAtIndex: i];
				done = false;


				break;
			}

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

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


				done = false;

				break;
			}
		}
	}







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

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}








|


>
>
>
>








>

>
>
>
>
>
|
>

<

>



|
|
|
<
|
>


<





>
>
>
>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210

211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
static OFString*
standardize_path(OFArray *components, OFString *currentDirectory,
    OFString *parentDirectory, OFString *joinString)
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *array;
	OFString *ret;
	bool done = false, startsWithEmpty, endsWithEmpty;

	array = [[components mutableCopy] autorelease];

	if ((startsWithEmpty = [[array firstObject] isEqual: @""]))
		[array removeObjectAtIndex: 0];
	endsWithEmpty = [[array lastObject] isEqual: @""];

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

		done = true;

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

			if (i > 0)
				parent = [array objectAtIndex: i - 1];
			else
				parent = nil;

			if ([object isEqual: currentDirectory] ||
			   [object length] == 0) {
				[array removeObjectAtIndex: i];


				done = false;
				break;
			}

			if ([object isEqual: parentDirectory] &&
			    parent != nil &&
			    ![parent isEqual: parentDirectory]) {

				[array removeObjectsInRange:
				    of_range(i - 1, 2)];

				done = false;

				break;
			}
		}
	}

	if (startsWithEmpty)
		[array insertObject: @""
			    atIndex: 0];
	if (endsWithEmpty)
		[array addObject: @""];

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

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}