@@ -13,7 +13,7 @@ mod word_count;
1313use std:: {
1414 borrow:: { Borrow , Cow } ,
1515 cmp:: max,
16- ffi:: OsString ,
16+ ffi:: { OsStr , OsString } ,
1717 fs:: { self , File } ,
1818 io:: { self , Write } ,
1919 iter,
@@ -28,7 +28,7 @@ use utf8::{BufReadDecoder, BufReadDecoderError};
2828use uucore:: {
2929 error:: { FromIo , UError , UResult } ,
3030 format_usage, help_about, help_usage,
31- quoting_style:: { escape_name , QuotingStyle } ,
31+ quoting_style:: { self , QuotingStyle } ,
3232 shortcut_value_parser:: ShortcutValueParser ,
3333 show,
3434} ;
@@ -259,7 +259,7 @@ impl<'a> Input<'a> {
259259 match self {
260260 Self :: Path ( path) => Some ( match path. to_str ( ) {
261261 Some ( s) if !s. contains ( '\n' ) => Cow :: Borrowed ( s) ,
262- _ => Cow :: Owned ( escape_name ( path. as_os_str ( ) , QS_ESCAPE ) ) ,
262+ _ => Cow :: Owned ( escape_name_wrapper ( path. as_os_str ( ) ) ) ,
263263 } ) ,
264264 Self :: Stdin ( StdinKind :: Explicit ) => Some ( Cow :: Borrowed ( STDIN_REPR ) ) ,
265265 Self :: Stdin ( StdinKind :: Implicit ) => None ,
@@ -269,7 +269,7 @@ impl<'a> Input<'a> {
269269 /// Converts input into the form that appears in errors.
270270 fn path_display ( & self ) -> String {
271271 match self {
272- Self :: Path ( path) => escape_name ( path. as_os_str ( ) , QS_ESCAPE ) ,
272+ Self :: Path ( path) => escape_name_wrapper ( path. as_os_str ( ) ) ,
273273 Self :: Stdin ( _) => String :: from ( "standard input" ) ,
274274 }
275275 }
@@ -361,7 +361,7 @@ impl WcError {
361361 Some ( ( input, idx) ) => {
362362 let path = match input {
363363 Input :: Stdin ( _) => STDIN_REPR . into ( ) ,
364- Input :: Path ( path) => escape_name ( path. as_os_str ( ) , QS_ESCAPE ) . into ( ) ,
364+ Input :: Path ( path) => escape_name_wrapper ( path. as_os_str ( ) ) . into ( ) ,
365365 } ;
366366 Self :: ZeroLengthFileNameCtx { path, idx }
367367 }
@@ -761,7 +761,9 @@ fn files0_iter_file<'a>(path: &Path) -> UResult<impl Iterator<Item = InputIterIt
761761 Err ( e) => Err ( e. map_err_context ( || {
762762 format ! (
763763 "cannot open {} for reading" ,
764- escape_name( path. as_os_str( ) , QS_QUOTE_ESCAPE )
764+ quoting_style:: escape_name( path. as_os_str( ) , QS_QUOTE_ESCAPE )
765+ . into_string( )
766+ . expect( "All escaped names with the escaping option return valid strings." )
765767 )
766768 } ) ) ,
767769 }
@@ -793,9 +795,9 @@ fn files0_iter<'a>(
793795 Ok ( Input :: Path ( PathBuf :: from ( s) . into ( ) ) )
794796 }
795797 }
796- Err ( e) => Err ( e. map_err_context ( || {
797- format ! ( "{}: read error" , escape_name ( & err_path, QS_ESCAPE ) )
798- } ) as Box < dyn UError > ) ,
798+ Err ( e) => Err ( e
799+ . map_err_context ( || format ! ( "{}: read error" , escape_name_wrapper ( & err_path) ) )
800+ as Box < dyn UError > ) ,
799801 } ) ,
800802 ) ;
801803 // Loop until there is an error; yield that error and then nothing else.
@@ -808,6 +810,12 @@ fn files0_iter<'a>(
808810 } )
809811}
810812
813+ fn escape_name_wrapper ( name : & OsStr ) -> String {
814+ quoting_style:: escape_name ( name, QS_ESCAPE )
815+ . into_string ( )
816+ . expect ( "All escaped names with the escaping option return valid strings." )
817+ }
818+
811819fn wc ( inputs : & Inputs , settings : & Settings ) -> UResult < ( ) > {
812820 let mut total_word_count = WordCount :: default ( ) ;
813821 let mut num_inputs: usize = 0 ;
0 commit comments