You are here: PSPad forum > Bug report / Hlášení chyb > Save ANSI file as UTF-8 doesn't work
Posted by: pspad | Date: 2015-03-21 20:09 | IP: IP Logged
OK Vladislav. I am in worst position than you, cause I use Delphi 7 only
I will system unicode encode/decode with your functions. As I tested the result is OK after you save file from PSPad. I got same result as you described (this one you call OK)
Posted by: Freeman | Date: 2015-03-21 20:43 | IP: IP Logged
pspad:OK Vladislav. I am in worst position than you, cause I use Delphi 7 only
I'm using Delphi 6 to develop my compiler. Modern Delphi versions are too complex and too bloated for system programming.
Posted by: Freeman | Date: 2015-03-29 15:23 | IP: IP Logged
Fixed in build 2656. Great work, Jan!
Posted by: Freeman | Date: 2015-04-04 17:55 | IP: IP Logged
Regarding to the topic.
MSDN:Windows XP and later: MB_ERR_INVALID_CHARS is the only dwFlags value supported by Code page 65001 (UTF-8).
So you can pass MB_ERR_INVALID_CHARS to our function and get the same behavior as from the Delphi built-in:
const
MB_ERR_INVALID_CHARS = 8;
function Utf8Decode(const Source: UTF8String): WideString; // my function
var
L: Integer;
Dest: WideString;
begin
L := Length(Source);
SetLength(Dest, L);
SetLength(Dest, MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, Pointer(Source), L, Pointer(Dest), L));
Result := Dest;
end;
begin
if Utf8Decode(Text) = '' then
// treat as ANSI
end;
This will work only since Windows XP and later, Windows 2000 requires dwFlags=0.
Posted by: pspad | Date: 2015-04-04 18:19 | IP: IP Logged
I know it Vladislav, but I wanted to let it try as it is - forced conversion. But I see there it causes problem to users and previous concept was better.
I will modify it into previous system - in case of wrong UTF-8 chars I will convert it as ANSI and will make a foce conversion only in case user will require it - change code page in menu format and reload.
Editor PSPad - freeware editor, © 2001 - 2025 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR