Fix the interaction between various flags in #fmt
This commit is contained in:
parent
2e12fbfc06
commit
8216b5fc10
2 changed files with 29 additions and 9 deletions
|
|
@ -532,15 +532,20 @@ mod RT {
|
|||
// instead.
|
||||
if (signed
|
||||
&& zero_padding
|
||||
&& _str.byte_len(s) > 0u
|
||||
&& s.(0) == '-' as u8) {
|
||||
&& _str.byte_len(s) > 0u) {
|
||||
|
||||
auto bytelen = _str.byte_len(s);
|
||||
auto numpart = _str.substr(s, 1u, bytelen - 1u);
|
||||
ret "-" + padstr + numpart;
|
||||
} else {
|
||||
ret padstr + s;
|
||||
auto head = s.(0);
|
||||
if (head == '+' as u8
|
||||
|| head == '-' as u8
|
||||
|| head == ' ' as u8) {
|
||||
|
||||
auto headstr = _str.unsafe_from_bytes(vec(head));
|
||||
auto bytelen = _str.byte_len(s);
|
||||
auto numpart = _str.substr(s, 1u, bytelen - 1u);
|
||||
ret headstr + padstr + numpart;
|
||||
}
|
||||
}
|
||||
ret padstr + s;
|
||||
}
|
||||
|
||||
fn have_flag(vec[flag] flags, flag f) -> bool {
|
||||
|
|
|
|||
|
|
@ -175,6 +175,21 @@ fn main() {
|
|||
test(#fmt("%06.5X", 127u), " 0007F");
|
||||
test(#fmt("%06.5o", 10u), " 00012");
|
||||
|
||||
// TODO: Padding and +
|
||||
// TODO: Padding and ' '
|
||||
// Signed combinations
|
||||
test(#fmt("% 5d", 1), " 1");
|
||||
test(#fmt("% 5d", -1), " -1");
|
||||
test(#fmt("%+5d", 1), " +1");
|
||||
test(#fmt("%+5d", -1), " -1");
|
||||
test(#fmt("% 05d", 1), " 0001");
|
||||
test(#fmt("% 05d", -1), "-0001");
|
||||
test(#fmt("%+05d", 1), "+0001");
|
||||
test(#fmt("%+05d", -1), "-0001");
|
||||
test(#fmt("%- 5d", 1), " 1 ");
|
||||
test(#fmt("%- 5d", -1), "-1 ");
|
||||
test(#fmt("%-+5d", 1), "+1 ");
|
||||
test(#fmt("%-+5d", -1), "-1 ");
|
||||
test(#fmt("%- 05d", 1), " 1 ");
|
||||
test(#fmt("%- 05d", -1), "-1 ");
|
||||
test(#fmt("%-+05d", 1), "+1 ");
|
||||
test(#fmt("%-+05d", -1), "-1 ");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue