mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 11:34:25 +00:00
Fix for stringByDeletingLastPathComponent.
[#126 state:resolved] Reviewed by tolmasky
This commit is contained in:
1 parent
9def3ba765
commit
9f9cc4c22c
4 files changed
+42
-7
No files matched your search
+1
-1
@@ -42,7 +42,7 @@ CPImageDidLoadNotification = @"CPImageDidLoadNotification";
|
||||
|
||||
- (CPString)pathForResource:(CPString)aFilename
|
||||
{
|
||||
return [self bundlePath] + "Resources/" + aFilename;
|
||||
return [self resourcePath] + '/' + aFilename;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -61,7 +61,12 @@
|
||||
|
||||
- (CPString)resourcePath
|
||||
{
|
||||
return [self bundlePath] + "Resources/";
|
||||
var path = [self bundlePath];
|
||||
|
||||
if (path.length)
|
||||
path += '/';
|
||||
|
||||
return path + "Resources";
|
||||
}
|
||||
|
||||
- (Class)principalClass
|
||||
|
||||
+15
-4
@@ -595,13 +595,24 @@ var CPStringHashes = new objj_dictionary();
|
||||
}
|
||||
|
||||
/*!
|
||||
Until this is corrected
|
||||
@ignore
|
||||
Deletes the last path component of a string.
|
||||
This method assumes that the string's content is a '/'
|
||||
separated file system path.
|
||||
*/
|
||||
- (CPString)stringByDeletingLastPathComponent
|
||||
{
|
||||
// FIXME: this is wrong: a/a/ returns a/a/.
|
||||
return substr(0, lastIndexOf('/') + 1);
|
||||
var path = self,
|
||||
start = length - 1;
|
||||
|
||||
while (path.charAt(start) === '/')
|
||||
start--;
|
||||
|
||||
path = path.substr(0, path.lastIndexOf('/', start));
|
||||
|
||||
if (path === "" && charAt(0) === '/')
|
||||
return '/';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
- (CPString)stringByStandardizingPath
|
||||
|
||||
@@ -56,9 +56,28 @@ import <Foundation/CPString.j>
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
|
||||
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
|
||||
}
|
||||
|
||||
- (void)testStringByDeletingLastPathComponent
|
||||
{
|
||||
var testStrings = [
|
||||
["/tmp/scratch.tiff", "/tmp"],
|
||||
["/tmp/lock/", "/tmp"],
|
||||
["/tmp/", "/"],
|
||||
["/tmp", "/"],
|
||||
["/", "/"],
|
||||
["scratch.tiff", ""],
|
||||
["a/b/c/d//////", "a/b/c"],
|
||||
["a/b/././././c/d/./././", "a/b/././././c/d/./."],
|
||||
[@"a/b/././././d////", "a/b/./././."],
|
||||
[@"~/a", "~"],
|
||||
[@"~/a/", "~"],
|
||||
[@"../../", ".."]
|
||||
];
|
||||
|
||||
for (var i = 0; i < testStrings.length; i++)
|
||||
[self assert:[testStrings[i][0] stringByDeletingLastPathComponent] equals:testStrings[i][1]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user