@@ -129,17 +129,16 @@ mod ct {
129
129
}
130
130
131
131
auto n = ( c - ( '0' as u8 ) ) as uint ;
132
- alt ( peek_num ( s, i + 1 u, lim) ) {
132
+ ret alt ( peek_num ( s, i + 1 u, lim) ) {
133
133
case ( none[ tup ( uint, uint) ] ) {
134
- ret some[ tup ( uint, uint) ] ( tup ( n, i + 1 u) ) ;
134
+ some[ tup ( uint, uint) ] ( tup ( n, i + 1 u) )
135
135
}
136
136
case ( some[ tup ( uint, uint) ] ( ?next) ) {
137
137
auto m = next. _0 ;
138
138
auto j = next. _1 ;
139
- ret some[ tup ( uint, uint) ] ( tup ( n * 10 u + m, j) ) ;
139
+ some[ tup ( uint, uint) ] ( tup ( n * 10 u + m, j) )
140
140
}
141
- }
142
-
141
+ } ;
143
142
}
144
143
145
144
fn parse_conversion ( str s, uint i, uint lim) -> tup ( piece , uint ) {
@@ -162,21 +161,21 @@ mod ct {
162
161
}
163
162
164
163
auto num = peek_num ( s, i, lim) ;
165
- alt ( num) {
164
+ ret alt ( num) {
166
165
case ( none[ tup ( uint, uint) ] ) {
167
- ret tup ( none[ int] , i) ;
166
+ tup ( none[ int] , i)
168
167
}
169
168
case ( some[ tup ( uint, uint) ] ( ?t) ) {
170
169
auto n = t. _0 ;
171
170
auto j = t. _1 ;
172
171
if ( j < lim && s. ( j) == '$' as u8 ) {
173
- ret tup ( some[ int] ( n as int ) , j + 1 u) ;
172
+ tup ( some[ int] ( n as int ) , j + 1 u)
174
173
}
175
174
else {
176
- ret tup ( none[ int] , i) ;
175
+ tup ( none[ int] , i)
177
176
}
178
177
}
179
- }
178
+ } ;
180
179
}
181
180
182
181
fn parse_flags ( str s, uint i, uint lim) -> tup ( vec[ flag ] , uint ) {
@@ -197,70 +196,66 @@ mod ct {
197
196
auto more = bind more_ ( _, s, i, lim) ;
198
197
199
198
auto f = s. ( i) ;
200
- if ( f == ( '-' as u8 ) ) {
201
- ret more ( flag_left_justify) ;
199
+ ret if ( f == ( '-' as u8 ) ) {
200
+ more ( flag_left_justify)
202
201
} else if ( f == ( '0' as u8 ) ) {
203
- ret more ( flag_left_zero_pad) ;
202
+ more ( flag_left_zero_pad)
204
203
} else if ( f == ( ' ' as u8 ) ) {
205
- ret more ( flag_space_for_sign) ;
204
+ more ( flag_space_for_sign)
206
205
} else if ( f == ( '+' as u8 ) ) {
207
- ret more ( flag_sign_always) ;
206
+ more ( flag_sign_always)
208
207
} else if ( f == ( '#' as u8 ) ) {
209
- ret more ( flag_alternate) ;
208
+ more ( flag_alternate)
210
209
} else {
211
- ret tup ( noflags, i) ;
212
- }
210
+ tup ( noflags, i)
211
+ } ;
213
212
}
214
213
215
214
fn parse_count ( str s, uint i, uint lim) -> tup ( count , uint ) {
216
- if ( i >= lim) {
217
- ret tup ( count_implied, i) ;
218
- }
219
-
220
- if ( s. ( i) == ( '*' as u8 ) ) {
215
+ ret if ( i >= lim) {
216
+ tup ( count_implied, i)
217
+ } else if ( s. ( i) == ( '*' as u8 ) ) {
221
218
auto param = parse_parameter ( s, i + 1 u, lim) ;
222
219
auto j = param. _1 ;
223
220
alt ( param. _0 ) {
224
221
case ( none[ int] ) {
225
- ret tup ( count_is_next_param, j) ;
222
+ tup ( count_is_next_param, j)
226
223
}
227
224
case ( some[ int] ( ?n) ) {
228
- ret tup ( count_is_param ( n) , j) ;
225
+ tup ( count_is_param ( n) , j)
229
226
}
230
227
}
231
228
} else {
232
229
auto num = peek_num ( s, i, lim) ;
233
230
alt ( num) {
234
231
case ( none[ tup ( uint, uint) ] ) {
235
- ret tup ( count_implied, i) ;
232
+ tup ( count_implied, i)
236
233
}
237
234
case ( some[ tup ( uint, uint) ] ( ?num) ) {
238
- ret tup ( count_is ( num. _0 as int ) , num. _1 ) ;
235
+ tup ( count_is ( num. _0 as int ) , num. _1 )
239
236
}
240
237
}
241
- }
238
+ } ;
242
239
}
243
240
244
241
fn parse_precision ( str s, uint i, uint lim) -> tup ( count , uint ) {
245
- if ( i >= lim) {
246
- ret tup ( count_implied, i) ;
247
- }
248
-
249
- if ( s. ( i) == '.' as u8 ) {
242
+ ret if ( i >= lim) {
243
+ tup ( count_implied, i)
244
+ } else if ( s. ( i) == '.' as u8 ) {
250
245
auto count = parse_count ( s, i + 1 u, lim) ;
251
246
// If there were no digits specified, i.e. the precision
252
247
// was ".", then the precision is 0
253
248
alt ( count. _0 ) {
254
249
case ( count_implied) {
255
- ret tup ( count_is ( 0 ) , count. _1 ) ;
250
+ tup ( count_is ( 0 ) , count. _1 )
256
251
}
257
252
case ( _) {
258
- ret count;
253
+ count
259
254
}
260
255
}
261
256
} else {
262
- ret tup ( count_implied, i) ;
263
- }
257
+ tup ( count_implied, i)
258
+ } ;
264
259
}
265
260
266
261
fn parse_type ( str s, uint i, uint lim) -> tup ( ty , uint ) {
@@ -269,33 +264,32 @@ mod ct {
269
264
fail;
270
265
}
271
266
272
- auto t;
273
267
auto tstr = str:: substr ( s, i, 1 u) ;
274
- if ( str:: eq ( tstr, "b" ) ) {
275
- t = ty_bool;
268
+ auto t = if ( str:: eq ( tstr, "b" ) ) {
269
+ ty_bool
276
270
} else if ( str:: eq ( tstr, "s" ) ) {
277
- t = ty_str;
271
+ ty_str
278
272
} else if ( str:: eq ( tstr, "c" ) ) {
279
- t = ty_char;
273
+ ty_char
280
274
} else if ( str:: eq ( tstr, "d" )
281
275
|| str:: eq ( tstr, "i" ) ) {
282
276
// TODO: Do we really want two signed types here?
283
277
// How important is it to be printf compatible?
284
- t = ty_int ( signed) ;
278
+ ty_int ( signed)
285
279
} else if ( str:: eq ( tstr, "u" ) ) {
286
- t = ty_int ( unsigned) ;
280
+ ty_int ( unsigned)
287
281
} else if ( str:: eq ( tstr, "x" ) ) {
288
- t = ty_hex ( case_lower) ;
282
+ ty_hex ( case_lower)
289
283
} else if ( str:: eq ( tstr, "X" ) ) {
290
- t = ty_hex ( case_upper) ;
284
+ ty_hex ( case_upper)
291
285
} else if ( str:: eq ( tstr, "t" ) ) {
292
- t = ty_bits;
286
+ ty_bits
293
287
} else if ( str:: eq ( tstr, "o" ) ) {
294
- t = ty_octal;
288
+ ty_octal
295
289
} else {
296
290
log_err "unknown type in conversion" ;
297
- fail;
298
- }
291
+ fail
292
+ } ;
299
293
300
294
ret tup( t, i + 1 u) ;
301
295
}
@@ -355,34 +349,32 @@ mod rt {
355
349
356
350
fn conv_uint ( & conv cv, uint u) -> str {
357
351
auto prec = get_int_precision ( cv) ;
358
- auto res;
359
- alt ( cv. ty ) {
352
+ auto res = alt ( cv. ty ) {
360
353
case ( ty_default) {
361
- res = uint_to_str_prec ( u, 10 u, prec) ;
354
+ uint_to_str_prec ( u, 10 u, prec)
362
355
}
363
356
case ( ty_hex_lower) {
364
- res = uint_to_str_prec ( u, 16 u, prec) ;
357
+ uint_to_str_prec ( u, 16 u, prec)
365
358
}
366
359
case ( ty_hex_upper) {
367
- res = str:: to_upper ( uint_to_str_prec ( u, 16 u, prec) ) ;
360
+ str:: to_upper ( uint_to_str_prec ( u, 16 u, prec) )
368
361
}
369
362
case ( ty_bits) {
370
- res = uint_to_str_prec ( u, 2 u, prec) ;
363
+ uint_to_str_prec ( u, 2 u, prec)
371
364
}
372
365
case ( ty_octal) {
373
- res = uint_to_str_prec ( u, 8 u, prec) ;
366
+ uint_to_str_prec ( u, 8 u, prec)
374
367
}
375
- }
368
+ } ;
376
369
ret pad( cv, res, pad_unsigned) ;
377
370
}
378
371
379
372
fn conv_bool ( & conv cv, bool b) -> str {
380
- auto s;
381
- if ( b) {
382
- s = "true" ;
373
+ auto s = if ( b) {
374
+ "true"
383
375
} else {
384
- s = "false" ;
385
- }
376
+ "false"
377
+ } ;
386
378
// run the boolean conversion through the string conversion logic,
387
379
// giving it the same rules for precision, etc.
388
380
ret conv_str( cv, s) ;
@@ -393,61 +385,61 @@ mod rt {
393
385
}
394
386
395
387
fn conv_str ( & conv cv, str s) -> str {
396
- auto unpadded = s;
397
- alt ( cv. precision ) {
388
+ auto unpadded = alt ( cv. precision ) {
398
389
case ( count_implied) {
390
+ s
399
391
}
400
392
case ( count_is ( ?max) ) {
401
393
// For strings, precision is the maximum characters displayed
402
394
if ( max as uint < str:: char_len ( s ) ) {
403
395
// FIXME: substr works on bytes, not chars!
404
- unpadded = str:: substr ( s, 0 u, max as uint ) ;
396
+ str:: substr ( s, 0 u, max as uint )
397
+ } else {
398
+ s
405
399
}
406
400
}
407
- }
401
+ } ;
408
402
ret pad( cv, unpadded, pad_nozero) ;
409
403
}
410
404
411
405
// Convert an int to string with minimum number of digits. If precision is
412
406
// 0 and num is 0 then the result is the empty string.
413
407
fn int_to_str_prec ( int num, uint radix , uint prec) -> str {
414
- if ( num < 0 ) {
415
- ret "-" + uint_to_str_prec((-num) as uint, radix, prec);
408
+ ret if ( num < 0 ) {
409
+ "-" + uint_to_str_prec ( ( -num) as uint , radix, prec)
416
410
} else {
417
- ret uint_to_str_prec(num as uint, radix, prec);
418
- }
411
+ uint_to_str_prec ( num as uint , radix, prec)
412
+ } ;
419
413
}
420
414
421
415
// Convert a uint to string with a minimum number of digits. If precision
422
416
// is 0 and num is 0 then the result is the empty string. Could move this
423
417
// to uint: but it doesn't seem all that useful.
424
418
fn uint_to_str_prec ( uint num, uint radix , uint prec) -> str {
425
- auto s;
426
-
427
- if (prec == 0u && num == 0u) {
428
- s = " ";
419
+ ret if ( prec == 0 u && num == 0 u) {
420
+ ""
429
421
} else {
430
- s = uint:: to_str ( num, radix) ;
422
+ auto s = uint:: to_str ( num, radix) ;
431
423
auto len = str:: char_len ( s) ;
432
424
if ( len < prec) {
433
425
auto diff = prec - len;
434
426
auto pad = str_init_elt ( '0' , diff) ;
435
- s = pad + s;
427
+ pad + s
428
+ } else {
429
+ s
436
430
}
437
- }
438
-
439
- ret s;
431
+ } ;
440
432
}
441
433
442
434
fn get_int_precision ( & conv cv) -> uint {
443
- alt ( cv. precision ) {
435
+ ret alt ( cv. precision ) {
444
436
case ( count_is ( ?c) ) {
445
- ret c as uint ;
437
+ c as uint
446
438
}
447
439
case ( count_implied) {
448
- ret 1 u ;
440
+ 1 u
449
441
}
450
- }
442
+ } ;
451
443
}
452
444
453
445
// FIXME: This might be useful in str: but needs to be utf8 safe first
@@ -505,14 +497,14 @@ mod rt {
505
497
}
506
498
507
499
fn have_precision ( & conv cv) -> bool {
508
- alt ( cv. precision ) {
500
+ ret alt ( cv. precision ) {
509
501
case ( count_implied) {
510
- ret false ;
502
+ false
511
503
}
512
504
case ( _) {
513
- ret true ;
505
+ true
514
506
}
515
- }
507
+ } ;
516
508
}
517
509
518
510
auto zero_padding = false ;
0 commit comments