@@ -663,43 +663,62 @@ fn extract_hyperlink(options: &clap::ArgMatches) -> bool {
663663/// # Returns
664664///
665665/// * An option with None if the style string is invalid, or a `QuotingStyle` wrapped in `Some`.
666+ struct QuotingStyleSpec {
667+ style : QuotingStyle ,
668+ fixed_control : bool ,
669+ locale : Option < LocaleQuoting > ,
670+ }
671+
672+ impl QuotingStyleSpec {
673+ fn new ( style : QuotingStyle ) -> Self {
674+ Self {
675+ style,
676+ fixed_control : false ,
677+ locale : None ,
678+ }
679+ }
680+
681+ fn with_locale ( style : QuotingStyle , locale : LocaleQuoting ) -> Self {
682+ Self {
683+ style,
684+ fixed_control : true ,
685+ locale : Some ( locale) ,
686+ }
687+ }
688+ }
689+
666690fn match_quoting_style_name (
667691 style : & str ,
668692 show_control : bool ,
669693) -> Option < ( QuotingStyle , Option < LocaleQuoting > ) > {
670- let ( qs, fixed_control, locale) = match style {
671- "literal" => (
672- QuotingStyle :: Literal {
673- show_control : false ,
674- } ,
675- false ,
676- None ,
677- ) ,
678- "shell" => ( QuotingStyle :: SHELL , false , None ) ,
679- "shell-always" => ( QuotingStyle :: SHELL_QUOTE , false , None ) ,
680- "shell-escape" => ( QuotingStyle :: SHELL_ESCAPE , false , None ) ,
681- "shell-escape-always" => ( QuotingStyle :: SHELL_ESCAPE_QUOTE , false , None ) ,
682- "c" => ( QuotingStyle :: C_DOUBLE , false , None ) ,
683- "escape" => ( QuotingStyle :: C_NO_QUOTES , false , None ) ,
684- "locale" => (
685- QuotingStyle :: Literal {
694+ let spec = match style {
695+ "literal" => QuotingStyleSpec :: new ( QuotingStyle :: Literal {
696+ show_control : false ,
697+ } ) ,
698+ "shell" => QuotingStyleSpec :: new ( QuotingStyle :: SHELL ) ,
699+ "shell-always" => QuotingStyleSpec :: new ( QuotingStyle :: SHELL_QUOTE ) ,
700+ "shell-escape" => QuotingStyleSpec :: new ( QuotingStyle :: SHELL_ESCAPE ) ,
701+ "shell-escape-always" => QuotingStyleSpec :: new ( QuotingStyle :: SHELL_ESCAPE_QUOTE ) ,
702+ "c" => QuotingStyleSpec :: new ( QuotingStyle :: C_DOUBLE ) ,
703+ "escape" => QuotingStyleSpec :: new ( QuotingStyle :: C_NO_QUOTES ) ,
704+ "locale" => QuotingStyleSpec {
705+ style : QuotingStyle :: Literal {
686706 show_control : false ,
687707 } ,
688- true ,
689- Some ( LocaleQuoting :: Single ) ,
690- ) ,
691- "clocale" => ( QuotingStyle :: C_DOUBLE , true , Some ( LocaleQuoting :: Double ) ) ,
708+ fixed_control : true ,
709+ locale : Some ( LocaleQuoting :: Single ) ,
710+ } ,
711+ "clocale" => QuotingStyleSpec :: with_locale ( QuotingStyle :: C_DOUBLE , LocaleQuoting :: Double ) ,
692712 _ => return None ,
693713 } ;
694714
695- Some ( (
696- if fixed_control {
697- qs
698- } else {
699- qs. show_control ( show_control)
700- } ,
701- locale,
702- ) )
715+ let style = if spec. fixed_control {
716+ spec. style
717+ } else {
718+ spec. style . show_control ( show_control)
719+ } ;
720+
721+ Some ( ( style, spec. locale ) )
703722}
704723
705724/// Extracts the quoting style to use based on the options provided.
0 commit comments