diff options
| author | wickerwaka <martin.donlon@gmail.com> | 2014-08-30 11:27:02 -0700 |
|---|---|---|
| committer | wickerwaka <martin.donlon@gmail.com> | 2014-09-04 07:38:53 -0700 |
| commit | 2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac (patch) | |
| tree | 3ae6b60182e140f23f3d1cc772349fb5eb29b3f1 /src/libfmt_macros/lib.rs | |
| parent | 6d8b5c9f7d1347b715242a837fba87a01ae61d7e (diff) | |
| download | rust-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/libfmt_macros/lib.rs')
| -rw-r--r-- | src/libfmt_macros/lib.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 560681765cd..9272369f73c 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -81,6 +81,8 @@ pub enum Alignment { AlignLeft, /// The value will be aligned to the right. AlignRight, + /// The value will be aligned in the center. + AlignCenter, /// The value will take on a default alignment. AlignUnknown, } @@ -279,7 +281,7 @@ impl<'a> Parser<'a> { match self.cur.clone().next() { Some((_, c)) => { match self.cur.clone().skip(1).next() { - Some((_, '>')) | Some((_, '<')) => { + Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => { spec.fill = Some(c); self.cur.next(); } @@ -293,6 +295,8 @@ impl<'a> Parser<'a> { spec.align = AlignLeft; } else if self.consume('>') { spec.align = AlignRight; + } else if self.consume('^') { + spec.align = AlignCenter; } // Sign flags if self.consume('+') { |
