Support #fmt precision for bools, with same rules as strings
Not totally confident this is desirable. The alternative would be to make it a compile error.
This commit is contained in:
parent
da996d6e6b
commit
1bec738c56
2 changed files with 14 additions and 2 deletions
|
@ -358,11 +358,15 @@ mod RT {
|
|||
}
|
||||
|
||||
fn conv_bool(&conv cv, bool b) -> str {
|
||||
auto s;
|
||||
if (b) {
|
||||
ret pad(cv, "true");
|
||||
s = "true";
|
||||
} else {
|
||||
ret pad(cv, "false");
|
||||
s = "false";
|
||||
}
|
||||
// Run the boolean conversion through the string conversion logic,
|
||||
// giving it the same rules for precision, etc.
|
||||
ret conv_str(cv, s);
|
||||
}
|
||||
|
||||
fn conv_char(&conv cv, char c) -> str {
|
||||
|
|
|
@ -104,4 +104,12 @@ fn main() {
|
|||
test(#fmt("%.5x", 127u), "0007f");
|
||||
test(#fmt("%.5t", 3u), "00011");
|
||||
test(#fmt("%.5c", 'A'), "A");
|
||||
|
||||
// Bool precision. I'm not sure if it's good or bad to have bool
|
||||
// conversions support precision - it's not standard printf so we
|
||||
// can do whatever. For now I'm making it behave the same as string
|
||||
// conversions.
|
||||
test(#fmt("%.b", true), "");
|
||||
test(#fmt("%.0b", true), "");
|
||||
test(#fmt("%.1b", true), "t");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue