Skip to content

Commit 0429493

Browse files
committed
fmt: fix formatting and style
1 parent 428abb3 commit 0429493

File tree

1 file changed

+75
-64
lines changed

1 file changed

+75
-64
lines changed

src/libcore/extfmt.rs

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ pub mod ct {
103103
use vec;
104104

105105
pub enum Signedness { Signed, Unsigned, }
106+
106107
pub enum Caseness { CaseUpper, CaseLower, }
108+
107109
pub enum Ty {
108110
TyBool,
109111
TyStr,
@@ -115,13 +117,15 @@ pub mod ct {
115117
TyFloat,
116118
TyPoly,
117119
}
120+
118121
pub enum Flag {
119122
FlagLeftJustify,
120123
FlagLeftZeroPad,
121124
FlagSpaceForSign,
122125
FlagSignAlways,
123126
FlagAlternate,
124127
}
128+
125129
pub enum Count {
126130
CountIs(uint),
127131
CountIsParam(uint),
@@ -136,22 +140,23 @@ pub mod ct {
136140

137141
impl<T> Parsed<T> {
138142
static pure fn new(val: T, next: uint) -> Parsed<T> {
139-
Parsed { val: val, next: next }
143+
Parsed {val: val, next: next}
140144
}
141145
}
142146

143147
// A formatted conversion from an expression to a string
144-
pub struct Conv
145-
{param: Option<uint>,
146-
flags: ~[Flag],
147-
width: Count,
148-
precision: Count,
149-
ty: Ty}
150-
148+
pub struct Conv {
149+
param: Option<uint>,
150+
flags: ~[Flag],
151+
width: Count,
152+
precision: Count,
153+
ty: Ty
154+
}
151155

152156
// A fragment of the output sequence
153157
pub enum Piece { PieceString(~str), PieceConv(Conv), }
154-
pub type ErrorFn = fn@(&str) -> ! ;
158+
159+
pub type ErrorFn = @fn(&str) -> !;
155160

156161
pub fn parse_fmt_string(s: &str, err: ErrorFn) -> ~[Piece] {
157162
fn push_slice(ps: &mut ~[Piece], s: &str, from: uint, to: uint) {
@@ -190,57 +195,61 @@ pub mod ct {
190195
push_slice(&mut pieces, s, h, i);
191196
pieces
192197
}
193-
pub fn peek_num(s: &str, i: uint, lim: uint) ->
194-
Option<Parsed<uint>> {
195-
let mut j = i;
196-
let mut accum = 0u;
198+
199+
pub fn peek_num(s: &str, i: uint, lim: uint) -> Option<Parsed<uint>> {
200+
let mut i = i;
201+
let mut accum = 0;
197202
let mut found = false;
198-
while j < lim {
199-
match char::to_digit(s[j] as char, 10) {
203+
204+
while i < lim {
205+
match char::to_digit(s[i] as char, 10) {
200206
Some(x) => {
201207
found = true;
202208
accum *= 10;
203209
accum += x;
204-
j += 1;
205-
},
210+
i += 1;
211+
}
206212
None => break
207213
}
208214
}
215+
209216
if found {
210-
Some(Parsed::new(accum, j))
217+
Some(Parsed::new(accum, i))
211218
} else {
212219
None
213220
}
214221
}
215-
pub fn parse_conversion(s: &str, i: uint, lim: uint,
216-
err: ErrorFn) ->
217-
Parsed<Piece> {
218-
let parm = parse_parameter(s, i, lim);
222+
223+
pub fn parse_conversion(s: &str, i: uint, lim: uint, err: ErrorFn) ->
224+
Parsed<Piece> {
225+
let param = parse_parameter(s, i, lim);
219226
// avoid copying ~[Flag] by destructuring
220227
let Parsed {val: flags_val, next: flags_next} = parse_flags(s,
221-
parm.next, lim);
228+
param.next, lim);
222229
let width = parse_count(s, flags_next, lim);
223230
let prec = parse_precision(s, width.next, lim);
224231
let ty = parse_type(s, prec.next, lim, err);
225-
Parsed::new(
226-
PieceConv(Conv {param: parm.val,
227-
flags: flags_val,
228-
width: width.val,
229-
precision: prec.val,
230-
ty: ty.val}),
231-
ty.next)
232+
233+
Parsed::new(PieceConv(Conv {
234+
param: param.val,
235+
flags: flags_val,
236+
width: width.val,
237+
precision: prec.val,
238+
ty: ty.val}), ty.next)
232239
}
240+
233241
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
234-
Parsed<Option<uint>> {
242+
Parsed<Option<uint>> {
235243
if i >= lim { return Parsed::new(None, i); }
244+
236245
match peek_num(s, i, lim) {
237246
Some(num) if num.next < lim && s[num.next] == '$' as u8 =>
238247
Parsed::new(Some(num.val), num.next + 1),
239248
_ => Parsed::new(None, i)
240249
}
241250
}
242-
pub fn parse_flags(s: &str, i: uint, lim: uint) ->
243-
Parsed<~[Flag]> {
251+
252+
pub fn parse_flags(s: &str, i: uint, lim: uint) -> Parsed<~[Flag]> {
244253
let mut i = i;
245254
let mut flags = ~[];
246255

@@ -260,44 +269,45 @@ pub mod ct {
260269

261270
Parsed::new(flags, i)
262271
}
263-
pub fn parse_count(s: &str, i: uint, lim: uint)
264-
-> Parsed<Count> {
265-
if i >= lim {
266-
Parsed::new(CountImplied, i)
267-
} else if s[i] == '*' as u8 {
268-
let param = parse_parameter(s, i + 1, lim);
269-
let j = param.next;
270-
match param.val {
271-
None => Parsed::new(CountIsNextParam, j),
272-
Some(n) => Parsed::new(CountIsParam(n), j)
273-
}
274-
} else {
275-
match peek_num(s, i, lim) {
276-
None => Parsed::new(CountImplied, i),
277-
Some(num) => Parsed::new(
278-
CountIs(num.val),
279-
num.next
280-
)
281-
}
272+
273+
pub fn parse_count(s: &str, i: uint, lim: uint) -> Parsed<Count> {
274+
if i >= lim {
275+
Parsed::new(CountImplied, i)
276+
} else if s[i] == '*' as u8 {
277+
let param = parse_parameter(s, i + 1, lim);
278+
let j = param.next;
279+
280+
match param.val {
281+
None => Parsed::new(CountIsNextParam, j),
282+
Some(n) => Parsed::new(CountIsParam(n), j)
283+
}
284+
} else {
285+
match peek_num(s, i, lim) {
286+
None => Parsed::new(CountImplied, i),
287+
Some(num) => Parsed::new(CountIs(num.val), num.next)
282288
}
289+
}
283290
}
284-
pub fn parse_precision(s: &str, i: uint, lim: uint) ->
285-
Parsed<Count> {
286-
if i < lim && s[i] == '.' as u8 {
287-
let count = parse_count(s, i + 1u, lim);
288291

292+
pub fn parse_precision(s: &str, i: uint, lim: uint) -> Parsed<Count> {
293+
if i < lim && s[i] == '.' as u8 {
294+
let count = parse_count(s, i + 1, lim);
289295

290-
// If there were no digits specified, i.e. the precision
291-
// was ".", then the precision is 0
292-
match count.val {
293-
CountImplied => Parsed::new(CountIs(0), count.next),
294-
_ => count
295-
}
296-
} else { Parsed::new(CountImplied, i) }
296+
// If there were no digits specified, i.e. the precision
297+
// was ".", then the precision is 0
298+
match count.val {
299+
CountImplied => Parsed::new(CountIs(0), count.next),
300+
_ => count
301+
}
302+
} else {
303+
Parsed::new(CountImplied, i)
304+
}
297305
}
306+
298307
pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
299-
Parsed<Ty> {
308+
Parsed<Ty> {
300309
if i >= lim { err(~"missing type in conversion"); }
310+
301311
// FIXME (#2249): Do we really want two signed types here?
302312
// How important is it to be printf compatible?
303313
let t = match s[i] {
@@ -314,6 +324,7 @@ pub mod ct {
314324
'?' as u8 => TyPoly,
315325
_ => err(~"unknown type in conversion: " + s.substr(i, 1))
316326
};
327+
317328
Parsed::new(t, i + 1)
318329
}
319330
}

0 commit comments

Comments
 (0)