My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes  
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// PKWhitespaceState.m
// ParseKit
//
// Created by Todd Ditchendorf on 1/20/06.
// Copyright 2009 Todd Ditchendorf. All rights reserved.
//

#import <ParseKit/PKWhitespaceState.h>
#import <ParseKit/PKReader.h>
#import <ParseKit/PKTokenizer.h>
#import <ParseKit/PKToken.h>
#import <ParseKit/PKTypes.h>

#define PKTRUE (id)kCFBooleanTrue
#define PKFALSE (id)kCFBooleanFalse

@interface PKToken ()
@property (nonatomic, readwrite) NSUInteger offset;
@end

@interface PKTokenizerState ()
- (void)resetWithReader:(PKReader *)r;
- (void)append:(PKUniChar)c;
- (NSString *)bufferedString;
@end

@interface PKWhitespaceState ()
@property (nonatomic, retain) NSMutableArray *whitespaceChars;
@end

@implementation PKWhitespaceState

- (id)init {
if (self = [super init]) {
const NSUInteger len = 255;
self.whitespaceChars = [NSMutableArray arrayWithCapacity:len];
NSUInteger i = 0;
for ( ; i <= len; i++) {
[whitespaceChars addObject:PKFALSE];
}

[self setWhitespaceChars:YES from:0 to:' '];
}
return self;
}


- (void)dealloc {
self.whitespaceChars = nil;
[super dealloc];
}


- (void)setWhitespaceChars:(BOOL)yn from:(PKUniChar)start to:(PKUniChar)end {
NSUInteger len = [whitespaceChars count];
if (start > len || end > len || start < 0 || end < 0) {
[NSException raise:@"PKWhitespaceStateNotSupportedException" format:@"PKWhitespaceState only supports setting word chars for chars in the latin1 set (under 256)"];
}

id obj = yn ? PKTRUE : PKFALSE;
NSUInteger i = start;
for ( ; i <= end; i++) {
[whitespaceChars replaceObjectAtIndex:i withObject:obj];
}
}


- (BOOL)isWhitespaceChar:(PKUniChar)cin {
if (cin < 0 || cin > [whitespaceChars count] - 1) {
return NO;
}
return PKTRUE == [whitespaceChars objectAtIndex:cin];
}


- (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin tokenizer:(PKTokenizer *)t {
NSParameterAssert(r);
if (reportsWhitespaceTokens) {
[self resetWithReader:r];
}

PKUniChar c = cin;
while ([self isWhitespaceChar:c]) {
if (reportsWhitespaceTokens) {
[self append:c];
}
c = [r read];
}
if (PKEOF != c) {
[r unread];
}

if (reportsWhitespaceTokens) {
PKToken *tok = [PKToken tokenWithTokenType:PKTokenTypeWhitespace stringValue:[self bufferedString] floatValue:0.0];
tok.offset = offset;
return tok;
} else {
return [t nextToken];
}
}

@synthesize whitespaceChars;
@synthesize reportsWhitespaceTokens;
@end

Change log

r1405 by todd.ditchendorf on Oct 7, 2009   Diff
no more a.count. use [a count] instead
Go to: 
Project members, sign in to write a code review

Older revisions

r1170 by todd.ditchendorf on Jul 3, 2009   Diff
copyright
r1124 by todd.ditchendorf on Jun 30, 2009   Diff
continuing the move to rename to
ParseKit
r1115 by todd.ditchendorf on Jun 29, 2009   Diff
continuing the move to rename to
ParseKit
All revisions of this file

File info

Size: 2643 bytes, 106 lines

File properties

svn:mergeinfo
Powered by Google Project Hosting