Skip to content

Commit

Permalink
Support :i(ignorecase) / :m(ignoremark) with Str.ends-with
Browse files Browse the repository at this point in the history
- on MoarVM, uses nqp::indexic / indexim / indexicim ops
- other backends use foldcase logic for :i(ignorecase)
- dies on other backends trying to use :m(ignoremark)
  • Loading branch information
lizmat committed Feb 11, 2020
1 parent 49aaa6f commit 60b0d86
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions src/core.c/Str.pm6
Expand Up @@ -209,16 +209,80 @@ my class Str does Stringy { # declared in BOOTSTRAP
self.starts-with($needle.Str, |%_)
}

multi method ends-with(Str:D: Cool:D $needle --> Bool:D) {
self.ends-with: $needle.Str
multi method ends-with(Str:D:
Str:D $needle, :i($ignorecase)!, :m($ignoremark)!
--> Bool:D) {
nqp::hllbool($ignorecase
?? $ignoremark
#?if moar
?? nqp::eqaticim(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
!! nqp::eqatic(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
#?if !moar
?? self!die-named('ignorecase and :ignoremark')
!! nqp::eqat(nqp::fc(self),nqp::fc($needle),
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
!! $ignoremark
#?if moar
?? nqp::eqatim(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
#?if !moar
?? self!die-named('ignoremark')
#?endif
!! nqp::eqat(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
)
}
multi method ends-with(Str:D: Str:D $needle --> Bool:D) {

multi method ends-with(Str:D:
Str:D $needle, :i($ignorecase)!
--> Bool:D) {
nqp::hllbool($ignorecase
#?if moar
?? nqp::eqatic(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
#?if !moar
?? nqp::eqat(nqp::fc(self),nqp::fc($needle),
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
!! nqp::eqat(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
)
}

multi method ends-with(Str:D:
Str:D $needle, :m($ignoremark)!
--> Bool:D) {
nqp::hllbool($ignoremark
#?if moar
?? nqp::eqatim(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
#?endif
#?if !moar
?? self!die-named('ignoremark')
#?endif
!! nqp::eqat(self,$needle,
nqp::sub_i(nqp::chars(self),nqp::chars($needle)))
)
}

multi method ends-with(Str:D:
Str:D $needle
--> Bool:D) {
nqp::hllbool(
nqp::eqat(
self,$needle,nqp::sub_i(nqp::chars(self),nqp::chars($needle))
)
)
}
multi method ends-with(Str:D: Cool:D $needle --> Bool:D) {
self.ends-with($needle.Str, |%_)
}

multi method substr-eq(Str:D: Cool:D $needle --> Bool:D) {
nqp::hllbool(nqp::eqat(self,$needle.Str,0))
Expand Down

0 comments on commit 60b0d86

Please sign in to comment.