artichoke_backend/extn/core/regexp/
opts.rs

1//! Parse options parameter to `Regexp#initialize` and `Regexp::compile`.
2
3use super::Options;
4use crate::convert::implicitly_convert_to_int;
5use crate::extn::prelude::*;
6
7impl ConvertMut<Value, Options> for Artichoke {
8    fn convert_mut(&mut self, value: Value) -> Options {
9        // If options is an Integer, it should be one or more of the constants
10        // `Regexp::EXTENDED`, `Regexp::IGNORECASE`, and `Regexp::MULTILINE`,
11        // logically or-ed together. Otherwise, if options is not nil or false,
12        // the regexp will be case insensitive.
13        if let Ok(options) = implicitly_convert_to_int(self, value) {
14            Options::from(options)
15        } else if let Ok(options) = value.try_convert_into::<Option<bool>>(self) {
16            Options::from(options)
17        } else if let Ok(options) = value.try_convert_into_mut::<&[u8]>(self) {
18            Options::from(options)
19        } else {
20            Options::with_ignore_case()
21        }
22    }
23}