1use crate::match_validation::match_status::MatchStatus;
2use crate::{encoding::Encoding, path::Path, StringMatch};
3use std::fmt::Debug;
4use std::fmt::{Display, Formatter};
5
6#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
8pub struct RuleMatch {
9 pub rule_index: usize,
12
13 pub path: Path<'static>,
15
16 pub replacement_type: ReplacementType,
18
19 pub start_index: usize,
22
23 pub end_index_exclusive: usize,
27
28 pub shift_offset: isize,
32
33 pub match_value: Option<String>,
35
36 pub match_status: MatchStatus,
38}
39
40pub struct InternalRuleMatch<E: Encoding> {
41 pub rule_index: usize,
43
44 pub utf8_start: usize,
46
47 pub utf8_end: usize,
49
50 pub custom_start: <E as Encoding>::Index,
52
53 pub custom_end: <E as Encoding>::Index,
55}
56
57impl<E: Encoding> InternalRuleMatch<E> {
58 pub fn new(rule_index: usize, string_match: StringMatch) -> Self {
59 Self {
60 rule_index,
61 utf8_start: string_match.start,
62 utf8_end: string_match.end,
63 custom_start: E::zero_index(),
64 custom_end: E::zero_index(),
65 }
66 }
67
68 pub fn len(&self) -> usize {
69 self.utf8_end - self.utf8_start
70 }
71}
72
73#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
74pub enum ReplacementType {
75 None,
76 Placeholder,
77 Hash,
78 PartialStart,
79 PartialEnd,
80}
81
82impl Display for ReplacementType {
83 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
84 match self {
85 ReplacementType::None => write!(f, "none"),
86 ReplacementType::Placeholder => write!(f, "placeholder"),
87 ReplacementType::Hash => write!(f, "hash"),
88 ReplacementType::PartialStart => write!(f, "partial_beginning"),
89 ReplacementType::PartialEnd => write!(f, "partial_end"),
90 }
91 }
92}