String "dequote" in phobos?

Paul Backus snarwin at gmail.com
Thu May 13 14:20:53 UTC 2021


On Thursday, 13 May 2021 at 14:10:08 UTC, cc wrote:
> Does something to dequote (unquote? or what would you call it?) 
> a string exist in the standard library?  I didn't see one in 
> std.string, just wondering before reinventing the wheel.
>
> Something like:
> ```d
> assert(dequote(`"foo"`) == "foo");
> assert(dequote(`'foo'`) == "foo");
> assert(dequote(`"foo's"`) == "foo's");
> assert(dequote(`'foo "bar"'`) == `foo "bar"`);
> assert(dequote(`"fo\"o"`) == `fo"o`);
> dequote(`"fo"o"`); // bad quoting, maybe throw an exception 
> here or something?
> ```

I don't think there's anything like this in the standard library. 
If you write your own, consider publishing it on code.dlang.org.


More information about the Digitalmars-d-learn mailing list