8
8
mod operation;
9
9
mod unicode_table;
10
10
11
- use clap:: { crate_version, Arg , ArgAction , Command } ;
11
+ use clap:: { crate_version, value_parser , Arg , ArgAction , Command } ;
12
12
use operation:: {
13
13
translate_input, Sequence , SqueezeOperation , SymbolTranslator , TranslateOperation ,
14
14
} ;
15
+ use std:: ffi:: OsString ;
15
16
use std:: io:: { stdin, stdout, BufWriter } ;
16
- use uucore:: { format_usage, help_about, help_section, help_usage, show} ;
17
+ use uucore:: { format_usage, help_about, help_section, help_usage, os_str_as_bytes , show} ;
17
18
18
19
use crate :: operation:: DeleteOperation ;
19
20
use uucore:: display:: Quotable ;
@@ -43,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
43
44
// Ultimately this should be OsString, but we might want to wait for the
44
45
// pattern API on OsStr
45
46
let sets: Vec < _ > = matches
46
- . get_many :: < String > ( options:: SETS )
47
+ . get_many :: < OsString > ( options:: SETS )
47
48
. into_iter ( )
48
49
. flatten ( )
49
50
. map ( ToOwned :: to_owned)
@@ -97,7 +98,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
97
98
}
98
99
99
100
if let Some ( first) = sets. first ( ) {
100
- if first . ends_with ( '\\' ) {
101
+ if let Some ( b '\\') = os_str_as_bytes ( first ) ? . last ( ) {
101
102
show ! ( USimpleError :: new(
102
103
0 ,
103
104
"warning: an unescaped backslash at end of string is not portable"
@@ -113,10 +114,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
113
114
114
115
// According to the man page: translating only happens if deleting or if a second set is given
115
116
let translating = !delete_flag && sets. len ( ) > 1 ;
116
- let mut sets_iter = sets. iter ( ) . map ( |c| c. as_str ( ) ) ;
117
+ let mut sets_iter = sets. iter ( ) . map ( |c| c. as_os_str ( ) ) ;
117
118
let ( set1, set2) = Sequence :: solve_set_characters (
118
- sets_iter. next ( ) . unwrap_or_default ( ) . as_bytes ( ) ,
119
- sets_iter. next ( ) . unwrap_or_default ( ) . as_bytes ( ) ,
119
+ os_str_as_bytes ( sets_iter. next ( ) . unwrap_or_default ( ) ) ? ,
120
+ os_str_as_bytes ( sets_iter. next ( ) . unwrap_or_default ( ) ) ? ,
120
121
complement_flag,
121
122
// if we are not translating then we don't truncate set1
122
123
truncate_set1_flag && translating,
@@ -195,5 +196,9 @@ pub fn uu_app() -> Command {
195
196
. action ( ArgAction :: SetTrue )
196
197
. overrides_with ( options:: TRUNCATE_SET1 ) ,
197
198
)
198
- . arg ( Arg :: new ( options:: SETS ) . num_args ( 1 ..) )
199
+ . arg (
200
+ Arg :: new ( options:: SETS )
201
+ . num_args ( 1 ..)
202
+ . value_parser ( value_parser ! ( OsString ) ) ,
203
+ )
199
204
}
0 commit comments