mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-28 09:18:53 +01:00
HighlightingAssets: Move common get_extension_syntax() code into find_syntax_by_extension()
This commit is contained in:
parent
974dec38e3
commit
0994f3783f
@ -250,22 +250,18 @@ impl HighlightingAssets {
|
||||
.map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
|
||||
}
|
||||
|
||||
fn find_syntax_by_extension(&self, extension: &str) -> Result<Option<SyntaxReferenceInSet>> {
|
||||
fn find_syntax_by_extension(&self, e: Option<&OsStr>) -> Result<Option<SyntaxReferenceInSet>> {
|
||||
let syntax_set = self.get_syntax_set()?;
|
||||
let extension = e.and_then(|x| x.to_str()).unwrap_or_default();
|
||||
Ok(syntax_set
|
||||
.find_syntax_by_extension(extension)
|
||||
.map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
|
||||
}
|
||||
|
||||
fn get_extension_syntax(&self, file_name: &OsStr) -> Result<Option<SyntaxReferenceInSet>> {
|
||||
let mut syntax = self.find_syntax_by_extension(file_name.to_str().unwrap_or_default())?;
|
||||
let mut syntax = self.find_syntax_by_extension(Some(file_name))?;
|
||||
if syntax.is_none() {
|
||||
syntax = self.find_syntax_by_extension(
|
||||
Path::new(file_name)
|
||||
.extension()
|
||||
.and_then(|x| x.to_str())
|
||||
.unwrap_or_default(),
|
||||
)?;
|
||||
syntax = self.find_syntax_by_extension(Path::new(file_name).extension())?;
|
||||
}
|
||||
if syntax.is_none() {
|
||||
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
|
||||
|
Loading…
Reference in New Issue
Block a user