Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 13, 2015 Unicode exception raise when replacing underscore with space | ||||
---|---|---|---|---|
| ||||
I get core.exception.UnicodeException@src/rt/util/utf.d(290): in a call to std.string.tr(x, `_`, ` `) for a badly encode string x. Is it really needed to do auto-decoding here? Isn't the encoding of underscore and space uniquely one by byte in UTF-8? What do I need to do/add to avoid auto-decoding here? |
January 13, 2015 Re: Unicode exception raise when replacing underscore with space | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | V Tue, 13 Jan 2015 12:32:15 +0000 "Nordlöw" via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> napsáno: > I get > > core.exception.UnicodeException@src/rt/util/utf.d(290): > > in a call to > > std.string.tr(x, `_`, ` `) > > for a badly encode string x. Is it really needed to do auto-decoding here? > > Isn't the encoding of underscore and space uniquely one by byte in UTF-8? > > What do I need to do/add to avoid auto-decoding here? std.array.replace(x, `_`, ` `); |
January 13, 2015 Re: Unicode exception raise when replacing underscore with space | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozák | On Tuesday, 13 January 2015 at 13:01:56 UTC, Daniel Kozák via Digitalmars-d-learn wrote:
>> What do I need to do/add to avoid auto-decoding here?
>
> std.array.replace(x, `_`, ` `);
Thanks! What about adding See alsos in the docs that relate these two with respect to auto-decoding?
|
January 13, 2015 Re: Unicode exception raise when replacing underscore with space | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Tuesday, 13 January 2015 at 20:30:16 UTC, Nordlöw wrote: > On Tuesday, 13 January 2015 at 13:01:56 UTC, Daniel Kozák via Digitalmars-d-learn wrote: >>> What do I need to do/add to avoid auto-decoding here? >> >> std.array.replace(x, `_`, ` `); > > Thanks! What about adding See alsos in the docs that relate these two with respect to auto-decoding? I am not sure, it doesn`t exactly do the same. And to be fair std.array.replace use internaly std.algorithm.find which use in some scenario auto-decoding. So to be sure no autodecoding occured you must used something like that: string x = "some_text"; auto res = std.array.replace(cast(byte[])x, [byte('_')], [byte(' ')]); writeln(cast(string)res); |
Copyright © 1999-2021 by the D Language Foundation