nucleo/src/config.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

2023-07-20 00:09:51 +00:00
use crate::chars::CharClass;
use crate::score::BONUS_BOUNDARY;
2023-07-17 15:26:27 +00:00
2023-07-20 00:09:51 +00:00
#[non_exhaustive]
pub struct MatcherConfig {
2023-07-17 15:26:27 +00:00
pub delimeter_chars: &'static [u8],
/// Extra bonus for word boundary after whitespace character or beginning of the string
pub bonus_boundary_white: u16,
2023-07-17 15:26:27 +00:00
// Extra bonus for word boundary after slash, colon, semi-colon, and comma
pub bonus_boundary_delimiter: u16,
2023-07-17 15:26:27 +00:00
pub inital_char_class: CharClass,
/// Whether to normalize latin script charaters to ASCII
/// this significantly degrades performance so its not recommended
/// to be truned on by default
pub normalize: bool,
2023-07-20 00:09:51 +00:00
/// whether to ignore casing
pub ignore_case: bool,
2023-07-17 15:26:27 +00:00
}
2023-07-20 00:09:51 +00:00
// #[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Copy, Clone, Hash)]
// #[non_exhaustive]
// pub enum CaseMatching {
// Respect,
// Ignore,
// Smart,
// }
2023-07-17 15:26:27 +00:00
impl MatcherConfig {
pub const DEFAULT: Self = {
MatcherConfig {
delimeter_chars: b"/,:;|",
bonus_boundary_white: BONUS_BOUNDARY + 2,
bonus_boundary_delimiter: BONUS_BOUNDARY + 1,
2023-07-17 15:26:27 +00:00
inital_char_class: CharClass::Whitespace,
normalize: false,
2023-07-20 00:09:51 +00:00
ignore_case: true,
2023-07-17 15:26:27 +00:00
}
};
}
impl MatcherConfig {
pub fn set_match_paths(&mut self) {
if cfg!(windows) {
self.delimeter_chars = b"/\\";
} else {
self.delimeter_chars = b"/";
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-17 15:26:27 +00:00
self.inital_char_class = CharClass::Delimiter;
}
pub const fn match_paths(mut self) -> Self {
if cfg!(windows) {
self.delimeter_chars = b"/\\";
} else {
self.delimeter_chars = b"/";
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-17 15:26:27 +00:00
self.inital_char_class = CharClass::Delimiter;
self
}
}