1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// Checks if string starts with any of the `&str`s
#[macro_export]
macro_rules! match_start {
    ($to_check:expr, $( $( $start:literal)|* => $to_return:expr )* ) => {
        if false {None} // This is here to use else if later
        $(
            else if match_start!(@INTERNAL $to_check, $($start),*) {
                Some($to_return)
            }
        )*
        else {None}
    };

    (@INTERNAL $to_check:expr, $($start:literal),*) => {
        $(
            $to_check.starts_with($start)
        )||*
    }
}

/// Checks if string ends with any of the `&str`s
#[macro_export]
macro_rules! match_end {
    ($to_check:expr, $( $( $end:literal)|* => $to_return:expr )* ) => {
        if false {None} // This is here to use else if later
        $(
            else if match_end!(@INTERNAL $to_check, $($end),*) {
                Some($to_return)
            }
        )*
        else {None}
    };

    (@INTERNAL $to_check:expr, $($start:literal),*) => {
        $(
            $to_check.ends_with($start)
        )||*
    }
}