From 13c7ef0eb71ff1d4ada353575e6fc43a840a060f Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 1 Oct 2022 20:38:17 -0400 Subject: [PATCH] use replacement char instead of nothing in lossy read --- characterencodings.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/characterencodings.d b/characterencodings.d index 7fc56d5..96f7d29 100644 --- a/characterencodings.d +++ b/characterencodings.d @@ -47,6 +47,8 @@ import std.string; import std.array; import std.conv; +// FIXME: use replacement char here instead + /// Like convertToUtf8, but if the encoding is unknown, it just strips all chars > 127 and calls it done instead of throwing string convertToUtf8Lossy(immutable(ubyte)[] data, string dataCharacterEncoding) { try { @@ -59,6 +61,8 @@ string convertToUtf8Lossy(immutable(ubyte)[] data, string dataCharacterEncoding) foreach(b; data) if(b < 128) ret ~= b; + else + ret ~= '\uFFFD'; return ret; } }