Skip to content
Permalink
Browse files

Fix various issues with order of flag checks

Also, if there is no size specified, we don't need to check for anything
wrt to justification or padding.
  • Loading branch information...
lizmat committed Apr 9, 2019
1 parent 7201d89 commit 29107b172d0162d9f5bc1b7766bb70f6157657ff
Showing with 34 additions and 37 deletions.
  1. +34 −37 src/core/Rakudo/Internals/Sprintf.pm6
@@ -141,35 +141,33 @@ class Rakudo::Internals::Sprintf {
$value = "'$prefix' ~ $value" if $prefix;

# handle left/right justification
if has_minus($/) {
$value = "str-left-justified($size,$value)";
}
elsif $size {
$value = "str-right-justified($size,$value)";
if $size {
$value = has_minus($/)
?? "str-left-justified($size,$value)"
!! "str-right-justified($size,$value)";
}

make (~$<sym>, $value);
}

# show character representation of codepoint value
method directive:sym<c>($/) {
my int $size = +$<size>;
my str $value = "\@args.AT-POS({$*DIRECTIVES_SEEN++}).chr";
make (
~$<sym>,
$size > 0
?? "str-right-justified($size,$value)"
!! $size < 0
?? "str-left-justified(-$size,$value)"
!! $value
)

# handle justification
if +$<size> -> $size {
$value = has_minus($/)
?? "str-left-justified($size,$value)"
!! "str-right-justified($size,$value)";
}

make (~$<sym>, $value)
}

# show decimal (integer) value
method directive:sym<d>($/) {
my int $size = +$<size>;

# handle precision / zero filling
# handle precision / plus prefixing
my str $value = "\@args.AT-POS({$*DIRECTIVES_SEEN++}).Int.Str";
if $<precision> -> $precision {
$value = has_plus($/)
@@ -179,24 +177,25 @@ class Rakudo::Internals::Sprintf {
elsif has_plus($/) {
$value = "prefix-plus($value)";
}
elsif has_zero($/) {
$value = "pad-zeroes-int($size,$value)";
}

# handle left/right justification
if has_minus($/) {
$value = "str-left-justified($size,$value)";
}
elsif $size {
$value = "str-right-justified($size,$value)";
# handle left/right justification / zero padding
if +$<size> -> $size {
if has_minus($/) {
$value = "str-left-justified($size,$value)";
}
elsif has_zero($/) {
$value = "pad-zeroes-int($size,$value)";
}
else {
$value = "str-right-justified($size,$value)";
}
}

make (~$<sym>, $value)
}

# show string
method directive:sym<s>($/) {
my int $size = +$<size>;
my str $value = "\@args.AT-POS({$*DIRECTIVES_SEEN++}).Str";

# handle precision
@@ -205,11 +204,10 @@ class Rakudo::Internals::Sprintf {
}

# handle left/right justification
if has_minus($/) {
$value = "str-left-justified($size,$value)";
}
elsif $size {
$value = "str-right-justified($size,$value)";
if +$<size> -> $size {
$value = has_minus($/)
?? "str-left-justified($size,$value)"
!! "str-right-justified($size,$value)";
}

make (~$<sym>, $value)
@@ -221,14 +219,13 @@ class Rakudo::Internals::Sprintf {
# handle unsigned check
my str $value = "unsigned-int(\@args.AT-POS({$*DIRECTIVES_SEEN++}))";
# handle zero padding / left / right justification
my int $size = +$<size>;
if $size {
if has_zero($/) {
$value = "pad-zeroes-int($size,$value)";
}
elsif has_minus($/) {
if +$<size> -> $size {
if has_minus($/) {
$value = "str-left-justified($size,$value)";
}
elsif has_zero($/) {
$value = "pad-zeroes-int($size,$value)";
}
else {
$value = "str-right-justified($size,$value)";
}

0 comments on commit 29107b1

Please sign in to comment.
You can’t perform that action at this time.