@@ -19,6 +19,9 @@ use thiserror::Error;
1919use uucore:: display:: Quotable ;
2020use uucore:: error:: { FromIo , UError , UResult , USimpleError , set_exit_code} ;
2121use uucore:: format_usage;
22+ use uucore:: i18n:: collator:: {
23+ AlternateHandling , CollatorOptions , locale_cmp, should_use_locale_collation, try_init_collator,
24+ } ;
2225use uucore:: line_ending:: LineEnding ;
2326use uucore:: translate;
2427
@@ -311,14 +314,16 @@ struct Input<Sep: Separator> {
311314 separator : Sep ,
312315 ignore_case : bool ,
313316 check_order : CheckOrder ,
317+ use_locale : bool ,
314318}
315319
316320impl < Sep : Separator > Input < Sep > {
317- fn new ( separator : Sep , ignore_case : bool , check_order : CheckOrder ) -> Self {
321+ fn new ( separator : Sep , ignore_case : bool , check_order : CheckOrder , use_locale : bool ) -> Self {
318322 Self {
319323 separator,
320324 ignore_case,
321325 check_order,
326+ use_locale,
322327 }
323328 }
324329
@@ -328,6 +333,8 @@ impl<Sep: Separator> Input<Sep> {
328333 let field1 = CaseInsensitiveSlice { v : field1 } ;
329334 let field2 = CaseInsensitiveSlice { v : field2 } ;
330335 field1. cmp ( & field2)
336+ } else if self . use_locale {
337+ locale_cmp ( field1, field2)
331338 } else {
332339 field1. cmp ( field2)
333340 }
@@ -823,6 +830,10 @@ fn parse_settings(matches: &clap::ArgMatches) -> UResult<Settings> {
823830pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
824831 let matches = uucore:: clap_localization:: handle_clap_result ( uu_app ( ) , args) ?;
825832
833+ let mut opts = CollatorOptions :: default ( ) ;
834+ opts. alternate_handling = Some ( AlternateHandling :: Shifted ) ;
835+ let _ = try_init_collator ( opts) ;
836+
826837 let settings = parse_settings ( & matches) ?;
827838
828839 let file1 = matches. get_one :: < OsString > ( "file1" ) . unwrap ( ) ;
@@ -989,7 +1000,12 @@ fn exec<Sep: Separator>(
9891000 settings. print_unpaired2 ,
9901001 ) ?;
9911002
992- let input = Input :: new ( sep. clone ( ) , settings. ignore_case , settings. check_order ) ;
1003+ let input = Input :: new (
1004+ sep. clone ( ) ,
1005+ settings. ignore_case ,
1006+ settings. check_order ,
1007+ should_use_locale_collation ( ) ,
1008+ ) ;
9931009
9941010 let format = if settings. autoformat {
9951011 let mut format = vec ! [ Spec :: Key ] ;
0 commit comments