std.utf.decode behaves unexpectedly - Bug?
BBaz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 6 11:59:08 PST 2015
On Friday, 6 November 2015 at 19:26:50 UTC, HeiHon wrote:
> Am I using std.utf.decode wrongly or is it buggy?
It's obviously used wrongly, try this instead:
import std.utf, std.stdio;
---
dstring do_decode(string txt)
{
dstring result;
try
{
size_t idx;
writeln("decode ", txt);
while (true)
{
result ~= std.utf.decode(txt, idx);
if (idx == txt.length) break;
}
}
catch(Exception e)
{
writeln(e.msg, " file=", e.file, " line=", e.line);
}
return result;
}
void main()
{
writeln(do_decode("abc"));
writeln(do_decode("Ã¥bc"));
writeln(do_decode("aåb"));
}
More information about the Digitalmars-d-learn
mailing list