Skip to content

Commit

Permalink
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
@@ -1395,6 +1395,7 @@ describe "String" do
("%20s" % 'a').should eq(" a")
("%-20s" % 'a').should eq("a ")
("%*s" % [10, 123]).should eq(" 123")
("%*s" % [-10, 123]).should eq("123 ")
("%.5s" % "foo bar baz").should eq("foo b")
("%.*s" % [5, "foo bar baz"]).should eq("foo b")
("%*.*s" % [20, 5, "foo bar baz"]).should eq(" foo b")
10 changes: 3 additions & 7 deletions src/string/formatter.cr
Original file line number Diff line number Diff line change
@@ -292,7 +292,7 @@ struct String::Formatter(A)

def pad(consumed, flags)
padding_char = flags.padding_char
(flags.width - consumed).times do
(flags.width.abs - consumed).times do
@io << padding_char
end
end
@@ -366,16 +366,12 @@ struct String::Formatter(A)
@precision_size = 0
end

def wants_padding?
@width > 0
end

def left_padding?
wants_padding? && !@minus
@minus ? @width < 0 : @width > 0
end

def right_padding?
wants_padding? && @minus
@minus ? @width > 0 : @width < 0
end

def padding_char

0 comments on commit 49f52ea

Please sign in to comment.