www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - wstring double quotes to string double quotes

reply Joel <joelcnz gmail.com> writes:
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");
Apr 19 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
Apr 19 2018
parent reply Joel <joelcnz gmail.com> writes:
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.
Apr 19 2018
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Apr 19 2018
parent reply Joel <joelcnz gmail.com> writes:
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.
Apr 20 2018
next sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Apr 20 2018
prev sibling parent ag0aep6g <anonymous example.com> writes:
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.
Apr 20 2018