std.regex replaceFirst vs. replaceFirstInto
Chris via Digitalmars-d
digitalmars-d at puremagic.com
Fri May 22 04:08:37 PDT 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?
More information about the Digitalmars-d
mailing list