Skip to content

Commit 9b666b7

Browse files
committed
---
yaml --- r: 52135 b: refs/heads/dist-snap c: 428abb3 h: refs/heads/master i: 52133: e3ee7d3 52131: b45a78c 52127: b8c9d96 v: v3
1 parent d0dc657 commit 9b666b7

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: 44d4d6de762f3f9aae1fedcf454c66b79b3ad58d
10-
refs/heads/dist-snap: 9e5a4166d5bf0ebad622535a6619e12014fc6470
10+
refs/heads/dist-snap: 428abb3d97bbecb90f29e6238dfbedfcf67df2b6
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/extfmt.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,39 +154,41 @@ pub mod ct {
154154
pub type ErrorFn = fn@(&str) -> ! ;
155155

156156
pub fn parse_fmt_string(s: &str, err: ErrorFn) -> ~[Piece] {
157-
let mut pieces: ~[Piece] = ~[];
158-
let lim = str::len(s);
159-
let mut buf = ~"";
160-
fn flush_buf(buf: ~str, pieces: &mut ~[Piece]) -> ~str {
161-
if buf.len() > 0 {
162-
let piece = PieceString(move buf);
163-
pieces.push(move piece);
157+
fn push_slice(ps: &mut ~[Piece], s: &str, from: uint, to: uint) {
158+
if to > from {
159+
ps.push(PieceString(s.slice(from, to)));
164160
}
165-
return ~"";
166161
}
162+
163+
let lim = s.len();
164+
let mut h = 0;
167165
let mut i = 0;
166+
let mut pieces = ~[];
167+
168168
while i < lim {
169-
let size = str::utf8_char_width(s[i]);
170-
let curr = str::slice(s, i, i+size);
171-
if curr == ~"%" {
169+
if s[i] == '%' as u8 {
172170
i += 1;
171+
173172
if i >= lim {
174173
err(~"unterminated conversion at end of string");
175-
}
176-
let curr2 = str::slice(s, i, i+1);
177-
if curr2 == ~"%" {
178-
buf += curr2;
174+
} else if s[i] == '%' as u8 {
175+
push_slice(&mut pieces, s, h, i);
179176
i += 1;
180177
} else {
181-
buf = flush_buf(move buf, &mut pieces);
182-
let rs = parse_conversion(s, i, lim, err);
183-
pieces.push(copy rs.val);
184-
i = rs.next;
178+
push_slice(&mut pieces, s, h, i - 1);
179+
let Parsed {val, next} = parse_conversion(s, i, lim, err);
180+
pieces.push(val);
181+
i = next;
185182
}
186-
} else { buf += curr; i += size; }
183+
184+
h = i;
185+
} else {
186+
i += str::utf8_char_width(s[i]);
187+
}
187188
}
188-
flush_buf(move buf, &mut pieces);
189-
move pieces
189+
190+
push_slice(&mut pieces, s, h, i);
191+
pieces
190192
}
191193
pub fn peek_num(s: &str, i: uint, lim: uint) ->
192194
Option<Parsed<uint>> {

0 commit comments

Comments
 (0)