Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (62 sloc) 1.645 kB
ee99867 @ccgus oh geeze
authored
1 //
2 // TDTokenArraySource.m
3 // TDParseKit
4 //
5 // Created by Todd Ditchendorf on 12/11/08.
6 // Copyright 2008 Todd Ditchendorf. All rights reserved.
7 //
8
9 #import "TDTokenArraySource.h"
10 #import "TDToken.h"
11 #import "TDTokenizer.h"
12
13 @interface TDTokenArraySource ()
14 @property (nonatomic, retain) TDTokenizer *tokenizer;
15 @property (nonatomic, retain) NSString *delimiter;
16 @property (nonatomic, retain) TDToken *nextToken;
17 @end
18
19 @implementation TDTokenArraySource
20
21 - (id)init {
22 return [self initWithTokenizer:nil delimiter:nil];
23 }
24
25
26 - (id)initWithTokenizer:(TDTokenizer *)t delimiter:(NSString *)s {
27 NSParameterAssert(t);
28 NSParameterAssert(s);
29 self = [super init];
30 if (self) {
31 self.tokenizer = t;
32 self.delimiter = s;
33 }
34 return self;
35 }
36
37
38 - (void)dealloc {
39 self.tokenizer = nil;
40 self.delimiter = nil;
41 self.nextToken = nil;
42 [super dealloc];
43 }
44
45
46 - (BOOL)hasMore {
47 if (!nextToken) {
48 self.nextToken = [tokenizer nextToken];
49 }
50
51 return ([TDToken EOFToken] != nextToken);
52 }
53
54
55 - (NSArray *)nextTokenArray {
56 if (![self hasMore]) {
57 return nil;
58 }
59
60 NSMutableArray *res = [NSMutableArray arrayWithObject:nextToken];
61 self.nextToken = nil;
62
63 TDToken *eof = [TDToken EOFToken];
64 TDToken *tok = nil;
65
66 while ((tok = [tokenizer nextToken]) != eof) {
67 if ([tok.stringValue isEqualToString:delimiter]) {
68 break; // discard delimiter tok
69 }
70 [res addObject:tok];
71 }
72
73 //return [[res copy] autorelease];
74 return res; // optimization
75 }
76
77 @synthesize tokenizer;
78 @synthesize delimiter;
79 @synthesize nextToken;
80 @end
Something went wrong with that request. Please try again.