<div dir="ltr">I keep running into issues due to auto-decoding (arguably a significant design flaw of phobos) when using strings from external sources (which may not be 100% valid UTF8) eg see stracktrace [1] on getSomeExternalString().splitLines, <br><br>Could we have something like `sanitizeUTF` in std.utf, to allow for a simple fix when running into such UTF8 issues see proposal implementation [2]; the fix would then be:<br>```<br>getSomeExternalString().splitLines, <br>=><br>getSomeExternalString().sanitizeUTF.splitLines, <br>```<br><div><br></div><div><br></div><div>[1] <br><div>core.exception.AssertError@std/utf.d(2254): Assertion failure</div><div>----------------</div><div>??:? _d_assert [0x4f4e63]</div><div>??:? void std.utf.__assert(int) [0x53a304]</div><div>??:? pure nothrow @nogc @safe ubyte std.utf.codeLength!(char).codeLength(dchar) [0xa5d78191]</div><div>??:? pure nothrow @nogc @safe int std.string.stripRight!(immutable(char)[]).stripRight(immutable(char)[]).__foreachbody2(ref ulong, ref dchar) [0xa5c42bd9]</div><div>??:? _aApplyRcd2 [0x4f9bd1]</div><div>??:? pure @nogc @safe immutable(char)[] std.string.stripRight!(immutable(char)[]).stripRight(immutable(char)[]) [0xa5c42b5c]</div><div>??:? pure @property @nogc @safe immutable(char)[] std.algorithm.iteration.stripRight.MapResult.front() [0xa5cda053]</div><div>??:? pure @safe immutable(char)[] std.array.join!(std.algorithm.iteration.stripRight.MapResult, immutable(char)[]).join(std.algorithm.iteration.stripRight.MapResult, immutable(char)[]) [0xa5cda39a]</div></div><div><br></div><div><br></div><div>[2] sanitizeUTF proposal:<br>// TODO: rangeify to make it work in more situations<br><div>string sanitizeUTF(string a){</div><div>  import std.utf;</div><div>  Appender!string b;</div><div>  while(a.length){</div><div>    b~=decodeFront!(Yes.useReplacementDchar)(a);</div><div>  }</div><div>  return b.data;</div><div>}</div></div><div><br></div></div>