-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTDReader.j
More file actions
55 lines (43 loc) · 746 Bytes
/
TDReader.j
File metadata and controls
55 lines (43 loc) · 746 Bytes
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
@import <Foundation/Foundation.j>
@implementation TDReader : CPObject
{
CPString string;
unsigned cursor;
unsigned length;
}
- (id)init
{
return [self initWithString:nil];
}
- (id)initWithString:(CPString)s
{
if (self = [super init]) {
[self setString:s];
}
return self;
}
- (CPString)string
{
return string;
}
- (void)setString:(CPString)s
{
if (string !== s) {
string = s;
length = string ? string.length : 0;
}
// reset cursor
cursor = 0;
}
- (unsigned)read
{
if (0 === length || cursor > length - 1) {
return -1;
}
return string.charAt(cursor++);
}
- (void)unread
{
cursor = (0 === cursor) ? 0 : cursor - 1;
}
@end