Skip to content

Commit

Permalink
make unbase moderately magic again
Browse files Browse the repository at this point in the history
This now allows 0x and 0o in :16(), but 0d is correctly interpreted as
a hex byte, not a prefix for decimal. pmichaud++
  • Loading branch information
moritz committed Mar 30, 2012
1 parent 3d7cc4d commit dab5893
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/Str.pm
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,15 @@ sub trim-trailing(Str:D $s) { $s.trim-trailing }

# the opposite of Real.base, used for :16($hex_str)
sub unbase(Int:D $base, Str:D $str) {
":{$base}<$str>".Numeric;
my Str $prefix = $str.substr(0, 2);
if $base <= 10 && $prefix eq any(<0x 0d 0o 0b>)
or $base <= 24 && $prefix eq any <0o 0x>
or $base <= 33 && $prefix eq '0x' {
$str.Numeric;

} else {
":{$base}<$str>".Numeric;
}
}

sub chrs(*@c) {
Expand Down

0 comments on commit dab5893

Please sign in to comment.