@@ -268,13 +268,11 @@ mod ct {
268
268
}
269
269
}
270
270
271
-
272
271
// Functions used by the fmt extension at runtime. For now there are a lot of
273
272
// decisions made a runtime. If it proves worthwhile then some of these
274
273
// conditions can be evaluated at compile-time. For now though it's cleaner to
275
274
// implement it 0this way, I think.
276
- // XXX Rename to rt after snapshot
277
- mod rt2 {
275
+ mod rt {
278
276
const flag_none : u32 = 0u32;
279
277
const flag_left_justify : u32 = 0b00000000000000000000000000000001u32;
280
278
const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32;
@@ -461,22 +459,21 @@ mod rt2 {
461
459
}
462
460
}
463
461
464
- // XXX remove after snappies
465
- #[ allow( non_camel_case_types) ]
466
- mod rt {
462
+ // XXX remove after snapshots
463
+ mod rt2 {
467
464
const flag_none : u32 = 0u32 ;
468
465
const flag_left_justify : u32 = 0b00000000000000000000000000000001u32 ;
469
466
const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32 ;
470
467
const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32 ;
471
468
const flag_sign_always : u32 = 0b00000000000000000000000000001000u32 ;
472
469
const flag_alternate : u32 = 0b00000000000000000000000000010000u32 ;
473
470
474
- enum count { count_is ( int ) , count_implied , }
475
- enum ty { ty_default , ty_bits , ty_hex_upper , ty_hex_lower , ty_octal , }
471
+ enum Count { CountIs ( int ) , CountImplied , }
472
+ enum Ty { TyDefault , TyBits , TyHexUpper , TyHexLower , TyOctal , }
476
473
477
- type conv = { flags : u32 , width : count , precision : count , ty: ty } ;
474
+ type Conv = { flags : u32 , width : Count , precision : Count , ty: Ty } ;
478
475
479
- pure fn conv_int ( cv : conv , i : int ) -> ~str {
476
+ pure fn conv_int ( cv : Conv , i : int ) -> ~str {
480
477
let radix = 10 u;
481
478
let prec = get_int_precision ( cv) ;
482
479
let mut s : ~str = int_to_str_prec ( i, radix, prec) ;
@@ -487,47 +484,47 @@ mod rt {
487
484
unchecked { str : : unshift_char ( s, ' ' ) } ;
488
485
}
489
486
}
490
- return unchecked { pad( cv, s, pad_signed ) } ;
487
+ return unchecked { pad( cv, s, PadSigned ) } ;
491
488
}
492
- pure fn conv_uint ( cv : conv , u : uint ) -> ~str {
489
+ pure fn conv_uint ( cv : Conv , u : uint ) -> ~str {
493
490
let prec = get_int_precision ( cv) ;
494
491
let mut rs =
495
492
match cv. ty {
496
- ty_default => uint_to_str_prec ( u, 10 u, prec) ,
497
- ty_hex_lower => uint_to_str_prec ( u, 16 u, prec) ,
498
- ty_hex_upper => str:: to_upper ( uint_to_str_prec ( u, 16 u, prec) ) ,
499
- ty_bits => uint_to_str_prec ( u, 2 u, prec) ,
500
- ty_octal => uint_to_str_prec ( u, 8 u, prec)
493
+ TyDefault => uint_to_str_prec ( u, 10 u, prec) ,
494
+ TyHexLower => uint_to_str_prec ( u, 16 u, prec) ,
495
+ TyHexUpper => str:: to_upper ( uint_to_str_prec ( u, 16 u, prec) ) ,
496
+ TyBits => uint_to_str_prec ( u, 2 u, prec) ,
497
+ TyOctal => uint_to_str_prec ( u, 8 u, prec)
501
498
} ;
502
- return unchecked { pad( cv, rs, pad_unsigned ) } ;
499
+ return unchecked { pad( cv, rs, PadUnsigned ) } ;
503
500
}
504
- pure fn conv_bool ( cv : conv , b : bool ) -> ~str {
501
+ pure fn conv_bool ( cv : Conv , b : bool ) -> ~str {
505
502
let s = if b { ~"true " } else { ~"false " } ;
506
503
// run the boolean conversion through the string conversion logic,
507
504
// giving it the same rules for precision, etc.
508
505
return conv_str ( cv, s) ;
509
506
}
510
- pure fn conv_char ( cv : conv , c : char ) -> ~str {
507
+ pure fn conv_char ( cv : Conv , c : char ) -> ~str {
511
508
let mut s = str:: from_char ( c) ;
512
- return unchecked { pad( cv, s, pad_nozero ) } ;
509
+ return unchecked { pad( cv, s, PadNozero ) } ;
513
510
}
514
- pure fn conv_str ( cv : conv , s : & str ) -> ~str {
511
+ pure fn conv_str ( cv : Conv , s : & str ) -> ~str {
515
512
// For strings, precision is the maximum characters
516
513
// displayed
517
514
let mut unpadded = match cv. precision {
518
- count_implied => s. to_unique ( ) ,
519
- count_is ( max) => if max as uint < str:: char_len ( s ) {
515
+ CountImplied => s. to_unique ( ) ,
516
+ CountIs ( max) => if max as uint < str:: char_len ( s ) {
520
517
str:: substr ( s, 0 u, max as uint )
521
518
} else {
522
519
s. to_unique ( )
523
520
}
524
521
} ;
525
- return unchecked { pad( cv, unpadded, pad_nozero ) } ;
522
+ return unchecked { pad( cv, unpadded, PadNozero ) } ;
526
523
}
527
- pure fn conv_float ( cv : conv , f : float ) -> ~str {
524
+ pure fn conv_float ( cv : Conv , f : float ) -> ~str {
528
525
let ( to_str, digits) = match cv. precision {
529
- count_is ( c) => ( float:: to_str_exact, c as uint ) ,
530
- count_implied => ( float:: to_str, 6 u)
526
+ CountIs ( c) => ( float:: to_str_exact, c as uint ) ,
527
+ CountImplied => ( float:: to_str, 6 u)
531
528
} ;
532
529
let mut s = unchecked { to_str( f, digits) } ;
533
530
if 0.0 <= f {
@@ -537,9 +534,9 @@ mod rt {
537
534
s = ~" " + s;
538
535
}
539
536
}
540
- return unchecked { pad(cv, s, pad_float ) };
537
+ return unchecked { pad(cv, s, PadFloat ) };
541
538
}
542
- pure fn conv_poly<T>(cv: conv , v: T) -> ~str {
539
+ pure fn conv_poly<T>(cv: Conv , v: T) -> ~str {
543
540
let s = sys::log_str(v);
544
541
return conv_str(cv, s);
545
542
}
@@ -568,35 +565,35 @@ mod rt {
568
565
} else { move s }
569
566
} ;
570
567
}
571
- pure fn get_int_precision ( cv : conv ) -> uint {
568
+ pure fn get_int_precision ( cv : Conv ) -> uint {
572
569
return match cv. precision {
573
- count_is ( c) => c as uint ,
574
- count_implied => 1 u
570
+ CountIs ( c) => c as uint ,
571
+ CountImplied => 1 u
575
572
} ;
576
573
}
577
574
578
- enum pad_mode { pad_signed , pad_unsigned , pad_nozero , pad_float }
575
+ enum PadMode { PadSigned , PadUnsigned , PadNozero , PadFloat }
579
576
580
- impl pad_mode : Eq {
581
- pure fn eq ( & & other: pad_mode ) -> bool {
577
+ impl PadMode : Eq {
578
+ pure fn eq ( & & other: PadMode ) -> bool {
582
579
match ( self , other) {
583
- ( pad_signed , pad_signed ) => true ,
584
- ( pad_unsigned , pad_unsigned ) => true ,
585
- ( pad_nozero , pad_nozero ) => true ,
586
- ( pad_float , pad_float ) => true ,
587
- ( pad_signed , _) => false ,
588
- ( pad_unsigned , _) => false ,
589
- ( pad_nozero , _) => false ,
590
- ( pad_float , _) => false
580
+ ( PadSigned , PadSigned ) => true ,
581
+ ( PadUnsigned , PadUnsigned ) => true ,
582
+ ( PadNozero , PadNozero ) => true ,
583
+ ( PadFloat , PadFloat ) => true ,
584
+ ( PadSigned , _) => false ,
585
+ ( PadUnsigned , _) => false ,
586
+ ( PadNozero , _) => false ,
587
+ ( PadFloat , _) => false
591
588
}
592
589
}
593
- pure fn ne ( & & other: pad_mode ) -> bool { !self . eq ( other) }
590
+ pure fn ne ( & & other: PadMode ) -> bool { !self . eq ( other) }
594
591
}
595
592
596
- fn pad ( cv : conv , & s: ~str , mode : pad_mode ) -> ~str {
593
+ fn pad ( cv : Conv , & s: ~str , mode : PadMode ) -> ~str {
597
594
let uwidth : uint = match cv. width {
598
- count_implied => return copy s,
599
- count_is ( width) => {
595
+ CountImplied => return copy s,
596
+ CountIs ( width) => {
600
597
// FIXME: width should probably be uint (see Issue #1996)
601
598
width as uint
602
599
}
@@ -610,17 +607,17 @@ mod rt {
610
607
return s + padstr;
611
608
}
612
609
let { might_zero_pad, signed} = match mode {
613
- pad_nozero => { might_zero_pad: false, signed: false} ,
614
- pad_signed => { might_zero_pad: true, signed: true } ,
615
- pad_float => { might_zero_pad: true, signed: true} ,
616
- pad_unsigned => { might_zero_pad: true, signed: false}
610
+ PadNozero => { might_zero_pad: false, signed: false} ,
611
+ PadSigned => { might_zero_pad: true, signed: true } ,
612
+ PadFloat => { might_zero_pad: true, signed: true} ,
613
+ PadUnsigned => { might_zero_pad: true, signed: false}
617
614
} ;
618
- pure fn have_precision ( cv : conv ) -> bool {
619
- return match cv. precision { count_implied => false , _ => true } ;
615
+ pure fn have_precision ( cv : Conv ) -> bool {
616
+ return match cv. precision { CountImplied => false , _ => true } ;
620
617
}
621
618
let zero_padding = {
622
619
if might_zero_pad && have_flag ( cv. flags , flag_left_zero_pad) &&
623
- ( !have_precision ( cv) || mode == pad_float ) {
620
+ ( !have_precision ( cv) || mode == PadFloat ) {
624
621
padchar = '0' ;
625
622
true
626
623
} else {
@@ -650,7 +647,6 @@ mod rt {
650
647
}
651
648
}
652
649
653
-
654
650
#[ cfg( test) ]
655
651
mod test {
656
652
#[ test]
0 commit comments