diff --git a/src/core/Cool.pm b/src/core/Cool.pm index ef35735259f..20a33380942 100644 --- a/src/core/Cool.pm +++ b/src/core/Cool.pm @@ -68,11 +68,11 @@ my class Cool { # declared in BOOTSTRAP ## string methods - method chars() { - nqp::p6box_i(nqp::chars(nqp::unbox_s(self.Str))); + method chars() returns Int:D { + self.Str.chars } method codes() { - nqp::p6box_i(nqp::chars(nqp::unbox_s(self.Str))); + self.Str.codes } method fmt($format = '%s') { @@ -89,20 +89,19 @@ my class Cool { # declared in BOOTSTRAP method substr-rw(\SELF: $from, $length?) { substr-rw(SELF,$from,$length) } method uc() { - nqp::p6box_s(nqp::uc(nqp::unbox_s(self.Str))) + self.Str.uc } method lc() { - nqp::p6box_s(nqp::lc(nqp::unbox_s(self.Str))) + self.Str.lc } method tc() { - my $u := nqp::unbox_s(self.Str); - nqp::p6box_s(nqp::uc(nqp::substr($u,0,1)) ~ nqp::substr($u,1)); + self.Str.tc } method tclc() { - nqp::p6box_s(nqp::tclc(nqp::unbox_s(self.Str))) + self.Str.tclc } method wordcase() { self.Str.wordcase } @@ -125,10 +124,7 @@ my class Cool { # declared in BOOTSTRAP } method ord(--> Int) { - my $s := self.Str; - $s.chars - ?? nqp::p6box_i(nqp::ord(nqp::unbox_s($s))) - !! Int; + self.Str.ord } method chr() { self.Int.chr; @@ -136,9 +132,11 @@ my class Cool { # declared in BOOTSTRAP method chrs(Cool:D:) { self>>.chr.join; } + method ords(Cool:D:) { self.Str.ords } + method flip() { - nqp::p6box_s(nqp::flip(nqp::unbox_s(self.Str))) + self.Str.flip } method trans(*@a) { self.Str.trans(@a) } @@ -222,7 +220,6 @@ my class Cool { # declared in BOOTSTRAP $result; } - method ords(Cool:D:) { self.Str.ords } proto method split(|) {*} multi method split(Regex $pat, $limit = Inf, :$all) { self.Stringy.split($pat, $limit, :$all); diff --git a/src/core/Str.pm b/src/core/Str.pm index 8a9b1ed627a..8d2898f38dd 100644 --- a/src/core/Str.pm +++ b/src/core/Str.pm @@ -1107,7 +1107,7 @@ my class Str does Stringy { # declared in BOOTSTRAP has str $.unsubstituted_text; has str $.substituted_text; - + submethod BUILD(:$!source, :$!squash, :$!complement) { } method add_substitution($key, $value) { @@ -1443,15 +1443,20 @@ my class Str does Stringy { # declared in BOOTSTRAP }).join; } - method codes(Str:D:) returns Int:D { - nqp::p6box_i(nqp::chars(nqp::unbox_s(self))) - } - method path(Str:D:) returns IO::Path:D { DEPRECATED('IO', |<2014.11 2015.11>); IO::Path.new(self) } + proto method codes(|) { * } + multi method codes(Str:D:) returns Int:D { + nqp::p6box_i(nqp::chars(nqp::unbox_s(self))) + } + multi method codes(Str:U:) returns Int:D { + self.Str; # generate undefined warning + 0 + } + proto method chars(|) { * } multi method chars(Str:D:) returns Int:D { nqp::p6box_i(nqp::chars($!value)) @@ -1461,6 +1466,57 @@ my class Str does Stringy { # declared in BOOTSTRAP 0 } + proto method uc(|) { * } + multi method uc(Str:D:) { + nqp::p6box_s(nqp::uc($!value)); + } + multi method uc(Str:U:) { + self.Str; + } + + proto method lc(|) { * } + multi method lc(Str:D:) { + nqp::p6box_s(nqp::lc($!value)); + } + multi method lc(Str:U:) { + self.Str; + } + + proto method tc(|) { * } + multi method tc(Str:D:) { + nqp::p6box_s(nqp::uc(nqp::substr($!value,0,1)) ~ nqp::substr($!value,1)); + } + multi method tc(Str:U:) { + self.Str + } + + proto method tclc(|) { * } + multi method tclc(Str:D:) { + nqp::p6box_s(nqp::tclc($!value)) + } + multi method tclc(Str:U:) { + self.Str + } + + proto method flip(|) { * } + multi method flip(Str:D:) { + nqp::p6box_s(nqp::flip($!value)) + } + multi method flip(Str:U:) { + self.Str + } + + proto method ord(|) { * } + multi method ord(Str:D:) returns Int { + nqp::chars($!value) + ?? nqp::p6box_i(nqp::ord($!value)) + !! Int; + } + multi method ord(Str:U:) { + self.Str; + Int + } + } @@ -1713,7 +1769,7 @@ multi sub substr(Str() $what, \start, $want?) { sub substr-rw(\what, \start, $want?) is rw { my $Str := nqp::istype(what,Str) ?? what !! what.Str; - + # should really be int, but \ then doesn't work for rw access my $r := SUBSTR-SANITY($Str, start, $want, my Int $from, my Int $chars); $r.defined