@@ -475,103 +475,6 @@ impl FormatOp {
475475 }
476476}
477477
478- #[ cfg( stage0) ]
479- fn format ( val : Param , op : FormatOp , flags : Flags ) -> Result < ~[ u8 ] , ~str > {
480- let mut s = match val {
481- Number ( d) => {
482- match op {
483- FormatString => {
484- return Err ( ~"non-number on stack with %s")
485- }
486- _ => {
487- let radix = match op {
488- FormatDigit => 10 ,
489- FormatOctal => 8 ,
490- FormatHex |FormatHEX => 16 ,
491- FormatString => util:: unreachable ( )
492- } ;
493- let mut s = ~[ ] ;
494- match op {
495- FormatDigit => {
496- let sign = if flags. sign { SignAll } else { SignNeg } ;
497- do int_to_str_bytes_common ( d, radix, sign) |c| {
498- s. push ( c) ;
499- }
500- }
501- _ => {
502- do int_to_str_bytes_common ( d as uint , radix, SignNone ) |c| {
503- s. push ( c) ;
504- }
505- }
506- } ;
507- if flags. precision > s. len ( ) {
508- let mut s_ = vec:: with_capacity ( flags. precision ) ;
509- let n = flags. precision - s. len ( ) ;
510- s_. grow ( n, & ( '0' as u8 ) ) ;
511- s_. push_all_move ( s) ;
512- s = s_;
513- }
514- assert ! ( !s. is_empty( ) , "string conversion produced empty result" ) ;
515- match op {
516- FormatDigit => {
517- if flags. space && !( s[ 0 ] == '-' as u8 || s[ 0 ] == '+' as u8 ) {
518- s. unshift ( ' ' as u8 ) ;
519- }
520- }
521- FormatOctal => {
522- if flags. alternate && s[ 0 ] != '0' as u8 {
523- s. unshift ( '0' as u8 ) ;
524- }
525- }
526- FormatHex => {
527- if flags. alternate {
528- let s_ = util:: replace ( & mut s, ~[ '0' as u8 , 'x' as u8 ] ) ;
529- s. push_all_move ( s_) ;
530- }
531- }
532- FormatHEX => {
533- s = s. into_ascii ( ) . to_upper ( ) . into_bytes ( ) ;
534- if flags. alternate {
535- let s_ = util:: replace ( & mut s, ~[ '0' as u8 , 'X' as u8 ] ) ;
536- s. push_all_move ( s_) ;
537- }
538- }
539- FormatString => util:: unreachable ( )
540- }
541- s
542- }
543- }
544- }
545- String ( s) => {
546- match op {
547- FormatString => {
548- let mut s = s. as_bytes ( ) . to_owned ( ) ;
549- if flags. precision > 0 && flags. precision < s. len ( ) {
550- s. truncate ( flags. precision ) ;
551- }
552- s
553- }
554- _ => {
555- return Err ( fmt ! ( "non-string on stack with %%%c" , op. to_char( ) ) )
556- }
557- }
558- }
559- } ;
560- if flags. width > s. len ( ) {
561- let n = flags. width - s. len ( ) ;
562- if flags. left {
563- s. grow ( n, & ( ' ' as u8 ) ) ;
564- } else {
565- let mut s_ = vec:: with_capacity ( flags. width ) ;
566- s_. grow ( n, & ( ' ' as u8 ) ) ;
567- s_. push_all_move ( s) ;
568- s = s_;
569- }
570- }
571- Ok ( s)
572- }
573-
574- #[ cfg( not( stage0) ) ]
575478fn format ( val : Param , op : FormatOp , flags : Flags ) -> Result < ~[ u8 ] , ~str > {
576479 let mut s = match val {
577480 Number ( d) => {
0 commit comments