Skip to content

Commit 454aa4b

Browse files
committed
fix count not advance
1 parent 169368b commit 454aa4b

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎src/engine.rs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// good luck to those that follow; here be dragons
22

3-
use super::constants::{SreAtCode, SreCatCode, SreOpcode, SreInfo};
3+
use super::constants::{SreAtCode, SreCatCode, SreInfo, SreOpcode};
44
use super::MAXREPEAT;
55
use optional::Optioned;
66
use std::convert::TryFrom;
@@ -1418,31 +1418,31 @@ fn _count<S: StrDrive>(
14181418
general_count_literal(req, &mut ctx, end, |code, c| !char_loc_ignore(code, c));
14191419
}
14201420
SreOpcode::LITERAL_UNI_IGNORE => {
1421-
general_count_literal(req, &mut ctx, end, |code, c| {
1422-
code == lower_unicode(c)
1423-
});
1421+
general_count_literal(req, &mut ctx, end, |code, c| code == lower_unicode(c));
14241422
}
14251423
SreOpcode::NOT_LITERAL_UNI_IGNORE => {
1426-
general_count_literal(req, &mut ctx, end, |code, c| {
1427-
code != lower_unicode(c)
1428-
});
1424+
general_count_literal(req, &mut ctx, end, |code, c| code != lower_unicode(c));
14291425
}
14301426
_ => {
14311427
/* General case */
14321428
let mut count = 0;
14331429

1430+
let mut sub_ctx = MatchContext {
1431+
toplevel: false,
1432+
jump: Jump::OpCode,
1433+
repeat_ctx_id: usize::MAX,
1434+
count: -1,
1435+
..ctx
1436+
};
1437+
14341438
while count < max_count {
1435-
let sub_ctx = MatchContext {
1436-
toplevel: false,
1437-
jump: Jump::OpCode,
1438-
repeat_ctx_id: usize::MAX,
1439-
count: -1,
1440-
..ctx
1441-
};
14421439
if !_match(req, state, sub_ctx) {
14431440
break;
14441441
}
14451442
count += 1;
1443+
sub_ctx.skip_char(req, 1);
1444+
// ctx.string_position = state.string_position;
1445+
// ctx.string_offset = req.string.offset(0, state.string_position);
14461446
}
14471447
return count;
14481448
}

‎tests/tests.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,15 @@ fn test_bug_20998() {
162162
req.match_all = true;
163163
assert!(state.pymatch(&req));
164164
assert_eq!(state.string_position, 3);
165-
}
165+
}
166+
167+
#[test]
168+
fn test_bigcharset() {
169+
// pattern p = re.compile('[a-z]*', re.I)
170+
// START GENERATED by generate_tests.py
171+
#[rustfmt::skip] let p = Pattern { code: &[14, 4, 0, 0, 4294967295, 24, 97, 0, 4294967295, 39, 92, 10, 3, 33685760, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 33686018, 0, 0, 0, 134217726, 0, 0, 0, 0, 0, 131072, 0, 2147483648, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] };
172+
// END GENERATED
173+
let (req, mut state) = p.state("x ");
174+
assert!(state.pymatch(&req));
175+
assert_eq!(state.string_position, 1);
176+
}

0 commit comments

Comments
 (0)