bugGNU Octave - Bugs: bug #47403, 'strsplit' function doesn't work...

 
 

bug #47403: 'strsplit' function doesn't work with delimiter '+'

Submitter:  Luis Mendo <lmendo>
Submitted:  Mon 14 Mar 2016 01:29:33 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  lachlan
Originator Name:  Luis Mendo Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 16 Mar 2016 04:19:05 AM UTC, comment #5: 

I checked ostrsplit and it produces the same results as when CollapseDelimiters is false.  When run with that option set the other way it swallows the last term, which is different than strsplit.


ostrsplit('a+bb++ccd+a++', '+',true)
ans =
{
  [1,1] = a
  [1,2] = bb
  [1,3] = ccd
  [1,4] = a
}


I modified the patch because the '+' character is inside of a character class expression and doesn't need backslash escaping.  The cset is here http://hg.savannah.gnu.org/hgweb/octave/rev/04e0598f8b94.

Marking as fixed and cloing report.

Rik <rik5>
Group administrator
Tue 15 Mar 2016 07:42:37 PM UTC, comment #4: 

Can you please also check + if needed patch ostrsplit.m ?

Philip Nienhuis <philipnienhuis>
Group Member
Tue 15 Mar 2016 08:05:17 AM UTC, comment #3: 

The attached changeset has a test for '+'.

I also did a test of all ASCII delimiters (32-127), which passes.  Should I put that in the automated tests?

(file #36642)

Lachlan Andrew <lachlan>
Mon 14 Mar 2016 11:39:42 PM UTC, comment #2: 

Can one of you add a test case to strsplit.m for this bug?

Mike Miller <mtmiller>
Group Member
Mon 14 Mar 2016 11:19:05 AM UTC, comment #1: 

Thanks, Luis.

I'm attaching a changeset based on your file.

(file #36631)

Lachlan Andrew <lachlan>
Mon 14 Mar 2016 01:29:33 AM UTC, original submission:  

The following produces an error


strsplit('a+bb++ccd+a++', '+')


instead of the correct result, which is


ans =
{
  [1,1] = a
  [1,2] = bb
  [1,3] = ccd
  [1,4] = a
  [1,5] =
}


The problem seems to be that line 199 of 'strsplit.m'


## Escape characters which have a special meaning in regexp.
del = regexprep (del, '([{}()[\]^$.*?|\\])', '\\$1');


doesn't escape '+' (it does escape other characters).

The solution is simply to add '\+' (escaped) to the regexp in that line, so that '+' also gets escaped:


## Escape characters which have a special meaning in regexp.
del = regexprep (del, '([{}()[\]^$.*?|\\\+])', '\\$1');


I attach the modified file. It seems to work correctly, also with the 'CollapseDelimiters' option:


>> strsplit_modified('a+bb++ccd+a++', '+', 'CollapseDelimiters', false)
ans =
{
  [1,1] = a
  [1,2] = bb
  [1,3] =
  [1,4] = ccd
  [1,5] = a
  [1,6] =
  [1,7] =
}



Luis Mendo <lmendo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #36631:  bug_47403_strsplit.cset added by lachlan (876B - text/x-diff)
file #36627:  strsplit_modified.m added by lmendo (11KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by lachlan (Updated the item)
  • -email is unavailable- added by lmendo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-03-16 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2016-03-15 lachlan Attached File- Added bug_47403_strsplit.v1.cset, #36642
    2016-03-14 lachlan Attached File- Added bug_47403_strsplit.cset, #36631
        StatusNone Patch Submitted
        Assigned toNone lachlan
    2016-03-14 lmendo Attached File- Added strsplit_modified.m, #36627

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code