From b2ffe7e5093c3098e6843e788c06b292be93b40d Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Fri, 5 Mar 2010 21:11:53 -0800 Subject: [PATCH] Further cleaning and bringing CPURL up to speed with CFURL. Reviewed by me. --- Foundation/CPURL.j | 29 +++++++++-------------------- Objective-J/Bootstrap.js | 5 +++++ Objective-J/CFBundle.js | 6 +++--- Objective-J/CFURL.js | 24 ++++++++++++++++++++++-- Objective-J/Executable.js | 10 +++++----- Objective-J/FileExecutable.js | 4 ++-- Objective-J/StaticResource.js | 13 ++++--------- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/Foundation/CPURL.j b/Foundation/CPURL.j index e5ef1e3e2..a40c42a7d 100644 --- a/Foundation/CPURL.j +++ b/Foundation/CPURL.j @@ -86,13 +86,13 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; - (CPString)path { - return [self absoluteString].path(); + return [self absoluteURL].path(); } // if absolute, returns the same as path - (CPString)relativePath { - return URI_RE.test(_relative) ? (parse(_relative).path || nil) : nil; + return self.path(); } - (CPString)scheme @@ -102,43 +102,32 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; - (CPString)user { - var str = [self absoluteString]; - return URI_RE.test(str) ? (parse(str).user || nil) : nil; + return [self absoluteURL].user(); } - (CPString)password { - var str = [self absoluteString]; - return URI_RE.test(str) ? (parse(str).password || nil) : nil; + return [self absoluteURL].password(); } - (CPString)host { - var str = [self absoluteString]; - return URI_RE.test(str) ? (parse(str).domain || nil) : nil; + return [self absoluteURL].domain(); } - (Number)port { - var str = [self absoluteString]; - if (URI_RE.test(str)) { - var port = parse(str).port; - if (port) - return parseInt(port, 10); - } - return nil; + return parseInt([self absoluteURL].port(), 10); } - (CPString)parameterString { - var str = [self absoluteString]; - return URI_RE.test(str) ? (parse(str).query || nil) : nil; + return self.queryString(); } - (CPString)fragment { - var str = [self absoluteString]; - return URI_RE.test(str) ? (parse(str).anchor || nil) : nil; + return self.fragment(); } - (BOOL)isEqual:(id)anObject @@ -160,7 +149,7 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; - (CPURL)standardizedURL { - return [CPURL URLWithString:format(parse(_relative)) relativeToURL:_base]; + return self.standardizedURL(); } - (BOOL)isFileURL diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index 26b526b6a..26b3b9de2 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -21,6 +21,11 @@ */ +function makeAbsoluteURL(/*CFURL|String*/ aURL) +{ + return new CFURL(aURL, mainBundleURL); +} + #ifdef COMMONJS var mainBundleURL = new CFURL("file:" + require("file").cwd()); #elif defined(BROWSER) diff --git a/Objective-J/CFBundle.js b/Objective-J/CFBundle.js index 4ab762fac..b5882e287 100644 --- a/Objective-J/CFBundle.js +++ b/Objective-J/CFBundle.js @@ -35,7 +35,7 @@ var CFBundlesForURLStrings = { }, GLOBAL(CFBundle) = function(/*CFURL|String*/ aURL) { - aURL = resolveURL(aURL).asDirectoryPathURL(); + aURL = makeAbsoluteURL(aURL).asDirectoryPathURL(); var URLString = aURL.absoluteString(), existingBundle = CFBundlesForURLStrings[URLString]; @@ -64,9 +64,9 @@ CFBundle.environments = function() return ENVIRONMENTS; } -CFBundle.bundleContainingURL = function(/*CFURL*/ aURL) +CFBundle.bundleContainingURL = function(/*CFURL|String*/ aURL) { - aURL = new CFURL(".", resolveURL(aURL)); + aURL = new CFURL(".", makeAbsoluteURL(aURL)); while (aURL.path() !== "/") { diff --git a/Objective-J/CFURL.js b/Objective-J/CFURL.js index 55f32364d..b224793f5 100644 --- a/Objective-J/CFURL.js +++ b/Objective-J/CFURL.js @@ -221,7 +221,7 @@ CFURL.prototype.toString = function() return this.absoluteString(); } -function _resolveURL(aURL) +function resolveURL(aURL) { aURL = aURL.standardizedURL(); @@ -356,7 +356,7 @@ function URLStringFromParts(/*Object*/ parts) CFURL.prototype.absoluteURL = function() { if (this._absoluteURL === undefined) - this._absoluteURL = _resolveURL(this); + this._absoluteURL = resolveURL(this); return this._absoluteURL; } @@ -504,6 +504,26 @@ CFURL.prototype.scheme = function() return baseURL && baseURL.scheme() || ""; } +CFURL.prototype.user = function() +{ + return CFURLGetParts(this).user; +} + +CFURL.prototype.password = function() +{ + return CFURLGetParts(this).password; +} + +CFURL.prototype.port = function() +{ + return CFURLGetParts(this).port; +} + +CFURL.prototype.domain = function() +{ + return CFURLGetParts(this).domain; +} + CFURL.prototype.baseURL = function() { return this._baseURL; diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index bd0c1d468..5cce25e52 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -26,14 +26,14 @@ var ExecutableUnloadedFileDependencies = 0, ExecutableLoadedFileDependencies = 2, AnonymousExecutableCount = 0; -function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL*/ aURL, /*Function*/ aFunction) +function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction) { if (arguments.length === 0) return this; this._code = aCode; this._function = aFunction || NULL; - this._URL = resolveURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")", mainBundleURL)); + this._URL = makeAbsoluteURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")", mainBundleURL)); this._fileDependencies = fileDependencies; this._fileDependencyLoadStatus = ExecutableUnloadedFileDependencies; @@ -329,7 +329,7 @@ var cachedFileExecutersForURLStrings = { }; Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL) { - var referenceURL = resolveURL(aURL), + var referenceURL = makeAbsoluteURL(aURL), referenceURLString = referenceURL.absoluteString(), cachedFileExecuter = cachedFileExecutersForURLStrings[referenceURLString]; @@ -356,9 +356,9 @@ Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL) var cachedImportersForURLStrings = { }; -Executable.fileImporterForURL = function(/*CFURL*/ aURL) +Executable.fileImporterForURL = function(/*CFURL|String*/ aURL) { - var referenceURL = resolveURL(aURL), + var referenceURL = makeAbsoluteURL(aURL), referenceURLString = referenceURL.absoluteString(), cachedImporter = cachedImportersForURLStrings[referenceURLString]; diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 18c7d477d..63645ffe6 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -22,9 +22,9 @@ var FileExecutablesForURLStrings = { }; -function FileExecutable(/*CFURL*/ aURL, /*Executable*/ anExecutable) +function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable) { - aURL = resolveURL(aURL); + aURL = makeAbsoluteURL(aURL); var URLString = aURL.absoluteString(), existingFileExecutable = FileExecutablesForURLStrings[URLString]; diff --git a/Objective-J/StaticResource.js b/Objective-J/StaticResource.js index 02537ff4b..9ef509539 100644 --- a/Objective-J/StaticResource.js +++ b/Objective-J/StaticResource.js @@ -124,14 +124,9 @@ function rootResourceForAbsoluteURL(/*CFURL*/ anAbsoluteURL) return resource; } -function resolveURL(/*CFURL|String*/ aURL) +StaticResource.resourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ resolveAsDirectoriesIfNecessary) { - return new CFURL(aURL, mainBundleURL); -} - -StaticResource.resourceAtURL = function(/*CFURL*/ aURL, /*BOOL*/ resolveAsDirectoriesIfNecessary) -{ - aURL = resolveURL(aURL).absoluteURL(); + aURL = makeAbsoluteURL(aURL).absoluteURL(); var resource = rootResourceForAbsoluteURL(aURL), components = aURL.pathComponents(), @@ -160,9 +155,9 @@ StaticResource.prototype.resourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL* return StaticResource.resourceAtURL(new CFURL(aURL, this.URL()), resolveAsDirectoriesIfNecessary); } -StaticResource.resolveResourceAtURL = function(/*CFURL*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback) +StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback) { - aURL = resolveURL(aURL).absoluteURL(); + aURL = makeAbsoluteURL(aURL).absoluteURL(); resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback); }