Skip to content

Commit 4099d08

Browse files
committed
---
yaml --- r: 2714 b: refs/heads/master c: 90e6453 h: refs/heads/master v: v3
1 parent 45a955b commit 4099d08

File tree

2 files changed

+81
-89
lines changed

2 files changed

+81
-89
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d7d387171c0df40f125b844256d53a007ae290d6
2+
refs/heads/master: 90e6453f46892f20235750dcc0bb95bbb1792380

trunk/src/lib/extfmt.rs

Lines changed: 80 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ mod ct {
129129
}
130130

131131
auto n = (c - ('0' as u8)) as uint;
132-
alt (peek_num(s, i + 1u, lim)) {
132+
ret alt (peek_num(s, i + 1u, lim)) {
133133
case (none[tup(uint, uint)]) {
134-
ret some[tup(uint, uint)](tup(n, i + 1u));
134+
some[tup(uint, uint)](tup(n, i + 1u))
135135
}
136136
case (some[tup(uint, uint)](?next)) {
137137
auto m = next._0;
138138
auto j = next._1;
139-
ret some[tup(uint, uint)](tup(n * 10u + m, j));
139+
some[tup(uint, uint)](tup(n * 10u + m, j))
140140
}
141-
}
142-
141+
};
143142
}
144143

145144
fn parse_conversion(str s, uint i, uint lim) -> tup(piece, uint) {
@@ -162,21 +161,21 @@ mod ct {
162161
}
163162

164163
auto num = peek_num(s, i, lim);
165-
alt (num) {
164+
ret alt (num) {
166165
case (none[tup(uint, uint)]) {
167-
ret tup(none[int], i);
166+
tup(none[int], i)
168167
}
169168
case (some[tup(uint, uint)](?t)) {
170169
auto n = t._0;
171170
auto j = t._1;
172171
if (j < lim && s.(j) == '$' as u8) {
173-
ret tup(some[int](n as int), j + 1u);
172+
tup(some[int](n as int), j + 1u)
174173
}
175174
else {
176-
ret tup(none[int], i);
175+
tup(none[int], i)
177176
}
178177
}
179-
}
178+
};
180179
}
181180

182181
fn parse_flags(str s, uint i, uint lim) -> tup(vec[flag], uint) {
@@ -197,70 +196,66 @@ mod ct {
197196
auto more = bind more_(_, s, i, lim);
198197

199198
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)
202201
} else if (f == ('0' as u8)) {
203-
ret more(flag_left_zero_pad);
202+
more(flag_left_zero_pad)
204203
} else if (f == (' ' as u8)) {
205-
ret more(flag_space_for_sign);
204+
more(flag_space_for_sign)
206205
} else if (f == ('+' as u8)) {
207-
ret more(flag_sign_always);
206+
more(flag_sign_always)
208207
} else if (f == ('#' as u8)) {
209-
ret more(flag_alternate);
208+
more(flag_alternate)
210209
} else {
211-
ret tup(noflags, i);
212-
}
210+
tup(noflags, i)
211+
};
213212
}
214213

215214
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)) {
221218
auto param = parse_parameter(s, i + 1u, lim);
222219
auto j = param._1;
223220
alt (param._0) {
224221
case (none[int]) {
225-
ret tup(count_is_next_param, j);
222+
tup(count_is_next_param, j)
226223
}
227224
case (some[int](?n)) {
228-
ret tup(count_is_param(n), j);
225+
tup(count_is_param(n), j)
229226
}
230227
}
231228
} else {
232229
auto num = peek_num(s, i, lim);
233230
alt (num) {
234231
case (none[tup(uint, uint)]) {
235-
ret tup(count_implied, i);
232+
tup(count_implied, i)
236233
}
237234
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)
239236
}
240237
}
241-
}
238+
};
242239
}
243240

244241
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) {
250245
auto count = parse_count(s, i + 1u, lim);
251246
// If there were no digits specified, i.e. the precision
252247
// was ".", then the precision is 0
253248
alt (count._0) {
254249
case (count_implied) {
255-
ret tup(count_is(0), count._1);
250+
tup(count_is(0), count._1)
256251
}
257252
case (_) {
258-
ret count;
253+
count
259254
}
260255
}
261256
} else {
262-
ret tup(count_implied, i);
263-
}
257+
tup(count_implied, i)
258+
};
264259
}
265260

266261
fn parse_type(str s, uint i, uint lim) -> tup(ty, uint) {
@@ -269,33 +264,32 @@ mod ct {
269264
fail;
270265
}
271266

272-
auto t;
273267
auto tstr = str::substr(s, i, 1u);
274-
if (str::eq(tstr, "b")) {
275-
t = ty_bool;
268+
auto t = if (str::eq(tstr, "b")) {
269+
ty_bool
276270
} else if (str::eq(tstr, "s")) {
277-
t = ty_str;
271+
ty_str
278272
} else if (str::eq(tstr, "c")) {
279-
t = ty_char;
273+
ty_char
280274
} else if (str::eq(tstr, "d")
281275
|| str::eq(tstr, "i")) {
282276
// TODO: Do we really want two signed types here?
283277
// How important is it to be printf compatible?
284-
t = ty_int(signed);
278+
ty_int(signed)
285279
} else if (str::eq(tstr, "u")) {
286-
t = ty_int(unsigned);
280+
ty_int(unsigned)
287281
} else if (str::eq(tstr, "x")) {
288-
t = ty_hex(case_lower);
282+
ty_hex(case_lower)
289283
} else if (str::eq(tstr, "X")) {
290-
t = ty_hex(case_upper);
284+
ty_hex(case_upper)
291285
} else if (str::eq(tstr, "t")) {
292-
t = ty_bits;
286+
ty_bits
293287
} else if (str::eq(tstr, "o")) {
294-
t = ty_octal;
288+
ty_octal
295289
} else {
296290
log_err "unknown type in conversion";
297-
fail;
298-
}
291+
fail
292+
};
299293

300294
ret tup(t, i + 1u);
301295
}
@@ -355,34 +349,32 @@ mod rt {
355349

356350
fn conv_uint(&conv cv, uint u) -> str {
357351
auto prec = get_int_precision(cv);
358-
auto res;
359-
alt (cv.ty) {
352+
auto res = alt (cv.ty) {
360353
case (ty_default) {
361-
res = uint_to_str_prec(u, 10u, prec);
354+
uint_to_str_prec(u, 10u, prec)
362355
}
363356
case (ty_hex_lower) {
364-
res = uint_to_str_prec(u, 16u, prec);
357+
uint_to_str_prec(u, 16u, prec)
365358
}
366359
case (ty_hex_upper) {
367-
res = str::to_upper(uint_to_str_prec(u, 16u, prec));
360+
str::to_upper(uint_to_str_prec(u, 16u, prec))
368361
}
369362
case (ty_bits) {
370-
res = uint_to_str_prec(u, 2u, prec);
363+
uint_to_str_prec(u, 2u, prec)
371364
}
372365
case (ty_octal) {
373-
res = uint_to_str_prec(u, 8u, prec);
366+
uint_to_str_prec(u, 8u, prec)
374367
}
375-
}
368+
};
376369
ret pad(cv, res, pad_unsigned);
377370
}
378371

379372
fn conv_bool(&conv cv, bool b) -> str {
380-
auto s;
381-
if (b) {
382-
s = "true";
373+
auto s = if (b) {
374+
"true"
383375
} else {
384-
s = "false";
385-
}
376+
"false"
377+
};
386378
// run the boolean conversion through the string conversion logic,
387379
// giving it the same rules for precision, etc.
388380
ret conv_str(cv, s);
@@ -393,61 +385,61 @@ mod rt {
393385
}
394386

395387
fn conv_str(&conv cv, str s) -> str {
396-
auto unpadded = s;
397-
alt (cv.precision) {
388+
auto unpadded = alt (cv.precision) {
398389
case (count_implied) {
390+
s
399391
}
400392
case (count_is(?max)) {
401393
// For strings, precision is the maximum characters displayed
402394
if (max as uint < str::char_len(s)) {
403395
// FIXME: substr works on bytes, not chars!
404-
unpadded = str::substr(s, 0u, max as uint);
396+
str::substr(s, 0u, max as uint)
397+
} else {
398+
s
405399
}
406400
}
407-
}
401+
};
408402
ret pad(cv, unpadded, pad_nozero);
409403
}
410404

411405
// Convert an int to string with minimum number of digits. If precision is
412406
// 0 and num is 0 then the result is the empty string.
413407
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)
416410
} else {
417-
ret uint_to_str_prec(num as uint, radix, prec);
418-
}
411+
uint_to_str_prec(num as uint, radix, prec)
412+
};
419413
}
420414

421415
// Convert a uint to string with a minimum number of digits. If precision
422416
// is 0 and num is 0 then the result is the empty string. Could move this
423417
// to uint: but it doesn't seem all that useful.
424418
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 == 0u && num == 0u) {
420+
""
429421
} else {
430-
s = uint::to_str(num, radix);
422+
auto s = uint::to_str(num, radix);
431423
auto len = str::char_len(s);
432424
if (len < prec) {
433425
auto diff = prec - len;
434426
auto pad = str_init_elt('0', diff);
435-
s = pad + s;
427+
pad + s
428+
} else {
429+
s
436430
}
437-
}
438-
439-
ret s;
431+
};
440432
}
441433

442434
fn get_int_precision(&conv cv) -> uint {
443-
alt (cv.precision) {
435+
ret alt (cv.precision) {
444436
case (count_is(?c)) {
445-
ret c as uint;
437+
c as uint
446438
}
447439
case (count_implied) {
448-
ret 1u;
440+
1u
449441
}
450-
}
442+
};
451443
}
452444

453445
// FIXME: This might be useful in str: but needs to be utf8 safe first
@@ -505,14 +497,14 @@ mod rt {
505497
}
506498

507499
fn have_precision(&conv cv) -> bool {
508-
alt (cv.precision) {
500+
ret alt (cv.precision) {
509501
case (count_implied) {
510-
ret false;
502+
false
511503
}
512504
case (_) {
513-
ret true;
505+
true
514506
}
515-
}
507+
};
516508
}
517509

518510
auto zero_padding = false;

0 commit comments

Comments
 (0)