Skip to content

Commit

Permalink
Revert previous commit
Browse files Browse the repository at this point in the history
- not going to need Str!parse-base for val processing
- but keep the return value constraints
  • Loading branch information
lizmat committed Dec 5, 2019
1 parent a9afa01 commit 519cef4
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/core.c/Str.pm6
Expand Up @@ -1434,21 +1434,16 @@ my class Str does Stringy { # declared in BOOTSTRAP
multi method parse-base(Str:D: Int:D $radix --> Numeric:D) {
2 <= $radix <= 36 # (0..9,"a".."z").elems == 36
?? nqp::chars(self)
?? self!parse-base($radix)
?? nqp::atpos( # something to parse
(my $r := nqp::radix_I($radix,self,0,0x02,Int)),
2
) == nqp::chars(self)
?? nqp::atpos($r,0)
!! self!slow-parse-base($radix,nqp::atpos($r,0),nqp::atpos($r,2))
!! self!parse-fail($radix, 0) # nothing to parse
!! Failure.new(X::Syntax::Number::RadixOutOfRange.new(:$radix))
}

# Main entry point for non-empty strings and valid radixes
method !parse-base(int $radix --> Numeric:D) {
nqp::atpos(
(my $r := nqp::radix_I($radix,self,0,0x02,Int)),
2
) == nqp::chars(self)
?? nqp::atpos($r,0)
!! self!slow-parse-base($radix,nqp::atpos($r,0),nqp::atpos($r,2))
}

# Shortcut for generating parsing Failure
method !parse-fail($radix, $pos --> Failure) {
Failure.new(X::Str::Numeric.new(
Expand Down

0 comments on commit 519cef4

Please sign in to comment.