File size: 571 Bytes
72c0672
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use pyo3::exceptions;
use pyo3::prelude::*;
use tk::utils::SysRegex;

/// Instantiate a new Regex with the given pattern
#[pyclass(module = "tokenizers", name = "Regex")]
pub struct PyRegex {
    pub inner: SysRegex,
    pub pattern: String,
}

#[pymethods]
impl PyRegex {
    #[new]
    #[pyo3(text_signature = "(self, pattern)")]
    fn new(s: &str) -> PyResult<Self> {
        Ok(Self {
            inner: SysRegex::new(s)
                .map_err(|e| exceptions::PyException::new_err(e.to_string().to_owned()))?,
            pattern: s.to_owned(),
        })
    }
}