Thread overview
std.regex replaceFirst vs. replaceFirstInto
May 21, 2015
Chris
May 22, 2015
Dmitry Olshansky
May 22, 2015
Chris
May 22, 2015
Chris
May 22, 2015
Liam McSherry
May 22, 2015
Chris
May 21, 2015
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 22, 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#L962
>

Looks 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:
>> 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
>>
>
> Looks like a bug, no need to document this - please post it to bugzilla.
> A simple test case would help fixing it.
>
> Thanks!

Ok. Do you have a link for me?
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:
>> 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#L962
>>>
>>
>> Looks like a bug, no need to document this - please post it to bugzilla.
>> A simple test case would help fixing it.
>>
>> Thanks!
>
> Ok. Do you have a link for me?

Excuse my ignorance, but how do I file a bug on bugzilla?
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:
>> Excuse my ignorance, but how do I file a bug on bugzilla?
>
> http://wiki.dlang.org/Get_involved#File_a_bug_report

Thanks. Here it is:

https://issues.dlang.org/show_bug.cgi?id=14615