Стартовый пул
This commit is contained in:
136
SynEditEx/data/synex_charset.pas
Normal file
136
SynEditEx/data/synex_charset.pas
Normal file
@@ -0,0 +1,136 @@
|
||||
unit synex_charset;
|
||||
{$mode delphi}
|
||||
{$codepage UTF8}
|
||||
interface
|
||||
uses Classes, SysUtils, lconvencoding;
|
||||
type
|
||||
TTextCharset = (
|
||||
tcUnknown, tcUTF8, tcUTF8BOM, tcISO_8859_1, tcISO_8859_2, tcCP1250, tcCP1251, tcCP1252, tcCP1253,
|
||||
tcCP1254, tcCP1255, tcCP1256, tcCP1257, tcCP1258, tcCP437, tcCP850, tcCP852, tcCP866, tcCP874,
|
||||
tcKOI8, tcUCS2LE, tcUCS2BE, tcCP936, tcCP950, tcCP949, tcCP932
|
||||
);
|
||||
{stdcalls}
|
||||
function GetTextCharset (const AText: String): TTextCharset; STDCALL;
|
||||
function ConvertToUtf8 (const AText: String; const AEncoding: TTextCharset): String; STDCALL;
|
||||
function ConvertFromUtf8 (const AText: String; const AEncoding: TTextCharset): String; STDCALL;
|
||||
implementation
|
||||
function GetTextCharset (const AText: String): TTextCharset;
|
||||
var cur_charst: String;
|
||||
begin
|
||||
Result:= tcUnknown;
|
||||
cur_charst:= lowerCase(GuessEncoding(AText));
|
||||
if cur_charst = 'utf8' then
|
||||
Result:= tcUTF8;
|
||||
if cur_charst = 'utf8bom' then
|
||||
Result:= tcUTF8BOM;
|
||||
if cur_charst = 'iso_8859_1' then
|
||||
Result:= tcISO_8859_1;
|
||||
if cur_charst = 'iso_8859_2' then
|
||||
Result:= tcISO_8859_2;
|
||||
if cur_charst = 'cp1250' then
|
||||
Result:= tcCP1250;
|
||||
if cur_charst = 'cp1251' then
|
||||
Result:= tcCP1251;
|
||||
if cur_charst = 'cp1252' then
|
||||
Result:= tcCP1252;
|
||||
if cur_charst = 'cp1253' then
|
||||
Result:= tcCP1253;
|
||||
if cur_charst = 'cp1254' then
|
||||
Result:= tcCP1254;
|
||||
if cur_charst = 'cp1255' then
|
||||
Result:= tcCP1255;
|
||||
if cur_charst = 'cp1256' then
|
||||
Result:= tcCP1256;
|
||||
if cur_charst = 'cp1257' then
|
||||
Result:= tcCP1257;
|
||||
if cur_charst = 'cp1258' then
|
||||
Result:= tcCP1258;
|
||||
if cur_charst = 'cp437' then
|
||||
Result:= tcCP437;
|
||||
if cur_charst = 'cp850' then
|
||||
Result:= tcCP850;
|
||||
if cur_charst = 'cp852' then
|
||||
Result:= tcCP852;
|
||||
if cur_charst = 'cp866' then
|
||||
Result:= tcCP866;
|
||||
if cur_charst = 'cp874' then
|
||||
Result:= tcCP874;
|
||||
if cur_charst = 'koi8' then
|
||||
Result:= tcKOI8;
|
||||
if cur_charst = 'ucs2le' then
|
||||
Result:= tcUCS2LE;
|
||||
if cur_charst = 'ucs2be' then
|
||||
Result:= tcUCS2BE;
|
||||
if cur_charst = 'cp936' then
|
||||
Result:= tcCP936;
|
||||
if cur_charst = 'cp950' then
|
||||
Result:= tcCP950;
|
||||
if cur_charst = 'cp949' then
|
||||
Result:= tcCP949;
|
||||
if cur_charst = 'cp932' then
|
||||
Result:= tcCP932;
|
||||
end;
|
||||
function ConvertToUtf8 (const AText: String; const AEncoding: TTextCharset): String;
|
||||
begin
|
||||
case AEncoding of
|
||||
tcUTF8BOM: Result:= UTF8BOMToUTF8(AText);
|
||||
tcISO_8859_1: Result:= ISO_8859_1ToUTF8(AText);
|
||||
tcISO_8859_2: Result:= ISO_8859_2ToUTF8(AText);
|
||||
tcCP1250: Result:= CP1250ToUTF8(AText);
|
||||
tcCP1251: Result:= CP1251ToUTF8(AText);
|
||||
tcCP1252: Result:= CP1252ToUTF8(AText);
|
||||
tcCP1253: Result:= CP1253ToUTF8(AText);
|
||||
tcCP1254: Result:= CP1254ToUTF8(AText);
|
||||
tcCP1255: Result:= CP1255ToUTF8(AText);
|
||||
tcCP1256: Result:= CP1256ToUTF8(AText);
|
||||
tcCP1257: Result:= CP1257ToUTF8(AText);
|
||||
tcCP1258: Result:= CP1258ToUTF8(AText);
|
||||
tcCP437: Result:= CP437ToUTF8(AText);
|
||||
tcCP850: Result:= CP850ToUTF8(AText);
|
||||
tcCP852: Result:= CP852ToUTF8(AText);
|
||||
tcCP866: Result:= CP866ToUTF8(AText);
|
||||
tcCP874: Result:= CP874ToUTF8(AText);
|
||||
tcKOI8: Result:= KOI8ToUTF8(AText);
|
||||
tcUCS2LE: Result:= UCS2LEToUTF8(AText);
|
||||
tcUCS2BE: Result:= UCS2BEToUTF8(AText);
|
||||
tcCP936: Result:= CP936ToUTF8(AText);
|
||||
tcCP950: Result:= CP950ToUTF8(AText);
|
||||
tcCP949: Result:= CP949ToUTF8(AText);
|
||||
tcCP932: Result:= CP932ToUTF8(AText);
|
||||
else
|
||||
Result:= AText;
|
||||
end;
|
||||
end;
|
||||
function ConvertFromUtf8 (const AText: String; const AEncoding: TTextCharset): String;
|
||||
begin
|
||||
case AEncoding of
|
||||
tcUTF8BOM: Result:= UTF8ToUTF8BOM(AText);
|
||||
tcISO_8859_1: Result:= UTF8ToISO_8859_1(AText);
|
||||
tcISO_8859_2: Result:= UTF8ToISO_8859_2(AText);
|
||||
tcCP1250: Result:= UTF8ToCP1250(AText);
|
||||
tcCP1251: Result:= UTF8ToCP1251(AText);
|
||||
tcCP1252: Result:= UTF8ToCP1252(AText);
|
||||
tcCP1253: Result:= UTF8ToCP1253(AText);
|
||||
tcCP1254: Result:= UTF8ToCP1254(AText);
|
||||
tcCP1255: Result:= UTF8ToCP1255(AText);
|
||||
tcCP1256: Result:= UTF8ToCP1256(AText);
|
||||
tcCP1257: Result:= UTF8ToCP1257(AText);
|
||||
tcCP1258: Result:= UTF8ToCP1258(AText);
|
||||
tcCP437: Result:= UTF8ToCP437(AText);
|
||||
tcCP850: Result:= UTF8ToCP850(AText);
|
||||
tcCP852: Result:= UTF8ToCP852(AText);
|
||||
tcCP866: Result:= UTF8ToCP866(AText);
|
||||
tcCP874: Result:= UTF8ToCP874(AText);
|
||||
tcKOI8: Result:= UTF8ToKOI8(AText);
|
||||
tcUCS2LE: Result:= UTF8ToUCS2LE(AText);
|
||||
tcUCS2BE: Result:= UTF8ToUCS2BE(AText);
|
||||
tcCP936: Result:= UTF8ToCP936(AText);
|
||||
tcCP950: Result:= UTF8ToCP950(AText);
|
||||
tcCP949: Result:= UTF8ToCP949(AText);
|
||||
tcCP932: Result:= UTF8ToCP932(AText);
|
||||
else
|
||||
Result:= AText;
|
||||
end;
|
||||
end;
|
||||
end.
|
||||
|
12
SynEditEx/data/synex_register.pas
Normal file
12
SynEditEx/data/synex_register.pas
Normal file
@@ -0,0 +1,12 @@
|
||||
unit synex_register;
|
||||
{$mode delphi}
|
||||
{$codepage UTF8}
|
||||
interface
|
||||
uses Classes, SysUtils, synex_syncharmngr;
|
||||
procedure Register;
|
||||
implementation
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents ('SynEdit', [TSynEditCharsetManager]);
|
||||
end;
|
||||
end.
|
68
SynEditEx/data/synex_syncharmngr.pas
Normal file
68
SynEditEx/data/synex_syncharmngr.pas
Normal file
@@ -0,0 +1,68 @@
|
||||
unit synex_syncharmngr;
|
||||
{$mode delphi}
|
||||
{$codepage UTF8}
|
||||
interface
|
||||
uses Classes, SysUtils, synex_charset, SynEdit;
|
||||
type
|
||||
TSynEditCharsetManager = class (TComponent)
|
||||
private
|
||||
FCharset: TTextCharset;
|
||||
FSynEdit: TSynEdit;
|
||||
public
|
||||
constructor Create (AOwner: TComponent);
|
||||
destructor Destroy;
|
||||
procedure LoadFromStream (Stream: TStream);
|
||||
procedure LoadFromFile (const FileName: String);
|
||||
procedure SaveToStream(Stream: TStream);
|
||||
procedure SaveToFile(const FileName: String);
|
||||
published
|
||||
property Charset: TTextCharset read FCharset;
|
||||
property SynEdit: TSynEdit read FSynEdit write FSynEdit;
|
||||
end;
|
||||
implementation
|
||||
{TCharsetStrings}
|
||||
constructor TSynEditCharsetManager.Create (AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FCharset:= tcUTF8;
|
||||
FSynEdit:= Nil;
|
||||
end;
|
||||
destructor TSynEditCharsetManager.Destroy;
|
||||
begin
|
||||
FSynEdit:= Nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
procedure TSynEditCharsetManager.LoadFromStream (Stream: TStream);
|
||||
var SL: TStringList;
|
||||
begin
|
||||
SL:= TStringList.Create;
|
||||
SL.LoadFromStream(Stream);
|
||||
FCharset:= GetTextCharset(SL.Text);
|
||||
SL.Text:= ConvertToUtf8(SL.Text, FCharset);
|
||||
FSynEdit.Lines.Assign(SL);
|
||||
FreeAndNil(SL);
|
||||
end;
|
||||
procedure TSynEditCharsetManager.LoadFromFile (const FileName: String);
|
||||
var FS: TFileStream;
|
||||
begin
|
||||
FS:= TFileStream.Create(FileName, fmOpenRead + fmShareDenyNone);
|
||||
LoadFromStream(FS);
|
||||
FreeAndNil(FS);
|
||||
end;
|
||||
procedure TSynEditCharsetManager.SaveToStream(Stream: TStream);
|
||||
var SL: TStringList;
|
||||
begin
|
||||
SL:= TStringList.Create;
|
||||
SL.Assign(FSynEdit.Lines);
|
||||
SL.Text:= ConvertFromUtf8(SL.Text, FCharset);
|
||||
SL.SaveToStream(Stream);
|
||||
FreeAndNil(SL);
|
||||
end;
|
||||
procedure TSynEditCharsetManager.SaveToFile(const FileName: String);
|
||||
var FS: TFileStream;
|
||||
begin
|
||||
FS:= TFileStream.Create(FileName, fmOpenWrite + fmShareDenyWrite);
|
||||
SaveToStream(FS);
|
||||
FreeAndNil(FS);
|
||||
end;
|
||||
end.
|
Reference in New Issue
Block a user