@@ -135,6 +135,11 @@ cfg_langinfo! {
135135 }
136136 }
137137
138+ /// Distributes the given flag to all format specifiers in the string.
139+ ///
140+ /// For example, if the format string is "%a %b" and the flag is '^',
141+ /// the result will be "%^a %^b". Literal percent signs ("%%") are skipped
142+ /// and left as is.
138143 fn distribute_flag( fmt: & str , flag: char ) -> String {
139144 let mut res = String :: with_capacity( fmt. len( ) * 2 ) ;
140145 let mut chars = fmt. chars( ) . peekable( ) ;
@@ -367,4 +372,43 @@ mod tests {
367372 ) ;
368373 }
369374 }
375+
376+ #[ test]
377+ #[ cfg( any(
378+ target_os = "linux" ,
379+ target_vendor = "apple" ,
380+ target_os = "freebsd" ,
381+ target_os = "netbsd" ,
382+ target_os = "openbsd" ,
383+ target_os = "dragonfly"
384+ ) ) ]
385+ fn test_distribute_flag ( ) {
386+ // Standard distribution
387+ assert_eq ! ( distribute_flag( "%a %b" , '^' ) , "%^a %^b" ) ;
388+ // Ignore literals
389+ assert_eq ! ( distribute_flag( "foo %a bar" , '_' ) , "foo %_a bar" ) ;
390+ // Skip escaped percent signs
391+ assert_eq ! ( distribute_flag( "%% %a" , '^' ) , "%% %^a" ) ;
392+ // Handle flags that might already exist
393+ assert_eq ! ( distribute_flag( "%_a" , '^' ) , "%^_a" ) ;
394+ }
395+
396+ #[ test]
397+ #[ cfg( any(
398+ target_os = "linux" ,
399+ target_vendor = "apple" ,
400+ target_os = "freebsd" ,
401+ target_os = "netbsd" ,
402+ target_os = "openbsd" ,
403+ target_os = "dragonfly"
404+ ) ) ]
405+ fn test_expand_locale_format_basic ( ) {
406+ let format = "%^x" ;
407+ let expanded = expand_locale_format ( format) . to_string ( ) . to_lowercase ( ) ;
408+
409+ assert_ne ! ( expanded, "%^x" , "Should have expanded %^x" ) ;
410+ assert ! ( expanded. contains( "%^d" ) , "Should contain %^d" ) ;
411+ assert ! ( expanded. contains( "%^m" ) , "Should contain %^m" ) ;
412+ assert ! ( expanded. contains( "%^y" ) , "Should contain %^y" ) ;
413+ }
370414}
0 commit comments