@@ -5,6 +5,9 @@ use num_bigint::{BigInt, Sign};
5
5
use num_traits:: { cast:: ToPrimitive , Signed } ;
6
6
use std:: { cmp, str:: FromStr } ;
7
7
8
+ pub struct Locale ;
9
+ pub type LocaleFunc = fn ( ) -> Locale ;
10
+
8
11
trait FormatParse {
9
12
fn parse ( text : & str ) -> ( Option < Self > , & str )
10
13
where
@@ -312,6 +315,7 @@ impl FormatSpec {
312
315
inter : i32 ,
313
316
sep : char ,
314
317
disp_digit_cnt : i32 ,
318
+ locale_info : Option < LocaleFunc > , // will be used to calculate numbers here
315
319
) -> String {
316
320
// Don't add separators to the floating decimal point of numbers
317
321
let mut parts = magnitude_str. splitn ( 2 , '.' ) ;
@@ -391,7 +395,12 @@ impl FormatSpec {
391
395
}
392
396
}
393
397
394
- fn add_magnitude_separators ( & self , magnitude_str : String , prefix : & str ) -> String {
398
+ fn add_magnitude_separators (
399
+ & self ,
400
+ magnitude_str : String ,
401
+ prefix : & str ,
402
+ locale_info : Option < LocaleFunc > ,
403
+ ) -> String {
395
404
match & self . grouping_option {
396
405
Some ( fg) => {
397
406
let sep = match fg {
@@ -407,6 +416,7 @@ impl FormatSpec {
407
416
inter,
408
417
sep,
409
418
disp_digit_cnt,
419
+ locale_info,
410
420
)
411
421
}
412
422
None => magnitude_str,
@@ -487,7 +497,7 @@ impl FormatSpec {
487
497
FormatSign :: MinusOrSpace => " " ,
488
498
}
489
499
} ;
490
- let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str?, sign_str) ;
500
+ let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str?, sign_str, None ) ;
491
501
self . format_sign_and_align (
492
502
unsafe { & BorrowedStr :: from_ascii_unchecked ( magnitude_str. as_bytes ( ) ) } ,
493
503
sign_str,
@@ -503,7 +513,11 @@ impl FormatSpec {
503
513
}
504
514
}
505
515
506
- pub fn format_int ( & self , num : & BigInt ) -> Result < String , FormatSpecError > {
516
+ pub fn format_int (
517
+ & self ,
518
+ num : & BigInt ,
519
+ locale_info : Option < LocaleFunc > ,
520
+ ) -> Result < String , FormatSpecError > {
507
521
self . validate_format ( FormatType :: Decimal ) ?;
508
522
let magnitude = num. abs ( ) ;
509
523
let prefix = if self . alternate_form {
@@ -559,7 +573,8 @@ impl FormatSpec {
559
573
} ,
560
574
} ;
561
575
let sign_prefix = format ! ( "{sign_str}{prefix}" ) ;
562
- let magnitude_str = self . add_magnitude_separators ( raw_magnitude_str, & sign_prefix) ;
576
+ let magnitude_str =
577
+ self . add_magnitude_separators ( raw_magnitude_str, & sign_prefix, locale_info) ;
563
578
self . format_sign_and_align (
564
579
& BorrowedStr :: from_bytes ( magnitude_str. as_bytes ( ) ) ,
565
580
& sign_prefix,
0 commit comments