Skip to content

Commit

Permalink
Revert base 1 support in .parse-base and .base
Browse files Browse the repository at this point in the history
Revert "Add base 1 functionality to  .base and .parse-base" 295b0bf
Revert "Fix .base to allow string arguments for base 1" a21d2f9
  • Loading branch information
samcv committed Feb 10, 2017
1 parent 1615c83 commit f569c47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/core/Exception.pm
Expand Up @@ -1494,7 +1494,7 @@ my class X::Syntax::NoSelf does X::Syntax {

my class X::Syntax::Number::RadixOutOfRange does X::Syntax {
has $.radix;
method message() { "Radix $.radix out of range (allowed: 1..36)" }
method message() { "Radix $.radix out of range (allowed: 2..36)" }
}

my class X::Syntax::Number::IllegalDecimal does X::Syntax {
Expand Down
6 changes: 2 additions & 4 deletions src/core/Int.pm
Expand Up @@ -63,14 +63,12 @@ my class Int does Real { # declared in BOOTSTRAP

proto method base(|) { * }
multi method base(Int:D: Int:D $base) {
return nqp::x('1', self) if $base == 1;
2 <= $base <= 36
?? nqp::p6box_s(nqp::base_I(self,nqp::unbox_i($base)))
!! Failure.new(X::OutOfRange.new(
what => "base argument to base", :got($base), :range<1..36>))
what => "base argument to base", :got($base), :range<2..36>))
}
multi method base(Int:D: Int(Cool) $base, $digits?) {
return nqp::x('1', self) if $base == 1;
2 <= $base <= 36
?? $digits && ! nqp::istype($digits, Whatever)
?? $digits < 0
Expand All @@ -81,7 +79,7 @@ my class Int does Real { # declared in BOOTSTRAP
~ '0' x $digits
!! nqp::p6box_s(nqp::base_I(self,nqp::unbox_i($base)))
!! Failure.new(X::OutOfRange.new(
:what('base argument to base'),:got($base),:range<1..36>))
:what('base argument to base'),:got($base),:range<2..36>))
}

# If self is Int, we assume mods are Ints also. (div fails otherwise.)
Expand Down
21 changes: 3 additions & 18 deletions src/core/Str.pm
Expand Up @@ -1298,26 +1298,11 @@ my class Str does Stringy { # declared in BOOTSTRAP

limit = Inf if nqp::istype(limit,Whatever);
}

method parse-base(Str:D: Int:D $radix) {
if $radix == 1 {
my int $chars = nqp::chars(self);
if nqp::iseq_s(self, nqp::x('1', $chars)) {
return $chars;
}
else {
my int $i = 0;
while $i++ < $chars {
last unless nqp::eqat(self, '1', $i);
}
fail X::Str::Numeric.new(
:source(self),
:pos($i),
:reason("malformed base-$radix number"),
)
}
}
fail X::Syntax::Number::RadixOutOfRange.new(:$radix)
unless 1 <= $radix <= 36; # (0..9,"a".."z").elems == 36
unless 2 <= $radix <= 36; # (0..9,"a".."z").elems == 36

# do not modify $!value directly as that affects other same strings
my ($value, $sign, $sign-offset) = $!value, 1, 0;
given $value.substr(0,1) {
Expand Down

0 comments on commit f569c47

Please sign in to comment.