Guest User

Untitled

a guest
Dec 2nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2.  
  3. NSDictionary *dictionaryForURL(NSURL *aURL)
  4. {
  5. NSLog(@"scheme = %@ host = %@ port = %@ fragment = %@ lastPathComponent = %@ parameterString = %@ "
  6. @"query = %@ user = %@ password = %@ resourceSpecifier = %@",
  7. [aURL scheme],[aURL host],[aURL port],[aURL fragment],[aURL lastPathComponent],[aURL parameterString],
  8. [aURL query],[aURL user],[aURL password],[aURL resourceSpecifier]);
  9.  
  10. NSLog(@"absoluteString = %@",[aURL absoluteString]);
  11. NSLog(@"relativePath = %@",[aURL relativePath]);
  12. NSLog(@"relativeString = %@",[aURL relativeString]);
  13. NSLog(@"path = %@",[aURL path]);
  14. NSLog(@"pathExtension = %@",[aURL pathExtension]);
  15. NSLog(@"baseURL = %@",[aURL baseURL]);
  16. NSLog(@"standardizedURL = %@",[aURL standardizedURL]);
  17. NSLog(@"absoluteURL = %@",[aURL absoluteURL]);
  18.  
  19. NSMutableDictionary *aDict = [NSMutableDictionary dictionary];
  20. for (NSString *aString in [[aURL query] componentsSeparatedByString:@"&"]) {
  21. NSArray *anArray = [aString componentsSeparatedByString:@"="];
  22. NSString *aKey = [anArray objectAtIndex:0];
  23. if ( [anArray count] == 2 ) {
  24. NSString *aValue = [anArray objectAtIndex:1];
  25. [aDict setObject:aValue forKey:aKey];
  26. }
  27. else {
  28. [aDict setObject:[NSNull null] forKey:aKey];
  29. }
  30. }
  31. return aDict;
  32. }
  33.  
  34. int main(int argc, const char * argv[])
  35. {
  36. @autoreleasepool {
  37. NSLog(@"%@",dictionaryForURL([NSURL URLWithString:@"myscheme://myname:hogehoge@localhost:8080/cgi-bin/time.cgi;options?from=123456&to=789012&wrap=YES&novalue#something"]));
  38. // <scheme>://<user>:<password>@<host>:<port>/<path>;<parameterString>&<query>#<fragment>
  39. }
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment