@@ -20,11 +20,11 @@ pub fn slice<'a>(src: &'a str, (begin, end): (uint, uint)) -> &'a str{
20
20
}
21
21
22
22
enum State {
23
- Code ,
24
- Comment ,
25
- CommentBlock ,
26
- String ,
27
- Finished
23
+ StateCode ,
24
+ StateComment ,
25
+ StateCommentBlock ,
26
+ StateString ,
27
+ StateFinished
28
28
}
29
29
30
30
pub struct CodeIndicesIter < ' a > {
@@ -39,11 +39,11 @@ impl<'a> Iterator<(uint, uint)> for CodeIndicesIter<'a> {
39
39
#[ inline]
40
40
fn next ( & mut self ) -> Option < ( uint , uint ) > {
41
41
return match self . state {
42
- Code => code ( self ) ,
43
- Comment => comment ( self ) ,
44
- CommentBlock => comment_block ( self ) ,
45
- String => string ( self ) ,
46
- Finished => None
42
+ StateCode => code ( self ) ,
43
+ StateComment => comment ( self ) ,
44
+ StateCommentBlock => comment_block ( self ) ,
45
+ StateString => string ( self ) ,
46
+ StateFinished => None
47
47
}
48
48
}
49
49
}
@@ -60,28 +60,28 @@ fn code(self_: &mut CodeIndicesIter) -> Option<(uint,uint)> {
60
60
if pos > 0 && src_bytes[ pos] == slash && src_bytes[ pos-1 ] == slash {
61
61
self_. start = pos+1 ;
62
62
self_. pos = pos+1 ;
63
- self_. state = Comment ;
63
+ self_. state = StateComment ;
64
64
return Some ( ( start, pos-1 ) ) ;
65
65
}
66
66
67
67
if pos > 0 && src_bytes[ pos] == star && src_bytes[ pos-1 ] == slash {
68
68
self_. start = pos+1 ;
69
69
self_. pos = pos+1 ;
70
- self_. state = CommentBlock ;
70
+ self_. state = StateCommentBlock ;
71
71
self_. nesting_level = 0 ;
72
72
return Some ( ( start, pos-1 ) ) ;
73
73
}
74
74
75
75
if src_bytes[ pos] == dblquote {
76
76
self_. start = pos+1 ;
77
77
self_. pos = pos+1 ;
78
- self_. state = String ;
78
+ self_. state = StateString ;
79
79
return Some ( ( start, pos+1 ) ) ; // include the dblquote in the code
80
80
}
81
81
82
82
pos += 1 ;
83
83
}
84
- self_. state = Finished ;
84
+ self_. state = StateFinished ;
85
85
return Some ( ( start, end) ) ;
86
86
}
87
87
@@ -94,12 +94,12 @@ fn comment(self_: &mut CodeIndicesIter) -> Option<(uint,uint)> {
94
94
if src_bytes[ pos] == newline {
95
95
self_. start = pos+1 ;
96
96
self_. pos = pos+1 ;
97
- self_. state = Code ;
97
+ self_. state = StateCode ;
98
98
return code ( self_) ;
99
99
}
100
100
pos += 1 ;
101
101
}
102
- self_. state = Finished ;
102
+ self_. state = StateFinished ;
103
103
return Some ( ( start, end) ) ;
104
104
}
105
105
@@ -118,15 +118,15 @@ fn comment_block(self_: &mut CodeIndicesIter) -> Option<(uint,uint)> {
118
118
if self_. nesting_level == 0 {
119
119
self_. start = pos+1 ;
120
120
self_. pos = pos+1 ;
121
- self_. state = Code ;
121
+ self_. state = StateCode ;
122
122
return code ( self_) ;
123
123
} else {
124
124
self_. nesting_level -= 1 ;
125
125
}
126
126
}
127
127
pos += 1 ;
128
128
}
129
- self_. state = Finished ;
129
+ self_. state = StateFinished ;
130
130
return Some ( ( start, end) ) ;
131
131
}
132
132
@@ -152,18 +152,18 @@ fn string(self_: &mut CodeIndicesIter) -> Option<(uint,uint)> {
152
152
if src_bytes[ pos] == dblquote && !escaped ( src_bytes, pos) {
153
153
self_. start = pos; // include the dblquote as code
154
154
self_. pos = pos+1 ;
155
- self_. state = Code ;
155
+ self_. state = StateCode ;
156
156
return code ( self_) ;
157
157
}
158
158
pos += 1 ;
159
159
}
160
- self_. state = Finished ;
160
+ self_. state = StateFinished ;
161
161
return Some ( ( start, end) ) ;
162
162
}
163
163
164
164
/// Returns indices of chunks of code (minus comments and string contents)
165
165
pub fn code_chunks < ' a > ( src : & ' a str ) -> CodeIndicesIter < ' a > {
166
- CodeIndicesIter { src : src, start : 0 , pos : 0 , state : Code , nesting_level : 0 }
166
+ CodeIndicesIter { src : src, start : 0 , pos : 0 , state : StateCode , nesting_level : 0 }
167
167
}
168
168
169
169
#[ test]
0 commit comments