Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (68 sloc) 2.433 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "TDNCNameState.h"
16 #import "PKTokenizer.h"
17 #import "PKReader.h"
18 #import "TDXmlToken.h"
19
20 @interface PKTokenizerState ()
21 - (void)resetWithReader:(PKReader *)r;
22 - (void)append:(PKUniChar)c;
23 - (NSString *)bufferedString;
24 @end
25
26 @interface TDNCNameState ()
27 + (BOOL)isNameChar:(PKUniChar)c;
28 + (BOOL)isValidStartSymbolChar:(PKUniChar)c;
29 + (BOOL)isValidNonStartSymbolChar:(PKUniChar)c;
30 @end
31
32 // NCName ::= (Letter | '_') (NameChar)*
33 @implementation TDNCNameState
34
35 //- (BOOL)isWhitespace:(PKUniChar)c {
36 // return (' ' == c || '\n' == c || '\r' == c || '\t' == c);
37 //}
38
39
40 // NameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
41 + (BOOL)isNameChar:(PKUniChar)c {
42 if (isalnum(c)) {
43 return YES;
44 } else if ([self isValidNonStartSymbolChar:c]) {
45 return YES;
46 }
47 // TODO CombiningChar & Extender
48 return NO;
49 }
50
51
52 + (BOOL)isValidStartSymbolChar:(PKUniChar)c {
53 return ('_' == c);
54 }
55
56
57 + (BOOL)isValidNonStartSymbolChar:(PKUniChar)c {
58 return ('_' == c || '.' == c || '-' == c);
59 }
60
61
62 - (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin tokenizer:(PKTokenizer *)t {
63 [self resetWithReader:r];
64
eb778c5 @itod merging changes from Google Code SVN repo
authored
65 PKUniChar c = cin;
05eedb5 @itod initial add
authored
66 do {
67 [self append:c];
68 c = [r read];
69 } while ([TDNCNameState isNameChar:c]);
70
71 if (PKEOF != c) {
72 [r unread];
73 }
74
75 if ([[self bufferedString] length] == 1 && [TDNCNameState isValidStartSymbolChar:cin]) {
76 return [t.symbolState nextTokenFromReader:r startingWith:cin tokenizer:t];
77 } else {
78 // return [[[TDXmlToken alloc] initWithTokenType:TDTT_NAME
79 // stringValue:[[stringbuf copy] autorelease]
80 // floatValue:0.0] autorelease];
81 return nil;
82 }
83 }
84
85 @end
Something went wrong with that request. Please try again.