digitalmars.D - std.regex replaceFirst vs. replaceFirstInto
- Chris (19/19) May 21 2015 std.regex.replaceFirst uses
- Dmitry Olshansky (6/24) May 22 2015 Looks like a bug, no need to document this - please post it to bugzilla.
- Chris (2/45) May 22 2015 Ok. Do you have a link for me?
- Chris (2/49) May 22 2015 Excuse my ignorance, but how do I file a bug on bugzilla?
- Liam McSherry (2/3) May 22 2015 http://wiki.dlang.org/Get_involved#File_a_bug_report
- Chris (3/6) May 22 2015 Thanks. Here it is:
std.regex.replaceFirst uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L734 which returns the input, if no match is found. This is "safe", because the worst thing that can happen is that you get the input back unchanged. std.regex.replaceFirstInto, on the other hand, uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L700 which may throw an exception like this: phobos/std/regex/package.d(993): invalid submatch number 1* Shouldn't this be reflected in the documentation? At the moment, the documentation of replaceFirstInto says: "A variation on replaceFirst that instead of allocating a new string on each call outputs the result piece-wise to the sink." But it doesn't mention the difference in behavior (i.e. return input vs. exception). In other words, with replaceFirstInto, you have to make sure that you can indeed replace. The same probably goes for replaceAll / replaceAllInto. *Exception stems from https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L962
May 21 2015
On 21-May-2015 14:51, Chris wrote:std.regex.replaceFirst uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L734 which returns the input, if no match is found. This is "safe", because the worst thing that can happen is that you get the input back unchanged. std.regex.replaceFirstInto, on the other hand, uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L700 which may throw an exception like this: phobos/std/regex/package.d(993): invalid submatch number 1* Shouldn't this be reflected in the documentation? At the moment, the documentation of replaceFirstInto says: "A variation on replaceFirst that instead of allocating a new string on each call outputs the result piece-wise to the sink." But it doesn't mention the difference in behavior (i.e. return input vs. exception). In other words, with replaceFirstInto, you have to make sure that you can indeed replace. The same probably goes for replaceAll / replaceAllInto. *Exception stems from https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L962Looks like a bug, no need to document this - please post it to bugzilla. A simple test case would help fixing it. Thanks! -- Dmitry Olshansky
May 22 2015
On Friday, 22 May 2015 at 11:02:12 UTC, Dmitry Olshansky wrote:On 21-May-2015 14:51, Chris wrote:Ok. Do you have a link for me?std.regex.replaceFirst uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L734 which returns the input, if no match is found. This is "safe", because the worst thing that can happen is that you get the input back unchanged. std.regex.replaceFirstInto, on the other hand, uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L700 which may throw an exception like this: phobos/std/regex/package.d(993): invalid submatch number 1* Shouldn't this be reflected in the documentation? At the moment, the documentation of replaceFirstInto says: "A variation on replaceFirst that instead of allocating a new string on each call outputs the result piece-wise to the sink." But it doesn't mention the difference in behavior (i.e. return input vs. exception). In other words, with replaceFirstInto, you have to make sure that you can indeed replace. The same probably goes for replaceAll / replaceAllInto. *Exception stems from https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L962Looks like a bug, no need to document this - please post it to bugzilla. A simple test case would help fixing it. Thanks!
May 22 2015
On Friday, 22 May 2015 at 11:08:38 UTC, Chris wrote:On Friday, 22 May 2015 at 11:02:12 UTC, Dmitry Olshansky wrote:Excuse my ignorance, but how do I file a bug on bugzilla?On 21-May-2015 14:51, Chris wrote:Ok. Do you have a link for me?std.regex.replaceFirst uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L734 which returns the input, if no match is found. This is "safe", because the worst thing that can happen is that you get the input back unchanged. std.regex.replaceFirstInto, on the other hand, uses https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L700 which may throw an exception like this: phobos/std/regex/package.d(993): invalid submatch number 1* Shouldn't this be reflected in the documentation? At the moment, the documentation of replaceFirstInto says: "A variation on replaceFirst that instead of allocating a new string on each call outputs the result piece-wise to the sink." But it doesn't mention the difference in behavior (i.e. return input vs. exception). In other words, with replaceFirstInto, you have to make sure that you can indeed replace. The same probably goes for replaceAll / replaceAllInto. *Exception stems from https://github.com/D-Programming-Language/phobos/blob/master/std/regex/package.d#L962Looks like a bug, no need to document this - please post it to bugzilla. A simple test case would help fixing it. Thanks!
May 22 2015
On Friday, 22 May 2015 at 12:40:03 UTC, Chris wrote:Excuse my ignorance, but how do I file a bug on bugzilla?http://wiki.dlang.org/Get_involved#File_a_bug_report
May 22 2015
On Friday, 22 May 2015 at 12:47:18 UTC, Liam McSherry wrote:On Friday, 22 May 2015 at 12:40:03 UTC, Chris wrote:Thanks. Here it is: https://issues.dlang.org/show_bug.cgi?id=14615Excuse my ignorance, but how do I file a bug on bugzilla?http://wiki.dlang.org/Get_involved#File_a_bug_report
May 22 2015