Just staring at the code, I'm guessing the issue is on line 752-753 of
  https://github.com/chapel-lang/chapel/blob/master/
modules/internal/String.chpl

If the last character is the start of a chunk, then yieldChunk is not set,
and the loop ends, without returning the character.

I *think* putting in a check to see if chunkStart==localThis.len and
setting chunk and yieldChunk if true should work.

-- Nikhil

---------------------------------
Nikhil Padmanabhan
[email protected]

On Thu, Mar 16, 2017 at 4:18 PM, Brad Chamberlain <[email protected]> wrote:

>
> Hi --
>
> I strongly suspect that you aren't running into anything more subtle than
> a bug in split()'s implementation -- probably an off-by-one issue, though
> someone with more knowledge of the routines may correct me if I'm wrong.
>
> The routines are defined in modules/internal/String.chpl (search on 'iter
> split()') if you're interested in seeing if you can find+fix the bug
> yourself.  If not, and you'd be willing to file a bug report as a GitHub
> issue, that would be terrific.
>
> -Brad
>
>
> On Thu, 16 Mar 2017, Takeshi Yamamoto wrote:
>
> > Hello,
> >
> > While I'm learning the basics of Chapel, I have come across
> > the following case where split() seems to give an unexpected result:
> >
> > proc test()
> > {
> >    var a = "apple orange grape";   // OK
> >    // var a = "apple orange g";   // NG
> >
> >    writeln( "a = ", a );
> >    writeln( "a.split() = ", a.split() );
> >
> >    var b = a.split();
> >
> >    for i in 1 .. b.size {
> >        writeln( "b[", i, "]:", b[ i ] );
> >    }
> > }
> >
> > test();
> >
> > The above code gives
> >
> > a = apple orange grape
> > a.split() = apple orange grape
> > b[1]:apple
> > b[2]:orange
> > b[3]:grape
> >
> > which is my expected result. On the other hand,
> > if I comment the line with "OK" and uncomment the line
> > with "NG", then I get the following result:
> >
> > a = apple orange g
> > a.split() = apple orange
> > b[1]:apple
> > b[2]:orange
> >
> > That is, split() neglects the last "g" in the string a.
> >
> > I tried other patters also, and it seems that if the last word
> > in a string is only a single character, then split() neglects
> > it for some reason.
> >
> > # Also, if the string has \n at the end (e.g., a = ""apple orange g\n"),
> > # I get the expected result again.
> >
> > Is this an expected behavior of split(), or possibly a compiler issue...?
> >
> > PS. Also, I'm sorry if I'm making some big (or basic) mistake about
> > the usage of strings.
> >
> > My best regards,
> > Takeshi Yamamoto
> >
> > ------------------------------------------------------------
> ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Chapel-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/chapel-users
> >
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Chapel-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/chapel-users
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to