Unicode exception raise when replacing underscore with space

2015-01-13 Thread Nordlöw

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?


Re: Unicode exception raise when replacing underscore with space

2015-01-13 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 13 Jan 2015 12:32:15 +
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, `_`, ` `);



Re: Unicode exception raise when replacing underscore with space

2015-01-13 Thread Daniel Kozak via Digitalmars-d-learn

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);


Re: Unicode exception raise when replacing underscore with space

2015-01-13 Thread Nordlöw
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?