-
Notifications
You must be signed in to change notification settings - Fork 28
/
DDURLParser.m
50 lines (44 loc) · 1.41 KB
/
DDURLParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// DDURLParser.m
//
//
// Created by Dimitris Doukas on 09/02/2010.
// Copyright 2010 doukasd.com. All rights reserved.
//
#import "DDURLParser.h"
@implementation DDURLParser
- (id) initWithURLString:(NSString *)url{
self = [super init];
if (self != nil) {
NSString *string = url;
NSScanner *scanner = [NSScanner scannerWithString:string];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?"]];
NSString *tempString;
NSMutableArray *vars = [NSMutableArray new];
//ignore the beginning of the string and skip to the vars
[scanner scanUpToString:@"?" intoString:nil];
while ([scanner scanUpToString:@"&" intoString:&tempString]) {
[vars addObject:[tempString copy]];
}
variables = [vars copy];
[vars release];
}
return self;
}
- (NSString *)valueForVariable:(NSString *)varName {
int i;
for (i = 0; i < [variables count]; i++) {
NSString *var = [variables objectAtIndex:i];
if ([var length] > [varName length]+1 && [[var substringWithRange:NSMakeRange(0, [varName length]+1)] isEqualToString:[varName stringByAppendingString:@"="]]) {
NSString *varValue = [var substringFromIndex:[varName length]+1];
return varValue;
}
}
return nil;
}
- (void) dealloc{
[variables release];
variables = nil;
[super dealloc];
}
@end