Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- NSDictionary *dictionaryForURL(NSURL *aURL)
- {
- NSLog(@"scheme = %@ host = %@ port = %@ fragment = %@ lastPathComponent = %@ parameterString = %@ "
- @"query = %@ user = %@ password = %@ resourceSpecifier = %@",
- [aURL scheme],[aURL host],[aURL port],[aURL fragment],[aURL lastPathComponent],[aURL parameterString],
- [aURL query],[aURL user],[aURL password],[aURL resourceSpecifier]);
- NSLog(@"absoluteString = %@",[aURL absoluteString]);
- NSLog(@"relativePath = %@",[aURL relativePath]);
- NSLog(@"relativeString = %@",[aURL relativeString]);
- NSLog(@"path = %@",[aURL path]);
- NSLog(@"pathExtension = %@",[aURL pathExtension]);
- NSLog(@"baseURL = %@",[aURL baseURL]);
- NSLog(@"standardizedURL = %@",[aURL standardizedURL]);
- NSLog(@"absoluteURL = %@",[aURL absoluteURL]);
- NSMutableDictionary *aDict = [NSMutableDictionary dictionary];
- for (NSString *aString in [[aURL query] componentsSeparatedByString:@"&"]) {
- NSArray *anArray = [aString componentsSeparatedByString:@"="];
- NSString *aKey = [anArray objectAtIndex:0];
- if ( [anArray count] == 2 ) {
- NSString *aValue = [anArray objectAtIndex:1];
- [aDict setObject:aValue forKey:aKey];
- }
- else {
- [aDict setObject:[NSNull null] forKey:aKey];
- }
- }
- return aDict;
- }
- int main(int argc, const char * argv[])
- {
- @autoreleasepool {
- NSLog(@"%@",dictionaryForURL([NSURL URLWithString:@"myscheme://myname:hogehoge@localhost:8080/cgi-bin/time.cgi;options?from=123456&to=789012&wrap=YES&novalue#something"]));
- // <scheme>://<user>:<password>@<host>:<port>/<path>;<parameterString>&<query>#<fragment>
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment