Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 36433a9

Browse files
committed
fix Opcode::BIGCHARSET
1 parent db84f32 commit 36433a9

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

interp.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,16 @@ impl OpcodeDispatcher {
497497
}
498498
}),
499499
SreOpcode::IN => once(|drive| {
500-
general_op_in(drive, |x| x);
500+
general_op_in(drive, |set, c| charset(set, c));
501501
}),
502502
SreOpcode::IN_IGNORE => once(|drive| {
503-
general_op_in(drive, lower_ascii);
503+
general_op_in(drive, |set, c| charset(set, lower_ascii(c)));
504504
}),
505505
SreOpcode::IN_UNI_IGNORE => once(|drive| {
506-
general_op_in(drive, lower_unicode);
506+
general_op_in(drive, |set, c| charset(set, lower_unicode(c)));
507507
}),
508508
SreOpcode::IN_LOC_IGNORE => once(|drive| {
509-
let skip = drive.peek_code(1) as usize;
510-
if drive.at_end() || !charset_loc_ignore(&drive.pattern()[2..], drive.peek_char()) {
511-
drive.ctx_mut().has_matched = Some(false);
512-
} else {
513-
drive.skip_code(skip + 1);
514-
drive.skip_char(1);
515-
}
509+
general_op_in(drive, |set, c| charset_loc_ignore(set, c));
516510
}),
517511
SreOpcode::INFO | SreOpcode::JUMP => once(|drive| {
518512
drive.skip_code(drive.peek_code(1) as usize + 1);
@@ -661,9 +655,9 @@ fn general_op_literal<F: FnOnce(u32, char) -> bool>(drive: &mut StackDrive, f: F
661655
}
662656
}
663657

664-
fn general_op_in<F: FnOnce(char) -> char>(drive: &mut StackDrive, f: F) {
658+
fn general_op_in<F: FnOnce(&[u32], char) -> bool>(drive: &mut StackDrive, f: F) {
665659
let skip = drive.peek_code(1) as usize;
666-
if drive.at_end() || !charset(&drive.pattern()[2..], f(drive.peek_char())) {
660+
if drive.at_end() || !f(&drive.pattern()[2..], drive.peek_char()) {
667661
drive.ctx_mut().has_matched = Some(false);
668662
} else {
669663
drive.skip_code(skip + 1);
@@ -749,18 +743,20 @@ fn charset(set: &[u32], c: char) -> bool {
749743
}
750744
SreOpcode::BIGCHARSET => {
751745
/* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */
752-
let count = set[i + 1];
746+
let count = set[i + 1] as usize;
753747
if ch < 0x10000 {
754-
let (_, blockindices, _) = unsafe { set[i + 2..].align_to::<u8>() };
755-
let block = blockindices[(ch >> 8) as usize];
756-
if set[2 + 64 + ((block as u32 * 256 + (ch & 255)) / 32) as usize]
757-
& (1 << (ch & (32 - 1)))
748+
let set = &set[2..];
749+
let block_index = ch >> 8;
750+
let (_, blockindices, _) = unsafe { set.align_to::<u8>() };
751+
let blocks = &set[64..];
752+
let block = blockindices[block_index as usize];
753+
if blocks[((block as u32 * 256 + (ch & 255)) / 32) as usize] & (1u32 << (ch & 31))
758754
!= 0
759755
{
760756
return ok;
761757
}
762758
}
763-
i += 2 + 64 + count as usize * 8;
759+
i += 2 + 64 + count * 8;
764760
}
765761
SreOpcode::LITERAL => {
766762
/* <LITERAL> <code> */

0 commit comments

Comments
 (0)