Skip to content

Commit 3048751

Browse files
committed
---
yaml --- r: 2233 b: refs/heads/master c: 8216b5f h: refs/heads/master i: 2231: 100b855 v: v3
1 parent 55c3589 commit 3048751

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
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: 2e12fbfc06abdf1547528047b1438204ca4121a1
2+
refs/heads/master: 8216b5fc10e7c7b0d4e9f40bb4f9fdaaaebf9400

trunk/src/lib/ExtFmt.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,20 @@ mod RT {
532532
// instead.
533533
if (signed
534534
&& zero_padding
535-
&& _str.byte_len(s) > 0u
536-
&& s.(0) == '-' as u8) {
535+
&& _str.byte_len(s) > 0u) {
537536

538-
auto bytelen = _str.byte_len(s);
539-
auto numpart = _str.substr(s, 1u, bytelen - 1u);
540-
ret "-" + padstr + numpart;
541-
} else {
542-
ret padstr + s;
537+
auto head = s.(0);
538+
if (head == '+' as u8
539+
|| head == '-' as u8
540+
|| head == ' ' as u8) {
541+
542+
auto headstr = _str.unsafe_from_bytes(vec(head));
543+
auto bytelen = _str.byte_len(s);
544+
auto numpart = _str.substr(s, 1u, bytelen - 1u);
545+
ret headstr + padstr + numpart;
546+
}
543547
}
548+
ret padstr + s;
544549
}
545550

546551
fn have_flag(vec[flag] flags, flag f) -> bool {

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ fn main() {
175175
test(#fmt("%06.5X", 127u), " 0007F");
176176
test(#fmt("%06.5o", 10u), " 00012");
177177

178-
// TODO: Padding and +
179-
// TODO: Padding and ' '
178+
// Signed combinations
179+
test(#fmt("% 5d", 1), " 1");
180+
test(#fmt("% 5d", -1), " -1");
181+
test(#fmt("%+5d", 1), " +1");
182+
test(#fmt("%+5d", -1), " -1");
183+
test(#fmt("% 05d", 1), " 0001");
184+
test(#fmt("% 05d", -1), "-0001");
185+
test(#fmt("%+05d", 1), "+0001");
186+
test(#fmt("%+05d", -1), "-0001");
187+
test(#fmt("%- 5d", 1), " 1 ");
188+
test(#fmt("%- 5d", -1), "-1 ");
189+
test(#fmt("%-+5d", 1), "+1 ");
190+
test(#fmt("%-+5d", -1), "-1 ");
191+
test(#fmt("%- 05d", 1), " 1 ");
192+
test(#fmt("%- 05d", -1), "-1 ");
193+
test(#fmt("%-+05d", 1), "+1 ");
194+
test(#fmt("%-+05d", -1), "-1 ");
180195
}

0 commit comments

Comments
 (0)