Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1089 from AndrejMitrovic/Fix7142

Issue 7142 - Implement field width for boolean formatting
  • Loading branch information...
commit c89b21e38f5fd22a3d333a1061de6fcfce14a222 2 parents 1ec2e52 + 5057ca5
@alexrp alexrp authored
Showing with 26 additions and 1 deletion.
  1. +26 −1 std/format.d
View
27 std/format.d
@@ -1207,7 +1207,23 @@ if (is(BooleanTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
BooleanTypeOf!T val = obj;
if (f.spec == 's')
- put(w, val ? "true" : "false");
+ {
+ string s = val ? "true" : "false";
+ if (!f.flDash)
+ {
+ // right align
+ if (f.width > s.length)
+ foreach (i ; 0 .. f.width - s.length) put(w, ' ');
+ put(w, s);
+ }
+ else
+ {
+ // left align
+ put(w, s);
+ if (f.width > s.length)
+ foreach (i ; 0 .. f.width - s.length) put(w, ' ');
+ }
+ }
else
formatValue(w, cast(int) val, f);
}
@@ -1234,6 +1250,15 @@ unittest
formatTest( S2(true), "S" );
}
+unittest
+{
+ string t1 = format("[%6s] [%6s] [%-6s]", true, false, true);
+ assert(t1 == "[ true] [ false] [true ]");
+
+ string t2 = format("[%3s] [%-2s]", true, false);
+ assert(t2 == "[true] [false]");
+}
+
/**
$(D null) literal is formatted as $(D "null").
*/
Please sign in to comment.
Something went wrong with that request. Please try again.