@@ -865,12 +865,12 @@ impl<'a> Formatter<'a> {
865
865
let mut sign = None ;
866
866
if !is_positive {
867
867
sign = Some ( '-' ) ; width += 1 ;
868
- } else if self . flags & ( 1 << ( FlagV1 :: SignPlus as u32 ) ) != 0 {
868
+ } else if self . sign_plus ( ) {
869
869
sign = Some ( '+' ) ; width += 1 ;
870
870
}
871
871
872
872
let mut prefixed = false ;
873
- if self . flags & ( 1 << ( FlagV1 :: Alternate as u32 ) ) != 0 {
873
+ if self . alternate ( ) {
874
874
prefixed = true ; width += prefix. char_len ( ) ;
875
875
}
876
876
@@ -900,7 +900,7 @@ impl<'a> Formatter<'a> {
900
900
}
901
901
// The sign and prefix goes before the padding if the fill character
902
902
// is zero
903
- Some ( min) if self . flags & ( 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ) != 0 => {
903
+ Some ( min) if self . sign_aware_zero_pad ( ) => {
904
904
self . fill = '0' ;
905
905
try!( write_prefix ( self ) ) ;
906
906
self . with_padding ( min - width, Alignment :: Right , |f| {
@@ -1013,7 +1013,7 @@ impl<'a> Formatter<'a> {
1013
1013
let mut formatted = formatted. clone ( ) ;
1014
1014
let mut align = self . align ;
1015
1015
let old_fill = self . fill ;
1016
- if self . flags & ( 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ) != 0 {
1016
+ if self . sign_aware_zero_pad ( ) {
1017
1017
// a sign always goes first
1018
1018
let sign = unsafe { str:: from_utf8_unchecked ( formatted. sign ) } ;
1019
1019
try!( self . buf . write_str ( sign) ) ;
@@ -1117,6 +1117,28 @@ impl<'a> Formatter<'a> {
1117
1117
issue = "27726" ) ]
1118
1118
pub fn precision ( & self ) -> Option < usize > { self . precision }
1119
1119
1120
+ /// Determines if the `+` flag was specified.
1121
+ #[ unstable( feature = "fmt_flags" , reason = "method was just created" ,
1122
+ issue = "27726" ) ]
1123
+ pub fn sign_plus ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: SignPlus as u32 ) != 0 }
1124
+
1125
+ /// Determines if the `-` flag was specified.
1126
+ #[ unstable( feature = "fmt_flags" , reason = "method was just created" ,
1127
+ issue = "27726" ) ]
1128
+ pub fn sign_minus ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: SignMinus as u32 ) != 0 }
1129
+
1130
+ /// Determines if the `#` flag was specified.
1131
+ #[ unstable( feature = "fmt_flags" , reason = "method was just created" ,
1132
+ issue = "27726" ) ]
1133
+ pub fn alternate ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: Alternate as u32 ) != 0 }
1134
+
1135
+ /// Determines if the `0` flag was specified.
1136
+ #[ unstable( feature = "fmt_flags" , reason = "method was just created" ,
1137
+ issue = "27726" ) ]
1138
+ pub fn sign_aware_zero_pad ( & self ) -> bool {
1139
+ self . flags & ( 1 << FlagV1 :: SignAwareZeroPad as u32 ) != 0
1140
+ }
1141
+
1120
1142
/// Creates a `DebugStruct` builder designed to assist with creation of
1121
1143
/// `fmt::Debug` implementations for structs.
1122
1144
///
@@ -1361,7 +1383,7 @@ impl<T> Pointer for *const T {
1361
1383
// it denotes whether to prefix with 0x. We use it to work out whether
1362
1384
// or not to zero extend, and then unconditionally set it to get the
1363
1385
// prefix.
1364
- if f. flags & 1 << ( FlagV1 :: Alternate as u32 ) > 0 {
1386
+ if f. alternate ( ) {
1365
1387
f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
1366
1388
1367
1389
if let None = f. width {
@@ -1410,7 +1432,7 @@ impl<'a, T> Pointer for &'a mut T {
1410
1432
fn float_to_decimal_common < T > ( fmt : & mut Formatter , num : & T , negative_zero : bool ) -> Result
1411
1433
where T : flt2dec:: DecodableFloat
1412
1434
{
1413
- let force_sign = fmt. flags & ( 1 << ( FlagV1 :: SignPlus as u32 ) ) != 0 ;
1435
+ let force_sign = fmt. sign_plus ( ) ;
1414
1436
let sign = match ( force_sign, negative_zero) {
1415
1437
( false , false ) => flt2dec:: Sign :: Minus ,
1416
1438
( false , true ) => flt2dec:: Sign :: MinusRaw ,
@@ -1434,7 +1456,7 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter, num: &T, negative_zero: bool)
1434
1456
fn float_to_exponential_common < T > ( fmt : & mut Formatter , num : & T , upper : bool ) -> Result
1435
1457
where T : flt2dec:: DecodableFloat
1436
1458
{
1437
- let force_sign = fmt. flags & ( 1 << ( FlagV1 :: SignPlus as u32 ) ) != 0 ;
1459
+ let force_sign = fmt. sign_plus ( ) ;
1438
1460
let sign = match force_sign {
1439
1461
false => flt2dec:: Sign :: Minus ,
1440
1462
true => flt2dec:: Sign :: MinusPlus ,
0 commit comments