diff --git a/src/lib.rs b/src/lib.rs index b082dea..649f703 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,14 +107,13 @@ fn raw_to_parse_error(map: &CodeMap, err: Error, unicode: bool) -> Box { Box::new(Error::from_loc(message, map.look_up_span(span), unicode)) } -fn from_string_with_file_name(input: String, file_name: &str, options: &Options) -> Result { +fn from_string_with_file_name>(input: String, file_name: P, options: &Options) -> Result { let mut map = CodeMap::new(); - let file = map.add_file(file_name.to_owned(), input); + let path = file_name.as_ref(); + let file = map.add_file(path.to_string_lossy().into_owned(), input); let empty_span = file.span.subspan(0, 0); let lexer = Lexer::new_from_file(&file); - let path = Path::new(file_name); - let input_syntax = options .input_syntax .unwrap_or_else(|| InputSyntax::for_path(path)); @@ -178,9 +177,9 @@ fn from_string_with_file_name(input: String, file_name: &str, options: &Options) /// ``` #[inline] -pub fn from_path(p: &str, options: &Options) -> Result { +pub fn from_path>(p: P, options: &Options) -> Result { from_string_with_file_name( - String::from_utf8(options.fs.read(Path::new(p))?)?, + String::from_utf8(options.fs.read(p.as_ref())?)?, p, options, ) diff --git a/src/options.rs b/src/options.rs index d891acb..cdfe0a3 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,4 +1,4 @@ -use std::path::Path; +use std::path::{Path, PathBuf}; use crate::{Fs, StdFs}; @@ -11,7 +11,7 @@ use crate::{Fs, StdFs}; pub struct Options<'a> { pub(crate) fs: &'a dyn Fs, pub(crate) style: OutputStyle, - pub(crate) load_paths: Vec<&'a Path>, + pub(crate) load_paths: Vec, pub(crate) allows_charset: bool, pub(crate) unicode_error_messages: bool, pub(crate) quiet: bool, @@ -88,8 +88,8 @@ impl<'a> Options<'a> { /// This method will append a single path to the list. #[must_use] #[inline] - pub fn load_path(mut self, path: &'a Path) -> Self { - self.load_paths.push(path); + pub fn load_path>(mut self, path: P) -> Self { + self.load_paths.push(path.as_ref().to_owned()); self } @@ -101,8 +101,11 @@ impl<'a> Options<'a> { /// load paths #[must_use] #[inline] - pub fn load_paths(mut self, paths: &'a [&'a Path]) -> Self { - self.load_paths.extend_from_slice(paths); + pub fn load_paths>(mut self, paths: &[P]) -> Self { + for path in paths { + self.load_paths.push(path.as_ref().to_owned()); + } + self } diff --git a/tests/important.rs b/tests/important.rs index a92aa2c..12a923b 100644 --- a/tests/important.rs +++ b/tests/important.rs @@ -31,5 +31,13 @@ test!( "a {\n color: ! important;\n}\n", "a {\n color: !important;\n}\n" ); - -// todo: loud comment between !<>i, silent comment between !<>i +test!( + loud_comment_after_exclamation, + "a {\n color: !/**/important;\n}\n", + "a {\n color: !important;\n}\n" +); +test!( + silent_comment_after_exclamation, + "a {\n color: !//\nimportant;\n}\n", + "a {\n color: !important;\n}\n" +);