@@ -65,20 +65,38 @@ pub mod ct {
65
65
FlagSignAlways ,
66
66
FlagAlternate ,
67
67
}
68
+ #[ cfg( stage0) ]
68
69
pub enum Count {
69
70
CountIs ( int ) ,
70
71
CountIsParam ( int ) ,
71
72
CountIsNextParam ,
72
73
CountImplied ,
73
74
}
75
+ #[ cfg( stage1) ]
76
+ #[ cfg( stage2) ]
77
+ pub enum Count {
78
+ CountIs ( uint ) ,
79
+ CountIsParam ( uint ) ,
80
+ CountIsNextParam ,
81
+ CountImplied ,
82
+ }
74
83
75
- // A formatted conversion from an expression to a string
84
+ # [ cfg ( stage0 ) ]
76
85
pub type Conv =
77
86
{ param : Option < int > ,
78
87
flags : ~[ Flag ] ,
79
88
width : Count ,
80
89
precision : Count ,
81
90
ty: Ty } ;
91
+ #[ cfg( stage1) ]
92
+ #[ cfg( stage2) ]
93
+ // A formatted conversion from an expression to a string
94
+ pub type Conv =
95
+ { param : Option < uint > ,
96
+ flags : ~[ Flag ] ,
97
+ width : Count ,
98
+ precision : Count ,
99
+ ty: Ty } ;
82
100
83
101
84
102
// A fragment of the output sequence
@@ -158,8 +176,26 @@ pub mod ct {
158
176
ty: ty.ty}),
159
177
next: ty.next};
160
178
}
179
+ #[cfg(stage0)]
161
180
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
162
181
{param: Option<int>, next: uint} {
182
+ if i >= lim { return {param: None, next: i}; }
183
+ let num = peek_num(s, i, lim);
184
+ return match num {
185
+ None => {param: None, next: i},
186
+ Some(t) => {
187
+ let n = t.num as int;
188
+ let j = t.next;
189
+ if j < lim && s[j] == '$' as u8 {
190
+ {param: Some(n), next: j + 1}
191
+ } else { {param: None, next: i} }
192
+ }
193
+ };
194
+ }
195
+ #[cfg(stage1)]
196
+ #[cfg(stage2)]
197
+ pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
198
+ {param: Option<uint>, next: uint} {
163
199
if i >= lim { return {param: None, next: i}; }
164
200
let num = peek_num(s, i, lim);
165
201
return match num {
@@ -168,7 +204,7 @@ pub mod ct {
168
204
let n = t.num;
169
205
let j = t.next;
170
206
if j < lim && s[j] == '$' as u8 {
171
- {param: Some(n as int ), next: j + 1u }
207
+ {param: Some(n), next: j + 1 }
172
208
} else { {param: None, next: i} }
173
209
}
174
210
};
@@ -201,12 +237,13 @@ pub mod ct {
201
237
more(FlagAlternate, s, i, lim)
202
238
} else { {flags: move noflags, next: i} };
203
239
}
240
+ #[cfg(stage0)]
204
241
pub fn parse_count(s: &str, i: uint, lim: uint)
205
242
-> {count: Count, next: uint} {
206
243
return if i >= lim {
207
244
{count: CountImplied, next: i}
208
245
} else if s[i] == '*' as u8 {
209
- let param = parse_parameter(s, i + 1u , lim);
246
+ let param = parse_parameter(s, i + 1 , lim);
210
247
let j = param.next;
211
248
match param.param {
212
249
None => {count: CountIsNextParam, next: j},
@@ -223,6 +260,30 @@ pub mod ct {
223
260
}
224
261
};
225
262
}
263
+ #[cfg(stage1)]
264
+ #[cfg(stage2)]
265
+ pub fn parse_count(s: &str, i: uint, lim: uint)
266
+ -> {count: Count, next: uint} {
267
+ return if i >= lim {
268
+ {count: CountImplied, next: i}
269
+ } else if s[i] == '*' as u8 {
270
+ let param = parse_parameter(s, i + 1, lim);
271
+ let j = param.next;
272
+ match param.param {
273
+ None => {count: CountIsNextParam, next: j},
274
+ Some(n) => {count: CountIsParam(n), next: j}
275
+ }
276
+ } else {
277
+ let num = peek_num(s, i, lim);
278
+ match num {
279
+ None => {count: CountImplied, next: i},
280
+ Some(num) => {
281
+ count: CountIs(num.num),
282
+ next: num.next
283
+ }
284
+ }
285
+ };
286
+ }
226
287
pub fn parse_precision(s: &str, i: uint, lim: uint) ->
227
288
{count: Count, next: uint} {
228
289
return if i >= lim {
@@ -285,7 +346,12 @@ pub mod rt {
285
346
pub const flag_sign_always : u32 = 0b00000000001000u32;
286
347
pub const flag_alternate : u32 = 0b00000000010000u32;
287
348
349
+ #[cfg(stage0)]
288
350
pub enum Count { CountIs(int), CountImplied, }
351
+ #[cfg(stage1)]
352
+ #[cfg(stage2)]
353
+ pub enum Count { CountIs(uint), CountImplied, }
354
+
289
355
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
290
356
291
357
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
@@ -307,11 +373,11 @@ pub mod rt {
307
373
let prec = get_int_precision(cv);
308
374
let mut rs =
309
375
match cv.ty {
310
- TyDefault => uint_to_str_prec(u, 10u , prec),
311
- TyHexLower => uint_to_str_prec(u, 16u , prec),
312
- TyHexUpper => str::to_upper(uint_to_str_prec(u, 16u , prec)),
313
- TyBits => uint_to_str_prec(u, 2u , prec),
314
- TyOctal => uint_to_str_prec(u, 8u , prec)
376
+ TyDefault => uint_to_str_prec(u, 10 , prec),
377
+ TyHexLower => uint_to_str_prec(u, 16 , prec),
378
+ TyHexUpper => str::to_upper(uint_to_str_prec(u, 16 , prec)),
379
+ TyBits => uint_to_str_prec(u, 2 , prec),
380
+ TyOctal => uint_to_str_prec(u, 8 , prec)
315
381
};
316
382
return unsafe { pad(cv, move rs, PadUnsigned) };
317
383
}
@@ -331,7 +397,7 @@ pub mod rt {
331
397
let mut unpadded = match cv. precision {
332
398
CountImplied => s. to_owned ( ) ,
333
399
CountIs ( max) => if max as uint < str:: char_len ( s ) {
334
- str:: substr ( s, 0 u , max as uint )
400
+ str:: substr ( s, 0 , max as uint )
335
401
} else {
336
402
s. to_owned ( )
337
403
}
@@ -412,10 +478,7 @@ pub mod rt {
412
478
let mut s = move s; // sadtimes
413
479
let uwidth : uint = match cv. width {
414
480
CountImplied => return ( move s) ,
415
- CountIs ( width) => {
416
- // FIXME: width should probably be uint (see Issue #1996)
417
- width as uint
418
- }
481
+ CountIs ( width) => { width as uint }
419
482
} ;
420
483
let strlen = str:: char_len ( s) ;
421
484
if uwidth <= strlen { return ( move s) ; }
0 commit comments