about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorwickerwaka <martin.donlon@gmail.com>2014-08-30 11:27:02 -0700
committerwickerwaka <martin.donlon@gmail.com>2014-09-04 07:38:53 -0700
commit2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac (patch)
tree3ae6b60182e140f23f3d1cc772349fb5eb29b3f1 /src/libstd
parent6d8b5c9f7d1347b715242a837fba87a01ae61d7e (diff)
downloadrust-2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac.tar.gz
rust-2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac.zip
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
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fmt.rs3
1 files changed, 2 insertions, 1 deletions
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