@@ -126,7 +126,7 @@ pub enum FormatType {
126
126
Character ,
127
127
Decimal ,
128
128
Octal ,
129
- Number ,
129
+ Number ( Case ) ,
130
130
Hex ( Case ) ,
131
131
Exponent ( Case ) ,
132
132
GeneralFormat ( Case ) ,
@@ -142,7 +142,8 @@ impl From<&FormatType> for char {
142
142
FormatType :: Character => 'c' ,
143
143
FormatType :: Decimal => 'd' ,
144
144
FormatType :: Octal => 'o' ,
145
- FormatType :: Number => 'n' ,
145
+ FormatType :: Number ( Case :: Lower ) => 'n' ,
146
+ FormatType :: Number ( Case :: Upper ) => 'N' ,
146
147
FormatType :: Hex ( Case :: Lower ) => 'x' ,
147
148
FormatType :: Hex ( Case :: Upper ) => 'X' ,
148
149
FormatType :: Exponent ( Case :: Lower ) => 'e' ,
@@ -165,7 +166,8 @@ impl FormatParse for FormatType {
165
166
Some ( 'c' ) => ( Some ( Self :: Character ) , chars. as_str ( ) ) ,
166
167
Some ( 'd' ) => ( Some ( Self :: Decimal ) , chars. as_str ( ) ) ,
167
168
Some ( 'o' ) => ( Some ( Self :: Octal ) , chars. as_str ( ) ) ,
168
- Some ( 'n' ) => ( Some ( Self :: Number ) , chars. as_str ( ) ) ,
169
+ Some ( 'n' ) => ( Some ( Self :: Number ( Case :: Lower ) ) , chars. as_str ( ) ) ,
170
+ Some ( 'N' ) => ( Some ( Self :: Number ( Case :: Upper ) ) , chars. as_str ( ) ) ,
169
171
Some ( 'x' ) => ( Some ( Self :: Hex ( Case :: Lower ) ) , chars. as_str ( ) ) ,
170
172
Some ( 'X' ) => ( Some ( Self :: Hex ( Case :: Upper ) ) , chars. as_str ( ) ) ,
171
173
Some ( 'e' ) => ( Some ( Self :: Exponent ( Case :: Lower ) ) , chars. as_str ( ) ) ,
@@ -367,14 +369,14 @@ impl FormatSpec {
367
369
| FormatType :: Binary
368
370
| FormatType :: Octal
369
371
| FormatType :: Hex ( _)
370
- | FormatType :: Number ,
372
+ | FormatType :: Number ( _ ) ,
371
373
) => {
372
374
let ch = char:: from ( format_type) ;
373
375
Err ( FormatSpecError :: UnspecifiedFormat ( ',' , ch) )
374
376
}
375
377
(
376
378
Some ( FormatGrouping :: Underscore ) ,
377
- FormatType :: String | FormatType :: Character | FormatType :: Number ,
379
+ FormatType :: String | FormatType :: Character | FormatType :: Number ( _ ) ,
378
380
) => {
379
381
let ch = char:: from ( format_type) ;
380
382
Err ( FormatSpecError :: UnspecifiedFormat ( '_' , ch) )
@@ -386,7 +388,7 @@ impl FormatSpec {
386
388
fn get_separator_interval ( & self ) -> usize {
387
389
match self . format_type {
388
390
Some ( FormatType :: Binary | FormatType :: Octal | FormatType :: Hex ( _) ) => 4 ,
389
- Some ( FormatType :: Decimal | FormatType :: Number | FormatType :: FixedPoint ( _) ) => 3 ,
391
+ Some ( FormatType :: Decimal | FormatType :: Number ( _ ) | FormatType :: FixedPoint ( _) ) => 3 ,
390
392
None => 3 ,
391
393
_ => panic ! ( "Separators only valid for numbers!" ) ,
392
394
}
@@ -430,12 +432,12 @@ impl FormatSpec {
430
432
| Some ( FormatType :: Octal )
431
433
| Some ( FormatType :: Hex ( _) )
432
434
| Some ( FormatType :: String )
433
- | Some ( FormatType :: Character ) => {
435
+ | Some ( FormatType :: Character )
436
+ | Some ( FormatType :: Number ( Case :: Upper ) ) => {
434
437
let ch = char:: from ( self . format_type . as_ref ( ) . unwrap ( ) ) ;
435
438
Err ( FormatSpecError :: UnknownFormatCode ( ch, "float" ) )
436
439
}
437
- Some ( FormatType :: Number ) => Err ( FormatSpecError :: NotImplemented ( 'n' , "float" ) ) ,
438
- Some ( FormatType :: GeneralFormat ( case) ) => {
440
+ Some ( FormatType :: GeneralFormat ( case) ) | Some ( FormatType :: Number ( case) ) => {
439
441
let precision = if precision == 0 { 1 } else { precision } ;
440
442
Ok ( float_ops:: format_general (
441
443
precision,
@@ -531,7 +533,10 @@ impl FormatSpec {
531
533
Ok ( result)
532
534
}
533
535
} ,
534
- Some ( FormatType :: Number ) => self . format_int_radix ( magnitude, 10 ) ,
536
+ Some ( FormatType :: Number ( Case :: Lower ) ) => self . format_int_radix ( magnitude, 10 ) ,
537
+ Some ( FormatType :: Number ( Case :: Upper ) ) => {
538
+ Err ( FormatSpecError :: UnknownFormatCode ( 'N' , "int" ) )
539
+ }
535
540
Some ( FormatType :: String ) => Err ( FormatSpecError :: UnknownFormatCode ( 's' , "int" ) ) ,
536
541
Some ( FormatType :: Character ) => match ( self . sign , self . alternate_form ) {
537
542
( Some ( _) , _) => Err ( FormatSpecError :: NotAllowed ( "Sign" ) ) ,
0 commit comments