https://issues.dlang.org/show_bug.cgi?id=15710

Seb <greensunn...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |bootcamp
                 CC|                            |greensunn...@gmail.com

--- Comment #1 from Seb <greensunn...@gmail.com> ---
Yeah, I would be really cool if I don't have to do such ugly hacks when I just
want to handle invalid UTF.

---
private string toValidUTF(string s)
{
        import std.algorithm.iteration : map;
        import std.range : iota;
        import std.utf;
        return s.representation.length
                .iota
                .map!(i => s.decode!(UseReplacementDchar.yes)(i))
                .toUTF8;
}

try {
        outStream.validate;
} catch (UTFException) {
        outStream = outStream.toValidUTF;
}
---

--

Reply via email to