Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename Str.parse-names to Str.uniparse
The original name was chosen to align with `.parse-base` that parses out
base-X numbers out strings. However, we have a whole block of more closely
related routines all named in `.uni*` format, so it makes sense for this
routine's naming to align with those. They are: `infix:<unicmp>`,
`unimatch`, `uniname`, `uninames`, `unival`, `univals`, `uniprop`,
`uniprop-bool`, `uniprop-int`, `uniprop-str`, `uniprops`.

Refs:
Raku/6.d-prep@efa24f6
https://irclog.perlgeek.de/perl6-dev/2017-12-21#i_15609653
  • Loading branch information
zoffixznet committed Dec 22, 2017
1 parent e5c38ad commit 2a8287c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
49 changes: 29 additions & 20 deletions src/core/Str.pm
Expand Up @@ -1410,24 +1410,6 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}

method parse-names(Str:D:) {
my \names := nqp::split(',', self);
my int $elems = nqp::elems(names);
my int $i = -1;
my str $res = '';
nqp::while(
nqp::islt_i( ($i = nqp::add_i($i,1)), $elems ),
($res = nqp::concat($res,
nqp::unless(
nqp::getstrfromname(nqp::atpos(names, $i).trim),
X::Str::InvalidCharName.new(
:name(nqp::atpos(names, $i).trim)
).fail
))),
);
$res
}

multi method split(Str:D: Regex:D $pat, $limit is copy = Inf;;
:$v is copy, :$k, :$kv, :$p, :$skip-empty) {

Expand Down Expand Up @@ -2607,6 +2589,29 @@ my class Str does Stringy { # declared in BOOTSTRAP
LSM.new(self,$substitutions,$squash,$complement).result;
}
}

method parse-names(Str:D:) {
# XXX TODO: issue deprecation warning in 6.d; remove in 6.e
self.uniparse
}
method uniparse(Str:D:) {
my \names := nqp::split(',', self);
my int $elems = nqp::elems(names);
my int $i = -1;
my str $res = '';
nqp::while(
nqp::islt_i( ($i = nqp::add_i($i,1)), $elems ),
($res = nqp::concat($res,
nqp::unless(
nqp::getstrfromname(nqp::atpos(names, $i).trim),
X::Str::InvalidCharName.new(
:name(nqp::atpos(names, $i).trim)
).fail
))),
);
$res
}

proto method indent($) {*}
# Zero indent does nothing
multi method indent(Int() $steps where { $_ == 0 }) {
Expand Down Expand Up @@ -3020,8 +3025,6 @@ sub chrs(*@c --> Str:D) {
proto sub parse-base(|) {*}
multi sub parse-base(Str:D $str, Int:D $radix) { $str.parse-base($radix) }

sub parse-names(Str:D $str) { $str.parse-names }

proto sub substr(|) {*}
multi sub substr(Str:D \what, Int:D \start) {
my str $str = nqp::unbox_s(what);
Expand Down Expand Up @@ -3111,4 +3114,10 @@ multi sub infix:<eqv>(Str:D \a, Str:D \b) {
proto sub samemark(|) {*}
multi sub samemark($s, $pat) { $s.samemark($pat) }

sub parse-names(Str:D \names) {
# XXX TODO: issue deprecation warning in 6.d; remove in 6.e
names.uniparse
}
sub uniparse (Str:D \names) { names.uniparse }

# vim: ft=perl6 expandtab sw=4
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -1143,7 +1143,6 @@ S32-str/numeric.t
S32-str/ords.t
S32-str/pack.t
S32-str/parse-base.t
S32-str/parse-names.t
S32-str/pos.t
S32-str/rindex.t
S32-str/samemark.t
Expand All @@ -1160,6 +1159,7 @@ S32-str/tc.t
S32-str/tclc.t
S32-str/trim.t
S32-str/uc.t
S32-str/uniparse.t
S32-str/unpack.t
S32-str/utf8-c8.t # moar
S32-str/words.t
Expand Down

0 comments on commit 2a8287c

Please sign in to comment.