Skip to content

Commit 340d856

Browse files
committed
Bump to 0.1.9
1 parent fa8b760 commit 340d856

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ license = "MIT"
55
repository = "https://github.com/conduit-rust/route-recognizer.rs"
66
keywords = ["router", "url"]
77

8-
version = "0.1.8"
8+
version = "0.1.9"
99
authors = ["wycats"]

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub mod nfa;
1010

1111
#[derive(Clone)]
1212
struct Metadata {
13-
statics: int,
14-
dynamics: int,
15-
stars: int,
13+
statics: u32,
14+
dynamics: u32,
15+
stars: u32,
1616
param_names: Vec<String>,
1717
}
1818

@@ -99,7 +99,7 @@ impl<T> Match<T> {
9999
#[derive(Clone)]
100100
pub struct Router<T> {
101101
nfa: NFA<Metadata>,
102-
handlers: BTreeMap<uint, T>
102+
handlers: BTreeMap<usize, T>
103103
}
104104

105105
impl<T> Router<T> {
@@ -165,15 +165,15 @@ impl<T> Router<T> {
165165
}
166166
}
167167

168-
fn process_static_segment<T>(segment: &str, nfa: &mut NFA<T>, mut state: uint) -> uint {
168+
fn process_static_segment<T>(segment: &str, nfa: &mut NFA<T>, mut state: usize) -> usize {
169169
for char in segment.chars() {
170170
state = nfa.put(state, CharacterClass::valid_char(char));
171171
}
172172

173173
state
174174
}
175175

176-
fn process_dynamic_segment<T>(nfa: &mut NFA<T>, mut state: uint) -> uint {
176+
fn process_dynamic_segment<T>(nfa: &mut NFA<T>, mut state: usize) -> usize {
177177
state = nfa.put(state, CharacterClass::invalid_char('/'));
178178
nfa.put_state(state, state);
179179
nfa.start_capture(state);
@@ -182,7 +182,7 @@ fn process_dynamic_segment<T>(nfa: &mut NFA<T>, mut state: uint) -> uint {
182182
state
183183
}
184184

185-
fn process_star_state<T>(nfa: &mut NFA<T>, mut state: uint) -> uint {
185+
fn process_star_state<T>(nfa: &mut NFA<T>, mut state: usize) -> usize {
186186
state = nfa.put(state, CharacterClass::any());
187187
nfa.put_state(state, state);
188188
nfa.start_capture(state);
@@ -208,21 +208,21 @@ fn basic_router() {
208208
#[test]
209209
fn root_router() {
210210
let mut router = Router::new();
211-
router.add("/", 10i);
211+
router.add("/", 10);
212212
assert_eq!(*router.recognize("/").unwrap().handler, 10)
213213
}
214214

215215
#[test]
216216
fn empty_path() {
217217
let mut router = Router::new();
218-
router.add("/", 12i);
218+
router.add("/", 12);
219219
assert_eq!(*router.recognize("").unwrap().handler, 12)
220220
}
221221

222222
#[test]
223223
fn empty_route() {
224224
let mut router = Router::new();
225-
router.add("", 12i);
225+
router.add("", 12);
226226
assert_eq!(*router.recognize("/").unwrap().handler, 12)
227227
}
228228

src/nfa.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl CharSet {
1818
}
1919

2020
pub fn insert(&mut self, char: char) {
21-
let val = char as uint - 1;
21+
let val = char as u32 - 1;
2222

2323
if val > 127 {
2424
self.non_ascii.insert(char);
@@ -32,7 +32,7 @@ impl CharSet {
3232
}
3333

3434
pub fn contains(&self, char: char) -> bool {
35-
let val = char as uint - 1;
35+
let val = char as u32 - 1;
3636

3737
if val > 127 {
3838
self.non_ascii.contains(&char)
@@ -67,7 +67,7 @@ impl CharacterClass {
6767
}
6868

6969
pub fn valid_char(char: char) -> CharacterClass {
70-
let val = char as uint - 1;
70+
let val = char as u32 - 1;
7171

7272
if val > 127 {
7373
ValidChars(CharacterClass::char_to_set(char))
@@ -79,7 +79,7 @@ impl CharacterClass {
7979
}
8080

8181
pub fn invalid_char(char: char) -> CharacterClass {
82-
let val = char as uint - 1;
82+
let val = char as u32 - 1;
8383

8484
if val > 127 {
8585
InvalidChars(CharacterClass::char_to_set(char))
@@ -96,7 +96,7 @@ impl CharacterClass {
9696
ValidChars(ref valid) => valid.contains(char),
9797
InvalidChars(ref invalid) => !invalid.contains(char),
9898
Ascii(high, low, unicode) => {
99-
let val = char as uint - 1;
99+
let val = char as u32 - 1;
100100
if val > 127 {
101101
unicode
102102
} else if val > 63 {
@@ -125,9 +125,9 @@ impl CharacterClass {
125125

126126
#[derive(Clone)]
127127
struct Thread {
128-
state: uint,
129-
captures: Vec<(uint, uint)>,
130-
capture_begin: Option<uint>
128+
state: usize,
129+
captures: Vec<(usize, usize)>,
130+
capture_begin: Option<usize>
131131
}
132132

133133
impl Thread {
@@ -136,12 +136,12 @@ impl Thread {
136136
}
137137

138138
#[inline]
139-
pub fn start_capture(&mut self, start: uint) {
139+
pub fn start_capture(&mut self, start: usize) {
140140
self.capture_begin = Some(start);
141141
}
142142

143143
#[inline]
144-
pub fn end_capture(&mut self, end: uint) {
144+
pub fn end_capture(&mut self, end: usize) {
145145
self.captures.push((self.capture_begin.unwrap(), end));
146146
self.capture_begin = None;
147147
}
@@ -153,9 +153,9 @@ impl Thread {
153153

154154
#[derive(Clone)]
155155
pub struct State<T> {
156-
pub index: uint,
156+
pub index: usize,
157157
pub chars: CharacterClass,
158-
pub next_states: Vec<uint>,
158+
pub next_states: Vec<usize>,
159159
pub acceptance: bool,
160160
pub start_capture: bool,
161161
pub end_capture: bool,
@@ -169,7 +169,7 @@ impl<T> PartialEq for State<T> {
169169
}
170170

171171
impl<T> State<T> {
172-
pub fn new(index: uint, chars: CharacterClass) -> State<T> {
172+
pub fn new(index: usize, chars: CharacterClass) -> State<T> {
173173
State {
174174
index: index,
175175
chars: chars,
@@ -183,12 +183,12 @@ impl<T> State<T> {
183183
}
184184

185185
pub struct Match<'a> {
186-
pub state: uint,
186+
pub state: usize,
187187
pub captures: Vec<&'a str>,
188188
}
189189

190190
impl<'a> Match<'a> {
191-
pub fn new<'b>(state: uint, captures: Vec<&'b str>) -> Match<'b> {
191+
pub fn new<'b>(state: usize, captures: Vec<&'b str>) -> Match<'b> {
192192
Match{ state: state, captures: captures }
193193
}
194194
}
@@ -214,7 +214,7 @@ impl<T> NFA<T> {
214214

215215
pub fn process<'a, I, F>(&self, string: &'a str, mut ord: F)
216216
-> Result<Match<'a>, String>
217-
where I: Ord, F: FnMut(uint) -> I
217+
where I: Ord, F: FnMut(usize) -> I
218218
{
219219
let mut threads = vec![Thread::new()];
220220

@@ -249,13 +249,13 @@ impl<T> NFA<T> {
249249

250250
#[inline]
251251
fn process_char<'a>(&self, threads: Vec<Thread>,
252-
char: char, pos: uint) -> Vec<Thread> {
252+
char: char, pos: usize) -> Vec<Thread> {
253253
let mut returned = Vec::with_capacity(threads.len());
254254

255255
for mut thread in threads.into_iter() {
256256
let current_state = self.get(thread.state);
257257

258-
let mut count = 0i;
258+
let mut count = 0;
259259
let mut found_state = 0;
260260

261261
for &index in current_state.next_states.iter() {
@@ -289,15 +289,15 @@ impl<T> NFA<T> {
289289
}
290290

291291
#[inline]
292-
pub fn get<'a>(&'a self, state: uint) -> &'a State<T> {
292+
pub fn get<'a>(&'a self, state: usize) -> &'a State<T> {
293293
&self.states[state]
294294
}
295295

296-
pub fn get_mut<'a>(&'a mut self, state: uint) -> &'a mut State<T> {
296+
pub fn get_mut<'a>(&'a mut self, state: usize) -> &'a mut State<T> {
297297
&mut self.states[state]
298298
}
299299

300-
pub fn put(&mut self, index: uint, chars: CharacterClass) -> uint {
300+
pub fn put(&mut self, index: usize, chars: CharacterClass) -> usize {
301301
{
302302
let state = self.get(index);
303303

@@ -314,32 +314,32 @@ impl<T> NFA<T> {
314314
state
315315
}
316316

317-
pub fn put_state(&mut self, index: uint, child: uint) {
317+
pub fn put_state(&mut self, index: usize, child: usize) {
318318
if !self.states[index].next_states.contains(&child) {
319319
self.get_mut(index).next_states.push(child);
320320
}
321321
}
322322

323-
pub fn acceptance(&mut self, index: uint) {
323+
pub fn acceptance(&mut self, index: usize) {
324324
self.get_mut(index).acceptance = true;
325325
self.acceptance[index] = true;
326326
}
327327

328-
pub fn start_capture(&mut self, index: uint) {
328+
pub fn start_capture(&mut self, index: usize) {
329329
self.get_mut(index).start_capture = true;
330330
self.start_capture[index] = true;
331331
}
332332

333-
pub fn end_capture(&mut self, index: uint) {
333+
pub fn end_capture(&mut self, index: usize) {
334334
self.get_mut(index).end_capture = true;
335335
self.end_capture[index] = true;
336336
}
337337

338-
pub fn metadata(&mut self, index: uint, metadata: T) {
338+
pub fn metadata(&mut self, index: usize, metadata: T) {
339339
self.get_mut(index).metadata = Some(metadata);
340340
}
341341

342-
fn new_state(&mut self, chars: CharacterClass) -> uint {
342+
fn new_state(&mut self, chars: CharacterClass) -> usize {
343343
let index = self.states.len();
344344
let state = State::new(index, chars);
345345
self.states.push(state);
@@ -360,7 +360,8 @@ fn fork_thread<T>(thread: &Thread, state: &State<T>) -> Thread {
360360
}
361361

362362
#[inline]
363-
fn capture<T>(nfa: &NFA<T>, thread: &mut Thread, current_state: uint, next_state: uint, pos: uint) {
363+
fn capture<T>(nfa: &NFA<T>, thread: &mut Thread, current_state: usize,
364+
next_state: usize, pos: usize) {
364365
if thread.capture_begin == None && nfa.start_capture[next_state] {
365366
thread.start_capture(pos);
366367
}

0 commit comments

Comments
 (0)