Thread overview
wstring double quotes to string double quotes
Apr 19, 2018
Joel
Apr 19, 2018
Adam D. Ruppe
Apr 19, 2018
Joel
Apr 20, 2018
Jonathan M Davis
Apr 20, 2018
Joel
Apr 20, 2018
Jonathan M Davis
Apr 20, 2018
ag0aep6g
April 19, 2018
I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes).

The following code crashes with an array.d(2211): Range violation error:

import std.conv : to;
import std.string : replace;

auto sourceTxtW = sourceTxt.to!wstring;
sourceTxtW.replace("”", `"`);
auto sourceTxtR = sourceTxtW.to!string;
sourceLines = sourceTxtR.split("\n");
April 19, 2018
On Thursday, 19 April 2018 at 21:53:52 UTC, Joel wrote:
> I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes).

quotes are quotes, you don't need to convert to wstring here.

I really don't think it should be throwing that error regardless... but you also should be able to just do

string[] sourceLines = sourceTxt.replace("”", `"`).split("\n");

and skip the wstring part entirely.
April 19, 2018
On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe wrote:
> On Thursday, 19 April 2018 at 21:53:52 UTC, Joel wrote:
>> I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes).
>
> quotes are quotes, you don't need to convert to wstring here.
>
> I really don't think it should be throwing that error regardless... but you also should be able to just do
>
> string[] sourceLines = sourceTxt.replace("”", `"`).split("\n");
>
> and skip the wstring part entirely.

That worked! Thanks Adam.
April 19, 2018
On Thursday, April 19, 2018 23:24:05 Joel via Digitalmars-d-learn wrote:
> On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe wrote:
> > On Thursday, 19 April 2018 at 21:53:52 UTC, Joel wrote:
> >> I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes).
> >
> > quotes are quotes, you don't need to convert to wstring here.
> >
> > I really don't think it should be throwing that error regardless... but you also should be able to just do
> >
> > string[] sourceLines = sourceTxt.replace("”", `"`).split("\n");
> >
> > and skip the wstring part entirely.
>
> That worked! Thanks Adam.

Given that these functions really shouldn't be throw RangeErrors, please create a bug report with example code that can someone can just run to reproduce the issue (your example isn't runnable as-is). That way, the bug can be fixed. Otherwise, it's probably just going to be lost, and someone else may hit it in the future. Thanks.

https://issues.dlang.org

- Jonathan M Davis


April 20, 2018
On Friday, 20 April 2018 at 02:46:14 UTC, Jonathan M Davis wrote:
> On Thursday, April 19, 2018 23:24:05 Joel via Digitalmars-d-learn wrote:
>> On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe wrote:
>> > [...]
>>
>> That worked! Thanks Adam.
>
> Given that these functions really shouldn't be throw RangeErrors, please create a bug report with example code that can someone can just run to reproduce the issue (your example isn't runnable as-is). That way, the bug can be fixed. Otherwise, it's probably just going to be lost, and someone else may hit it in the future. Thanks.
>
> https://issues.dlang.org
>
> - Jonathan M Davis

Done.
April 20, 2018
On Friday, April 20, 2018 07:45:14 Joel via Digitalmars-d-learn wrote:
> On Friday, 20 April 2018 at 02:46:14 UTC, Jonathan M Davis wrote:
> > On Thursday, April 19, 2018 23:24:05 Joel via
> >
> > Digitalmars-d-learn wrote:
> >> On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe
> >>
> >> wrote:
> >> > [...]
> >>
> >> That worked! Thanks Adam.
> >
> > Given that these functions really shouldn't be throw RangeErrors, please create a bug report with example code that can someone can just run to reproduce the issue (your example isn't runnable as-is). That way, the bug can be fixed. Otherwise, it's probably just going to be lost, and someone else may hit it in the future. Thanks.
> >
> > https://issues.dlang.org
> >
> > - Jonathan M Davis
>
> Done.

Thanks!

- Jonathan M Davis

April 20, 2018
On 04/20/2018 09:45 AM, Joel wrote:
> On Friday, 20 April 2018 at 02:46:14 UTC, Jonathan M Davis wrote:
[...]
>> please create a bug report
[...]
> Done.

For reference, that was <https://issues.dlang.org/show_bug.cgi?id=18783>.

But someone else was faster and filed <https://issues.dlang.org/show_bug.cgi?id=18781> without giving notice here.