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