mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-16 18:48:54 +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 }))
|
.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 syntax_set = self.get_syntax_set()?;
|
||||||
|
let extension = e.and_then(|x| x.to_str()).unwrap_or_default();
|
||||||
Ok(syntax_set
|
Ok(syntax_set
|
||||||
.find_syntax_by_extension(extension)
|
.find_syntax_by_extension(extension)
|
||||||
.map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
|
.map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_extension_syntax(&self, file_name: &OsStr) -> Result<Option<SyntaxReferenceInSet>> {
|
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() {
|
if syntax.is_none() {
|
||||||
syntax = self.find_syntax_by_extension(
|
syntax = self.find_syntax_by_extension(Path::new(file_name).extension())?;
|
||||||
Path::new(file_name)
|
|
||||||
.extension()
|
|
||||||
.and_then(|x| x.to_str())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
if syntax.is_none() {
|
if syntax.is_none() {
|
||||||
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
|
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
|
||||||
|
Loading…
Reference in New Issue
Block a user