/
TDTokenArraySource.h
62 lines (51 loc) · 1.75 KB
/
TDTokenArraySource.h
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
51
52
53
54
55
56
57
58
59
60
61
62
//
// TDTokenArraySource.h
// TDParseKit
//
// Created by Todd Ditchendorf on 12/11/08.
// Copyright 2008 Todd Ditchendorf. All rights reserved.
//
#import <Foundation/Foundation.h>
@class TDTokenizer;
@class TDToken;
/*!
@class TDTokenArraySource
@brief A <tt>TokenArraySource</tt> is a handy utility that enumerates over a specified reader, returning <tt>NSArray</tt>s of <tt>TDToken</tt>s delimited by a specified delimiter.
@details For example,
@code
NSString *s = @"I came; I saw; I left in peace;";
TDTokenizer *t = [TDTokenizer tokenizerWithString:s];
TDTokenArraySource *src = [[[TDTokenArraySource alloc] initWithTokenizer:t delimiter:@";"] autorelease];
while ([src hasMore]) {
NSLog(@"%@", [src nextTokenArray]);
}
@endcode
prints out:
@code
I came
I saw
I left in peace
@endcode
*/
@interface TDTokenArraySource : NSObject {
TDTokenizer *tokenizer;
NSString *delimiter;
TDToken *nextToken;
}
/*!
@brief Constructs a <tt>TDTokenArraySource</tt> that will read an <tt>NSArray</tt>s of <tt>TDToken</tt>s using the specified tokenizer, delimited by the specified delimiter.
@param tokenizer a tokenizer to read tokens from
@param delimiter the character(s) that fences off where one array of tokens ends and the next begins
*/
- (id)initWithTokenizer:(TDTokenizer *)t delimiter:(NSString *)s;
/*!
@brief true if the source has more arrays of tokens.
@result true, if the source has more arrays of tokens that have not yet been popped with <tt>-nextTokenArray</tt>
*/
- (BOOL)hasMore;
/*!
@brief Returns the next array of tokens from the source.
@result the next array of tokens from the source
*/
- (NSArray *)nextTokenArray;
@end