Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.split doesn't include an empty string before a first literal zero-length string in Rakudo #2759

Closed
p6rt opened this issue May 11, 2012 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 11, 2012

Migrated from rt.perl.org#112868 (status was 'resolved')

Searchable as RT112868$

@p6rt
Copy link
Author

p6rt commented May 11, 2012

From @masak

<sisar> n​: my $a = 'abc'; my @​rray = $a.split(''); say @​rray[0]; say @​rray[1];
<p6eval> niecza v17-4-ge5b869e​: OUTPUT«␤a␤»
<sisar> r​: my $a = 'abc'; my @​rray = $a.split(''); say @​rray[0]; say @​rray[1];
<p6eval> rakudo 372e6b​: OUTPUT«a␤b␤»
<sisar> ^^ when i spilt 'abc' with '' as delimiter, the first element
is 'a' right?
<TimToady> no, there's a '' on the front
<TimToady> use .comb to do that
<sisar> oh so its a rakudobug ?
<sisar> & not nieczabug ?
<TimToady> arguably niecza is more consistent with how /''/ would split
<sisar> masak​: would you be so kind to report this rakudobug?
<TimToady> p6​: my $a = 'abc'; my @​rray = $a.split(/''/); say @​rray[0];
say @​rray[1];
<p6eval> ..rakudo 372e6b, niecza v17-4-ge5b869e​: OUTPUT«␤a␤»
<TimToady> they both think there's a null string in that case before
the first empty match
* masak submits rakudobug
<TimToady> so I'd argue for consistency, especially when .comb is available
<sisar> masak++

@p6rt
Copy link
Author

p6rt commented May 14, 2012

From @kyleha

I've added a test in S32-str/split-simple.t

@p6rt
Copy link
Author

p6rt commented May 14, 2012

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Mar 29, 2014

From @coke

On Mon May 14 08​:26​:13 2012, KyleHa wrote​:

I've added a test in S32-str/split-simple.t

Here's a patch​:

Inline Patch
diff --git a/src/core/Str.pm b/src/core/Str.pm
index c81f371..629d2ae 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -719,7 +719,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
         my $done = 0;
         if $match-string eq "" {
             my $chars = self.chars;
-            map {
+            ("", (map {
                 last if $done;

                 if --$chars and --$l {
@@ -729,7 +729,9 @@ my class Str does Stringy { # declared in BOOTSTRAP
                     $done = 1;
                     self.substr($c);
                 }
-            }, 1 .. $l;
+            }, 1 .. $l
+            ), "").flat
+
         }
         else {
             my $width = $match-string.chars;

But this causes several tests to fail, most of which anticipate that there is no leading or trailing empty string. \-\- Will "Coke" Coleda

1 similar comment
@p6rt
Copy link
Author

p6rt commented Mar 29, 2014

From @coke

On Mon May 14 08​:26​:13 2012, KyleHa wrote​:

I've added a test in S32-str/split-simple.t

Here's a patch​:

Inline Patch
diff --git a/src/core/Str.pm b/src/core/Str.pm
index c81f371..629d2ae 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -719,7 +719,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
         my $done = 0;
         if $match-string eq "" {
             my $chars = self.chars;
-            map {
+            ("", (map {
                 last if $done;

                 if --$chars and --$l {
@@ -729,7 +729,9 @@ my class Str does Stringy { # declared in BOOTSTRAP
                     $done = 1;
                     self.substr($c);
                 }
-            }, 1 .. $l;
+            }, 1 .. $l
+            ), "").flat
+
         }
         else {
             my $width = $match-string.chars;

But this causes several tests to fail, most of which anticipate that there is no leading or trailing empty string. \-\- Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Jul 18, 2015

From @perlpilot

Unfortunately, this patch does not work with the $limit parameter specified. But ...

Fixed in rakudo/rakudo@4b5e196

-Scott

On Sat Mar 29 14​:23​:40 2014, coke wrote​:

On Mon May 14 08​:26​:13 2012, KyleHa wrote​:

I've added a test in S32-str/split-simple.t

Here's a patch​:

diff --git a/src/core/Str.pm b/src/core/Str.pm
index c81f371..629d2ae 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@​@​ -719,7 +719,7 @​@​ my class Str does Stringy { # declared in
BOOTSTRAP
my $done = 0;
if $match-string eq "" {
my $chars = self.chars;
- map {
+ ("", (map {
last if $done;

if --$chars and --$l {
@​@​ -729,7 +729,9 @​@​ my class Str does Stringy { # declared in
BOOTSTRAP
$done = 1;
self.substr($c);
}
- }, 1 .. $l;
+ }, 1 .. $l
+ ), "").flat
+
}
else {
my $width = $match-string.chars;

But this causes several tests to fail, most of which anticipate that
there is no leading or trailing empty string.

--
perlpilot

@p6rt
Copy link
Author

p6rt commented Jul 20, 2015

@perlpilot - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 20, 2015
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant