Skip to content

Commit

Permalink
First stab at KSURLComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeabdullah committed Jul 6, 2013
1 parent 4985e63 commit 0414a2c
Show file tree
Hide file tree
Showing 4 changed files with 379 additions and 0 deletions.
6 changes: 6 additions & 0 deletions KSFileUtilities.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
27A90103165C003A00D23C4B /* nameprep.c in Sources */ = {isa = PBXBuildFile; fileRef = 27A90101165C003A00D23C4B /* nameprep.c */; };
27A90106165C005700D23C4B /* puny.c in Sources */ = {isa = PBXBuildFile; fileRef = 27A90104165C005600D23C4B /* puny.c */; };
27DA2577148E641100209E50 /* TestKSURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 27DA2576148E641100209E50 /* TestKSURLUtilities.m */; };
27F0501C178829220019FC07 /* KSURLComponents.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F0501B178829180019FC07 /* KSURLComponents.m */; };
27F86FBF164FBA9D003608CC /* KSEncodeURLString.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F86FBE164FBA9D003608CC /* KSEncodeURLString.m */; };
801978D514FEDE0B008F41E3 /* TestKSURLNormalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 801978D414FEDE0B008F41E3 /* TestKSURLNormalization.m */; };
801978D914FEDE26008F41E3 /* KSURLNormalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 801978D714FEDE26008F41E3 /* KSURLNormalization.m */; };
Expand Down Expand Up @@ -45,6 +46,8 @@
27A90104165C005600D23C4B /* puny.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = puny.c; path = IFUnicodeURL/IDNSDK/puny.c; sourceTree = "<group>"; };
27A90105165C005700D23C4B /* puny.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = puny.h; path = IFUnicodeURL/IDNSDK/puny.h; sourceTree = "<group>"; };
27DA2576148E641100209E50 /* TestKSURLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestKSURLUtilities.m; sourceTree = "<group>"; };
27F0501A178829180019FC07 /* KSURLComponents.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KSURLComponents.h; sourceTree = SOURCE_ROOT; };
27F0501B178829180019FC07 /* KSURLComponents.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KSURLComponents.m; sourceTree = SOURCE_ROOT; };
27F86FBD164FBA9D003608CC /* KSEncodeURLString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KSEncodeURLString.h; sourceTree = SOURCE_ROOT; };
27F86FBE164FBA9D003608CC /* KSEncodeURLString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KSEncodeURLString.m; sourceTree = SOURCE_ROOT; };
801978D414FEDE0B008F41E3 /* TestKSURLNormalization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestKSURLNormalization.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -111,6 +114,8 @@
EE43C84413898D7B008ABD16 /* KSFileWrapperExtensions.m */,
EE43C84513898D7B008ABD16 /* KSURLFormatter.h */,
EE43C84613898D7B008ABD16 /* KSURLFormatter.m */,
27F0501A178829180019FC07 /* KSURLComponents.h */,
27F0501B178829180019FC07 /* KSURLComponents.m */,
27246F10165BF1D2001B638E /* IFUnicodeURL */,
27F86FBD164FBA9D003608CC /* KSEncodeURLString.h */,
27F86FBE164FBA9D003608CC /* KSEncodeURLString.m */,
Expand Down Expand Up @@ -278,6 +283,7 @@
EE43C85113898D7B008ABD16 /* KSURLUtilities.m in Sources */,
EE43C85213898D7B008ABD16 /* KSWebLocation.m in Sources */,
EE43C85313898D7B008ABD16 /* KSWebLocationPasteboardUtilities.m in Sources */,
27F0501C178829220019FC07 /* KSURLComponents.m in Sources */,
EE43C85413898D7B008ABD16 /* KSWorkspaceUtilities.m in Sources */,
27DA2577148E641100209E50 /* TestKSURLUtilities.m in Sources */,
801978D514FEDE0B008F41E3 /* TestKSURLNormalization.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectIdentifier</key>
<string>72EB93BD-5E52-4CFC-9084-BB412C002BC8</string>
<key>IDESourceControlProjectName</key>
<string>KSFileUtilities</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>ACFADC67-D143-4184-867B-0593C0DAF284</key>
<string>ssh://github.com/karelia/IFUnicodeURL.git</string>
<key>D8088101-6CE1-4173-B3CC-942700F057E2</key>
<string>ssh://github.com/karelia/KSFileUtilities.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>KSFileUtilities.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>ACFADC67-D143-4184-867B-0593C0DAF284</key>
<string>../IFUnicodeURL</string>
<key>D8088101-6CE1-4173-B3CC-942700F057E2</key>
<string>..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/karelia/KSFileUtilities.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>D8088101-6CE1-4173-B3CC-942700F057E2</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>D8088101-6CE1-4173-B3CC-942700F057E2</string>
<key>IDESourceControlWCCName</key>
<string>KSFileUtilities</string>
</dict>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>ACFADC67-D143-4184-867B-0593C0DAF284</string>
<key>IDESourceControlWCCName</key>
<string>IFUnicodeURL</string>
</dict>
</array>
</dict>
</plist>
63 changes: 63 additions & 0 deletions KSURLComponents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// KSURLComponents.h
// KSFileUtilities
//
// Created by Mike on 06/07/2013.
// Copyright (c) 2013 Karelia Software. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface KSURLComponents : NSObject
{
@private
NSString *_schemeComponent;
NSString *_userComponent;
NSString *_passwordComponent;
NSString *_hostComponent;
NSNumber *_portComponent;
NSString *_pathComponent;
NSString *_queryComponent;
NSString *_fragmentComponent;
}

// Initialize a KSURLComponents with the components of a URL. If resolvingAgainstBaseURL is YES and url is a relative URL, the components of [url absoluteURL] are used. If the url string from the NSURL is malformed, nil is returned.
- (id)initWithURL:(NSURL *)url resolvingAgainstBaseURL:(BOOL)resolve;

// Initializes and returns a newly created KSURLComponents with the components of a URL. If resolvingAgainstBaseURL is YES and url is a relative URL, the components of [url absoluteURL] are used. If the url string from the NSURL is malformed, nil is returned.
+ (id)componentsWithURL:(NSURL *)url resolvingAgainstBaseURL:(BOOL)resolve;

// Initialize a KSURLComponents with a URL string. If the URLString is malformed, nil is returned.
- (id)initWithString:(NSString *)URLString;

// Initializes and returns a newly created KSURLComponents with a URL string. If the URLString is malformed, nil is returned.
+ (id)componentsWithString:(NSString *)URLString;

// Returns a URL created from the NSURLComponents. If the NSURLComponents has an authority component (user, password, host or port) and a path component, then the path must either begin with "/" or be an empty string. If the NSURLComponents does not have an authority component (user, password, host or port) and has a path component, the path component must not start with "//". If those requirements are not met, nil is returned.
- (NSURL *)URL;

// Returns a URL created from the NSURLComponents relative to a base URL. If the NSURLComponents has an authority component (user, password, host or port) and a path component, then the path must either begin with "/" or be an empty string. If the NSURLComponents does not have an authority component (user, password, host or port) and has a path component, the path component must not start with "//". If those requirements are not met, nil is returned.
- (NSURL *)URLRelativeToURL:(NSURL *)baseURL;

// Warning: IETF STD 66 (rfc3986) says the use of the format "user:password" in the userinfo subcomponent of a URI is deprecated because passing authentication information in clear text has proven to be a security risk. However, there are cases where this practice is still needed, and so the user and password components and methods are provided.

// Getting these properties removes any percent encoding these components may have (if the component allows percent encoding). Setting these properties assumes the subcomponent or component string is not percent encoded and will add percent encoding (if the component allows percent encoding).
@property (copy) NSString *scheme; // Attempting to set the scheme with an invalid scheme string will cause an exception.
@property (copy) NSString *user;
@property (copy) NSString *password;
@property (copy) NSString *host;
@property (copy) NSNumber *port; // Attempting to set a negative port number will cause an exception.
@property (copy) NSString *path;
@property (copy) NSString *query;
@property (copy) NSString *fragment;

// Getting these properties retains any percent encoding these components may have. Setting these properties assumes the component string is already correctly percent encoded. Attempting to set an incorrectly percent encoded string will cause an exception. Although ';' is a legal path character, it is recommended that it be percent-encoded for best compatibility with NSURL (-stringByAddingPercentEncodingWithAllowedCharacters: will percent-encode any ';' chraracters if you pass the URLPathAllowedCharacterSet).
@property (copy) NSString *percentEncodedUser;
@property (copy) NSString *percentEncodedPassword;
@property (copy) NSString *percentEncodedHost;
@property (copy) NSString *percentEncodedPath;
@property (copy) NSString *percentEncodedQuery;
@property (copy) NSString *percentEncodedFragment;


@end
Loading

0 comments on commit 0414a2c

Please sign in to comment.