Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (51 sloc) 1.612 kB
7aa6b9d The remaining "core" files OBJJified (with probable errors)
Ross Boucher authored
1
2 @import "TDTokenizerState.j"
3
4 @implementation TDWhitespaceState : TDTokenizerState
5 {
6 CPArray whitespaceChars;
7 BOOL reportsWhitespaceTokens;
8 }
9
10 - (id)init
11 {
12 if (self = [super init])
13 {
14 whitespaceChars = [];
15
16 for (var i=0, len=255; i <= len; i++) {
17 [whitespaceChars addObject:NO];
18 }
19
20 [self setWhitespaceChars:YES from:0 to:255];
21 }
22
23 return self;
24 }
25
26 - (void)setWhitespaceChars:(BOOL)yn from:(unsigned)start to:(unsigned)end
27 {
28 var len = whitespaceChars.length;
29 if (start > len || end > len || start < 0 || end < 0)
30 [CPException raise:@"TDWhitespaceStateNotSupportedException" reason:@"TDWhitespaceState only supports setting word chars for chars in the latin1 set (under 256)"];
31
32 for (var i=start ; i <= end; i++) {
33 [whitespaceChars replaceObjectAtIndex:i withObject:yn];
34 }
35 }
36
37 - (BOOL)isWhitespaceChar:(unsigned)cin
38 {
39 if (cin < 0 || cin > whitespaceChars.length - 1)
40 return NO;
41
42 return !![whitespaceChars objectAtIndex:cin];
43 }
44
45 - (TDToken)nextTokenFromReader:(TDReader)r startingWith:(unsigned)cin tokenizer:(TDTokenizer)t
46 {
47 if (reportsWhitespaceTokens)
48 [self reset];
49
50 var c = cin;
51 while ([self isWhitespaceChar:c]) {
52 if (reportsWhitespaceTokens)
53 [self append:c];
54
55 c = [r read];
56 }
57
58 if (-1 != c)
59 [r unread];
60
61 if (reportsWhitespaceTokens)
62 return [TDToken tokenWithTokenType:TDTokenTypeWhitespace stringValue:[self bufferedString] floatValue:0.0];
63 else
64 return [t nextToken];
65 }
66
67 @end
Something went wrong with that request. Please try again.