Skip to content

Commit 9b845e4

Browse files
committed
---
yaml --- r: 23102 b: refs/heads/master c: 71bc267 h: refs/heads/master v: v3
1 parent 0193148 commit 9b845e4

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 800de26372513c12cf735b7dc43791808e5a5ee9
2+
refs/heads/master: 71bc2673edc7ba52c012392266ed7b9480e0f6ec
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/extfmt.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,25 @@ mod ct {
118118
}
119119
fn peek_num(s: ~str, i: uint, lim: uint) ->
120120
option<{num: uint, next: uint}> {
121-
if i >= lim { return none; }
122-
let c = s[i];
123-
if !('0' as u8 <= c && c <= '9' as u8) { return option::none; }
124-
let n = (c - ('0' as u8)) as uint;
125-
return match peek_num(s, i + 1u, lim) {
126-
none => some({num: n, next: i + 1u}),
127-
some(next) => {
128-
let m = next.num;
129-
let j = next.next;
130-
some({num: n * 10u + m, next: j})
131-
}
132-
};
121+
let mut j = i;
122+
let mut accum = 0u;
123+
let mut found = false;
124+
while j < lim {
125+
match char::to_digit(s[j] as char, 10) {
126+
some(x) => {
127+
found = true;
128+
accum *= 10;
129+
accum += x;
130+
j += 1;
131+
},
132+
none => break
133+
}
134+
}
135+
if found {
136+
some({num: accum, next: j})
137+
} else {
138+
none
139+
}
133140
}
134141
fn parse_conversion(s: ~str, i: uint, lim: uint, error: error_fn) ->
135142
{piece: piece, next: uint} {

trunk/src/test/run-pass/syntax-extension-fmt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ fn part4() {
138138
test(fmt!{"%.5c", 'A'}, ~"A");
139139
test(fmt!{"%.5f", 5.82}, ~"5.82000");
140140
test(fmt!{"%.5f", 5.0}, ~"5.00000");
141+
test(fmt!{"%.100f", 1.1}, ~"1.1000000000000000888178419700125232338905334472656250000000000000000000000000000000000000000000000000");
142+
141143
// Bool precision. I'm not sure if it's good or bad to have bool
142144
// conversions support precision - it's not standard printf so we
143145
// can do whatever. For now I'm making it behave the same as string

0 commit comments

Comments
 (0)