1 /* NSString+URL.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse group conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import "NSString+Utilities.h"
24 #import "NSDictionary+URL.h"
26 @implementation NSString (SOGoURLExtension)
28 - (NSString *) composeURLWithAction: (NSString *) action
29 parameters: (NSDictionary *) urlParameters
30 andHash: (BOOL) useHash
32 NSMutableString *completeURL;
34 completeURL = [NSMutableString new];
35 [completeURL autorelease];
37 [completeURL appendString: [self urlWithoutParameters]];
38 if (![completeURL hasSuffix: @"/"])
39 [completeURL appendString: @"/"];
40 [completeURL appendString: action];
41 [completeURL appendString: [urlParameters asURLParameters]];
43 [completeURL appendString: @"#"];
48 - (NSString *) hostlessURL
51 NSRange hostR, locationR;
53 if ([self hasPrefix: @"/"])
60 hostR = [self rangeOfString: @"://"];
61 locationR = [[self substringFromIndex: (hostR.location + hostR.length)]
63 newURL = [self substringFromIndex: (hostR.location + hostR.length + locationR.location)];
69 - (NSString *) urlWithoutParameters;
74 r = [self rangeOfString:@"?" options: NSBackwardsSearch];
76 newUrl = [self substringToIndex: NSMaxRange(r) - 1];
83 - (NSString *) davMethodToObjC
85 NSMutableString *newName;
86 NSEnumerator *components;
89 newName = [NSMutableString stringWithString: @"dav"];
90 components = [[self componentsSeparatedByString: @"-"] objectEnumerator];
91 component = [components nextObject];
94 [newName appendString: [component capitalizedString]];
95 component = [components nextObject];