Skip to main content

luaur_vm/functions/
matchbracketclass.rs

1use crate::functions::match_class::match_class;
2use crate::macros::l_esc::L_ESC;
3use crate::macros::uchar::uchar;
4
5pub fn matchbracketclass(
6    c: i32,
7    mut p: *const core::ffi::c_char,
8    ec: *const core::ffi::c_char,
9) -> i32 {
10    let mut sig: i32 = 1;
11
12    unsafe {
13        if *p.add(1) == b'^' as core::ffi::c_char {
14            sig = 0;
15            p = p.add(1); // skip the `^'
16        }
17
18        while p.add(1) < ec {
19            p = p.add(1);
20
21            if *p == L_ESC {
22                p = p.add(1);
23                if match_class(c, uchar(*p as i32) as i32) != 0 {
24                    return sig;
25                }
26            } else if *p.add(1) == b'-' as core::ffi::c_char && p.add(2) < ec {
27                p = p.add(2);
28                if (uchar(*(p.offset(-2)) as i32) as i32) <= c && c <= (uchar(*p as i32) as i32) {
29                    return sig;
30                }
31            } else if (uchar(*p as i32) as i32) == c {
32                return sig;
33            }
34        }
35
36        if sig == 0 {
37            1
38        } else {
39            0
40        }
41    }
42}