File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ use std::ffi::OsStr;
66use std:: fs;
77use std:: path:: { Path , PathBuf } ;
88use unindent:: unindent;
9+ use lazy_static:: lazy_static;
10+
11+
12+ lazy_static ! {
13+ static ref ENCODING_RE : Regex = Regex :: new( r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)" ) . unwrap( ) ;
14+ }
915
1016pub trait FileSystem : Send + Sync {
1117 fn sep ( & self ) -> String ;
@@ -81,13 +87,13 @@ impl FileSystem for RealBasicFileSystem {
8187 } ) ?;
8288
8389 let s = String :: from_utf8_lossy ( & bytes) ;
84- let encoding_re = Regex :: new ( r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)" ) . unwrap ( ) ;
90+
8591
8692 let mut detected_encoding: Option < String > = None ;
8793
8894 // Coding specification needs to be in the first two lines, or it's ignored.
8995 for line in s. lines ( ) . take ( 2 ) {
90- if let Some ( captures) = encoding_re . captures ( line)
96+ if let Some ( captures) = ENCODING_RE . captures ( line)
9197 && let Some ( encoding_name) = captures. get ( 1 ) {
9298 detected_encoding = Some ( encoding_name. as_str ( ) . to_string ( ) ) ;
9399 break ;
You can’t perform that action at this time.
0 commit comments