Skip to main content

perl_regex/validator/
mod.rs

1mod code_execution;
2mod complexity;
3mod config;
4mod group;
5mod nested_quantifier;
6
7pub use config::RegexValidationConfig;
8
9use crate::error::RegexError;
10
11pub struct RegexValidator {
12    config: RegexValidationConfig,
13}
14
15impl Default for RegexValidator {
16    fn default() -> Self {
17        Self::new()
18    }
19}
20
21impl RegexValidator {
22    pub fn new() -> Self {
23        Self { config: RegexValidationConfig::default() }
24    }
25
26    pub fn with_config(config: RegexValidationConfig) -> Self {
27        Self { config }
28    }
29
30    pub fn config(&self) -> &RegexValidationConfig {
31        &self.config
32    }
33
34    pub fn validate(&self, pattern: &str, start_pos: usize) -> Result<(), RegexError> {
35        complexity::check_complexity(pattern, start_pos, &self.config)
36    }
37
38    pub fn detects_code_execution(&self, pattern: &str) -> bool {
39        code_execution::detects_code_execution(pattern)
40    }
41
42    pub fn detect_nested_quantifiers(&self, pattern: &str) -> bool {
43        nested_quantifier::detect_nested_quantifiers(pattern)
44    }
45}