@@ -205,30 +205,27 @@ enum PtxError {
205205
206206impl UError for PtxError { }
207207
208- fn get_config ( matches : & clap:: ArgMatches ) -> UResult < Config > {
208+ fn get_config ( matches : & mut clap:: ArgMatches ) -> UResult < Config > {
209209 let mut config = Config :: default ( ) ;
210210 let err_msg = "parsing options failed" ;
211211 if matches. get_flag ( options:: TRADITIONAL ) {
212212 config. gnu_ext = false ;
213213 config. format = OutFormat :: Roff ;
214214 "[^ \t \n ]+" . clone_into ( & mut config. context_regex ) ;
215215 }
216- if let Some ( regex) = matches. get_one :: < String > ( options:: SENTENCE_REGEXP ) {
217- config. sentence_regex = Some ( regex. clone ( ) ) ;
218-
216+ if let Some ( regex) = matches. remove_one :: < String > ( options:: SENTENCE_REGEXP ) {
219217 // TODO: The regex crate used here is not fully compatible with GNU's regex implementation.
220218 // For example, it does not support backreferences.
221219 // In the future, we might want to switch to the onig crate (like expr does) for better compatibility.
222220
223221 // Verify regex is valid and doesn't match empty string
224- if let Ok ( re) = Regex :: new ( regex) {
222+ if let Ok ( re) = Regex :: new ( & regex) {
225223 if re. is_match ( "" ) {
226- return Err ( USimpleError :: new (
227- 1 ,
228- "A regular expression cannot match a length zero string" ,
229- ) ) ;
224+ return Err ( USimpleError :: new ( 1 , translate ! ( "ptx-error-empty-regexp" ) ) ) ;
230225 }
231226 }
227+
228+ config. sentence_regex = Some ( regex) ;
232229 }
233230 config. auto_ref = matches. get_flag ( options:: AUTO_REFERENCE ) ;
234231 config. input_ref = matches. get_flag ( options:: REFERENCES ) ;
@@ -288,14 +285,16 @@ fn read_input(input_files: &[OsString], config: &Config) -> std::io::Result<File
288285 let mut file_map: FileMap = HashMap :: new ( ) ;
289286 let mut offset: usize = 0 ;
290287
291- let sentence_splitter =
292- if let Some ( re_str) = & config. sentence_regex {
293- Some ( Regex :: new ( re_str) . map_err ( |_| {
294- std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid regex" )
295- } ) ?)
296- } else {
297- None
298- } ;
288+ let sentence_splitter = if let Some ( re_str) = & config. sentence_regex {
289+ Some ( Regex :: new ( re_str) . map_err ( |e| {
290+ std:: io:: Error :: new (
291+ std:: io:: ErrorKind :: InvalidInput ,
292+ translate ! ( "ptx-error-invalid-regexp" , "error" => e) ,
293+ )
294+ } ) ?)
295+ } else {
296+ None
297+ } ;
299298
300299 for filename in input_files {
301300 let mut reader: BufReader < Box < dyn Read > > = BufReader :: new ( if filename == "-" {
@@ -878,8 +877,8 @@ mod options {
878877
879878#[ uucore:: main]
880879pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
881- let matches = uucore:: clap_localization:: handle_clap_result ( uu_app ( ) , args) ?;
882- let mut config = get_config ( & matches) ?;
880+ let mut matches = uucore:: clap_localization:: handle_clap_result ( uu_app ( ) , args) ?;
881+ let mut config = get_config ( & mut matches) ?;
883882
884883 let input_files;
885884 let output_file: OsString ;
0 commit comments