bugGNU Octave - Bugs: bug #29987, strrep compatibility

 
 

bug #29987: strrep compatibility

Submitter:  John W. Eaton <jwe>
Submitted:  Sat 29 May 2010 01:21:10 AM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  highegg
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 02 Jun 2010 08:15:25 AM UTC, comment #3: 

Fixed by
http://hg.savannah.gnu.org/hgweb/octave/rev/21defab4207c

I also made both strfind and strrep recognize a bool "overlaps" option; I think that very often skipping overlaps is what you want.


Jaroslav Hajek <highegg>
Tue 01 Jun 2010 02:36:12 PM UTC, comment #2: 

I think the rule is that the full replacement string is inserted in the result string for each overlapping pattern match.  So your example produces "xyzxyz".

The Matlab docs say that strrep first gets a list of all the locations where the pattern matches (same as the strfind function).

John W. Eaton <jwe>
Group administrator
Tue 01 Jun 2010 05:57:17 AM UTC, comment #1: 

I don't think I understand how it works. Are the overlapping replacements overwritten over each other? What does strrep ("ababab", "abab", "xyz") return?

Jaroslav Hajek <highegg>
Sat 29 May 2010 01:21:10 AM UTC, original submission:  

Octave's strrep is incompatible with Matlab when there are overlapping patterns.  For example:

  Matlab> strrep(',0,0,',',0,',',,')
  ans = ,,,,
  Octave> strrep(',0,0,',',0,',',,')
  ans = ,,0,

The Matlab behavior is documented, so it seems that it is intentional.

It looks like the function to fix is qs_replace in src/DLD-FUNCTIONS/strfind.cc, but it is not clear to me exactly what the proper fix is.

John W. Eaton <jwe>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by highegg (Posted a comment)
  • -email is unavailable- added by jwe (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-06-02 highegg StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2010-06-01 highegg StatusNone Need Info
        Assigned toNone highegg

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code