From 2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac Mon Sep 17 00:00:00 2001 From: wickerwaka Date: Sat, 30 Aug 2014 11:27:02 -0700 Subject: Center alignment for fmt Use '^' to specify center alignment in format strings. fmt!( "[{:^5s}]", "Hi" ) -> "[ Hi ]" fmt!( "[{:^5s}]", "H" ) -> "[ H ]" fmt!( "[{:^5d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^5d}]", -1i ) -> "[ -1 ]" fmt!( "[{:^6d}]", 1i ) -> "[ 1 ]" fmt!( "[{:^6d}]", -1i ) -> "[ -1 ]" If the padding is odd then the padding on the right will be one character longer than the padding on the left. Tuples squashed --- src/libstd/fmt.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index 841567a9120..f69f94c4db6 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -333,7 +333,7 @@ argument := integer | identifier format_spec := [[fill]align][sign]['#'][0][width]['.' precision][type] fill := character -align := '<' | '>' +align := '<' | '^' | '>' sign := '+' | '-' width := count precision := count | '*' @@ -357,6 +357,7 @@ parameter. This indicates that if the value being formatted is smaller than are specified by `fill`, and the alignment can be one of two options: * `<` - the argument is left-aligned in `width` columns +* `^` - the argument is center-aligned in `width` columns * `>` - the argument is right-aligned in `width` columns ### Sign/#/0 -- cgit 1.4.1-3-g733a5