You are here: PSPad forum > Bug report / Hlášení chyb > Re: Save ANSI file as UTF-8 doesn't work

Re: Save ANSI file as UTF-8 doesn't work

Goto Page: Previous1 2 3

#21 Re: 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 winking smiley
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)

Options: Reply | Quote | Up ^


#22 Re: Save ANSI file as UTF-8 doesn't work

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 winking smiley

I'm using Delphi 6 to develop my compiler. Modern Delphi versions are too complex and too bloated for system programming. smiling smiley

Options: Reply | Quote | Up ^


#23 Re: Save ANSI file as UTF-8 doesn't work

Posted by: Freeman | Date: 2015-03-29 15:23 | IP: IP Logged

Fixed in build 2656. Great work, Jan!

Options: Reply | Quote | Up ^


#24 Re: Save ANSI file as UTF-8 doesn't work

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.

Options: Reply | Quote | Up ^


#25 Re: Save ANSI file as UTF-8 doesn't work

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.

Options: Reply | Quote | Up ^


Goto Page: Previous1 2 3





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR