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-20 14:03:31 +00:00
pub delimiter_chars: &'static [u8],
2023-07-17 15:26:27 +00:00
/// 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-20 14:03:31 +00:00
pub initial_char_class: CharClass,
/// Whether to normalize latin script characters to ASCII
2023-07-17 15:26:27 +00:00
/// this significantly degrades performance so its not recommended
2023-07-20 14:03:31 +00:00
/// to be turned on by default
2023-07-17 15:26:27 +00:00
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 {
2023-07-20 14:03:31 +00:00
delimiter_chars: b"/,:;|",
bonus_boundary_white: BONUS_BOUNDARY + 2,
bonus_boundary_delimiter: BONUS_BOUNDARY + 1,
2023-07-20 14:03:31 +00:00
initial_char_class: CharClass::Whitespace,
2023-07-17 15:26:27 +00:00
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) {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/\\";
2023-07-17 15:26:27 +00:00
} else {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/";
2023-07-17 15:26:27 +00:00
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-20 14:03:31 +00:00
self.initial_char_class = CharClass::Delimiter;
2023-07-17 15:26:27 +00:00
}
pub const fn match_paths(mut self) -> Self {
if cfg!(windows) {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/\\";
2023-07-17 15:26:27 +00:00
} else {
2023-07-20 14:03:31 +00:00
self.delimiter_chars = b"/";
2023-07-17 15:26:27 +00:00
}
self.bonus_boundary_white = BONUS_BOUNDARY;
2023-07-20 14:03:31 +00:00
self.initial_char_class = CharClass::Delimiter;
2023-07-17 15:26:27 +00:00
self
}
}