Bug Report - Regex.replace()

2 views
Skip to first unread message

Paul Nema

unread,
Nov 11, 2009, 11:14:43 AM11/11/09
to FalconPL
Documentation states (http://falconpl.org/project_docs/feathers/class_Regex.html#replace):
"The original string is untouched, and a new copy with the replaced value is returned."

Current version of .replace() changes the original string
See here:

Welcome to Falcon interactive mode.
Write statements directly at the prompt; when finished press CTRL+D to exit
>>> load regex
>>> str = 'abc:123:xyz'
: "abc:123:xyz"
>>> re = Regex(':')
: Regex(){ }
>>> replace = '$'       
: "$"
>>> new_str = re.replace(str, replace)
: "abc$123:xyz"
>>> > new_str
abc$123:xyz
>>> > str
abc$123:xyz
>>>

Original string "str" is changed from "abc:123:xyz" to "abc$123:xyz".  It should not be changed according to the documentation.

Thanks

Follow on Suggestion: Install a bug report tool to capture bugs plus all the associated tools to resolve a bug.

Paul Nema

unread,
Nov 11, 2009, 12:38:56 PM11/11/09
to FalconPL
OK, Patch developed on the #falcon IRC Channel:

Index: regex/regex_ext.cpp
===================================================================
--- regex/regex_ext.cpp    (Revision 315)
+++ regex/regex_ext.cpp    (Arbeitskopie)
@@ -694,8 +694,9 @@
          .extra( errVal ) );
    }
 
-   source->change( data->m_ovector[0], data->m_ovector[1], *dest );
-   vm->retval( source );
+   CoreString* ret = new CoreString(*source);
+   ret->change( data->m_ovector[0], data->m_ovector[1], *dest );
+   vm->retval( ret );
 }
 
Tested and svn'ed into the code base
Reply all
Reply to author
Forward
0 new messages