├── .gitignore ├── demos └── test1 │ ├── project1.lpi │ ├── project1.lpr │ ├── project1.res │ ├── unit1.lfm │ └── unit1.pas ├── encconv ├── encconv.pas ├── encconv_asiancodepagefunctions.inc ├── encconv_asiancodepages.inc ├── encconv_commoncodepagefunctions.inc ├── encconv_commoncodepages.inc ├── encconv_package.lpk └── encconv_package.pas ├── readme.txt └── testfiles ├── test-euc-jp.txt ├── test-euc-tw.txt ├── test-gb18030.txt ├── test-gb2312-hz.txt └── test-iso2022.txt /.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | project1 3 | *.lps 4 | *.exe 5 | *.dbg 6 | -------------------------------------------------------------------------------- /demos/test1/project1.lpi: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <Scaled Value="True"/> 9 | <ResourceType Value="res"/> 10 | <UseXPManifest Value="True"/> 11 | <XPManifest> 12 | <DpiAware Value="True"/> 13 | </XPManifest> 14 | </General> 15 | <BuildModes> 16 | <Item Name="Default" Default="True"/> 17 | </BuildModes> 18 | <PublishOptions> 19 | <Version Value="2"/> 20 | <UseFileFilters Value="True"/> 21 | </PublishOptions> 22 | <RunParams> 23 | <FormatVersion Value="2"/> 24 | <Modes Count="0"/> 25 | </RunParams> 26 | <RequiredPackages Count="2"> 27 | <Item1> 28 | <PackageName Value="encconv_package"/> 29 | </Item1> 30 | <Item2> 31 | <PackageName Value="LCL"/> 32 | </Item2> 33 | </RequiredPackages> 34 | <Units> 35 | <Unit> 36 | <Filename Value="project1.lpr"/> 37 | <IsPartOfProject Value="True"/> 38 | </Unit> 39 | <Unit> 40 | <Filename Value="unit1.pas"/> 41 | <IsPartOfProject Value="True"/> 42 | <ComponentName Value="Form1"/> 43 | <HasResources Value="True"/> 44 | <ResourceBaseClass Value="Form"/> 45 | <UnitName Value="Unit1"/> 46 | </Unit> 47 | </Units> 48 | </ProjectOptions> 49 | <CompilerOptions> 50 | <Version Value="11"/> 51 | <Target> 52 | <Filename Value="project1"/> 53 | </Target> 54 | <SearchPaths> 55 | <IncludeFiles Value="$(ProjOutDir)"/> 56 | <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> 57 | </SearchPaths> 58 | <Linking> 59 | <Debugging> 60 | <UseExternalDbgSyms Value="True"/> 61 | </Debugging> 62 | <Options> 63 | <Win32> 64 | <GraphicApplication Value="True"/> 65 | </Win32> 66 | </Options> 67 | </Linking> 68 | </CompilerOptions> 69 | <Debugging> 70 | <Exceptions Count="3"> 71 | <Item1> 72 | <Name Value="EAbort"/> 73 | </Item1> 74 | <Item2> 75 | <Name Value="ECodetoolError"/> 76 | </Item2> 77 | <Item3> 78 | <Name Value="EFOpenError"/> 79 | </Item3> 80 | </Exceptions> 81 | </Debugging> 82 | </CONFIG> 83 | -------------------------------------------------------------------------------- /demos/test1/project1.lpr: -------------------------------------------------------------------------------- 1 | program project1; 2 | 3 | {$mode objfpc}{$H+} 4 | 5 | uses 6 | {$IFDEF UNIX} 7 | cthreads, 8 | {$ENDIF} 9 | Interfaces, // this includes the LCL widgetset 10 | Forms, Unit1 11 | { you can add units after this }; 12 | 13 | {$R *.res} 14 | 15 | begin 16 | RequireDerivedFormResource:=True; 17 | Application.Title:='Test1'; 18 | Application.Scaled:=True; 19 | Application.Initialize; 20 | Application.CreateForm(TForm1, Form1); 21 | Application.Run; 22 | end. 23 | 24 | -------------------------------------------------------------------------------- /demos/test1/project1.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexey-T/EncConv/8caaa6b9838b2587d1d0a007dbc4a728a1306a72/demos/test1/project1.res -------------------------------------------------------------------------------- /demos/test1/unit1.lfm: -------------------------------------------------------------------------------- 1 | object Form1: TForm1 2 | Left = 1530 3 | Height = 532 4 | Top = 185 5 | Width = 561 6 | Caption = 'EncConv test' 7 | ClientHeight = 532 8 | ClientWidth = 561 9 | OnCreate = FormCreate 10 | Position = poScreenCenter 11 | LCLVersion = '2.1.0.0' 12 | object L: TListBox 13 | Left = 6 14 | Height = 470 15 | Top = 6 16 | Width = 549 17 | Align = alClient 18 | BorderSpacing.Around = 6 19 | ItemHeight = 0 20 | ScrollWidth = 547 21 | TabOrder = 0 22 | TopIndex = -1 23 | end 24 | object Panel1: TPanel 25 | Left = 0 26 | Height = 50 27 | Top = 482 28 | Width = 561 29 | Align = alBottom 30 | ClientHeight = 50 31 | ClientWidth = 561 32 | TabOrder = 1 33 | object Button1: TButton 34 | Left = 8 35 | Height = 29 36 | Top = 2 37 | Width = 223 38 | Caption = 'Run test' 39 | OnClick = Button1Click 40 | TabOrder = 0 41 | end 42 | object ComboBox1: TComboBox 43 | Left = 336 44 | Height = 27 45 | Top = 0 46 | Width = 220 47 | ItemHeight = 0 48 | Items.Strings = ( 49 | 'Skip chars' 50 | 'Exception' 51 | 'Replace chars with ''?''' 52 | 'Return empty string' 53 | ) 54 | OnChange = ComboBox1Change 55 | Style = csDropDownList 56 | TabOrder = 1 57 | end 58 | object Label1: TLabel 59 | AnchorSideTop.Control = ComboBox1 60 | AnchorSideTop.Side = asrCenter 61 | AnchorSideRight.Control = ComboBox1 62 | Left = 249 63 | Height = 17 64 | Top = 5 65 | Width = 81 66 | Anchors = [akTop, akRight] 67 | BorderSpacing.Right = 6 68 | Caption = 'error mode:' 69 | ParentColor = False 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /demos/test1/unit1.pas: -------------------------------------------------------------------------------- 1 | unit Unit1; 2 | 3 | {$mode objfpc}{$H+} 4 | 5 | interface 6 | 7 | uses 8 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; 9 | 10 | type 11 | 12 | { TForm1 } 13 | 14 | TForm1 = class(TForm) 15 | Button1: TButton; 16 | ComboBox1: TComboBox; 17 | L: TListBox; 18 | Label1: TLabel; 19 | Panel1: TPanel; 20 | procedure Button1Click(Sender: TObject); 21 | procedure ComboBox1Change(Sender: TObject); 22 | procedure FormCreate(Sender: TObject); 23 | private 24 | 25 | public 26 | 27 | end; 28 | 29 | var 30 | Form1: TForm1; 31 | 32 | implementation 33 | 34 | uses EncConv; 35 | 36 | {$R *.lfm} 37 | 38 | { TForm1 } 39 | 40 | procedure TForm1.Button1Click(Sender: TObject); 41 | const 42 | c_ru = 'Просто'; 43 | c_jp = 'のMGCを振り返る'; 44 | c_mix = 'пэцを振りeng'; 45 | err: array[boolean] of string = ('test failed', 'test ok'); 46 | var 47 | s1, s2: string; 48 | begin 49 | L.Items.Clear; 50 | 51 | L.Items.Add('test for russian...'); 52 | s1:= EncConvertFromUTF8(c_ru, eidCP1251); 53 | s2:= EncConvertToUTF8(s1, eidCP1251); 54 | L.Items.Add('conv to utf8: '+s2); 55 | L.Items.Add(err[c_ru=s2]); 56 | 57 | L.Items.Add(''); 58 | L.Items.Add('test for japanese...'); 59 | s1:= EncConvertFromUTF8(c_jp, eidCP932); 60 | s2:= EncConvertToUTF8(s1, eidCP932); 61 | L.Items.Add('conv to utf8: '+s2); 62 | L.Items.Add(err[c_jp=s2]); 63 | 64 | L.Items.Add(''); 65 | L.Items.Add('test for mixed ru/jp, must fail...'); 66 | s1:= EncConvertFromUTF8(c_mix, eidCP1251); 67 | s2:= EncConvertToUTF8(s1, eidCP1251); 68 | L.Items.Add('conv to utf8: '+s2); 69 | L.Items.Add(err[c_mix=s2]); 70 | 71 | end; 72 | 73 | procedure TForm1.ComboBox1Change(Sender: TObject); 74 | begin 75 | EncConvErrorMode:= TEncConvErrorMode(ComboBox1.ItemIndex); 76 | end; 77 | 78 | procedure TForm1.FormCreate(Sender: TObject); 79 | begin 80 | ComboBox1.ItemIndex:= Ord(EncConvErrorMode); 81 | end; 82 | 83 | end. 84 | 85 | -------------------------------------------------------------------------------- /encconv/encconv.pas: -------------------------------------------------------------------------------- 1 | { 2 | Codepage convertion functions, based on Lazarus' LConvEncoding code, 3 | but with simpler API. 4 | (c) 2019 Alexey Torgashin 5 | License: the same as Lazarus has 6 | } 7 | unit EncConv; 8 | 9 | {$mode objfpc}{$H+} 10 | 11 | interface 12 | 13 | {.$Define encconv_noasian} 14 | 15 | uses 16 | {$ifdef windows} 17 | Windows, 18 | {$endif} 19 | SysUtils, Classes, LazUTF8; 20 | 21 | type 22 | TEncConvId = ( 23 | eidUTF8, 24 | eidUTF8BOM, 25 | eidUCS2LE, 26 | eidUCS2BE, //eidLastUnicode points here 27 | 28 | eidCP1250, 29 | eidCP1251, 30 | eidCP1252, 31 | eidCP1253, 32 | eidCP1254, 33 | eidCP1255, 34 | eidCP1256, 35 | eidCP1257, 36 | eidCP1258, 37 | 38 | eidCP437, 39 | eidCP850, 40 | eidCP852, 41 | eidCP861, 42 | eidCP865, 43 | eidCP866, 44 | eidCP874, 45 | 46 | {$IFnDEF encconv_noasian} 47 | eidCP932, 48 | eidCP936, 49 | eidCNS, 50 | eidCP949, 51 | eidCP950, 52 | eidGB2312, 53 | eidEUC_KR, 54 | {$ENDIF} 55 | 56 | eidISO1, 57 | eidISO2, 58 | eidISO3, 59 | eidISO4, 60 | eidISO5, 61 | eidISO7, 62 | eidISO9, 63 | eidISO10, 64 | eidISO13, 65 | eidISO14, 66 | eidISO15, 67 | eidISO16, 68 | 69 | eidCPMac, 70 | eidKOI8R, 71 | eidKOI8U, 72 | eidKOI8RU 73 | ); 74 | 75 | const 76 | eidLastUnicode = eidUCS2BE; 77 | 78 | const 79 | cEncConvNames: array[TEncConvId] of string = ( 80 | 'utf8', 81 | 'utf8_bom', 82 | 'utf16le', 83 | 'utf16be', 84 | 85 | 'cp1250', 86 | 'cp1251', 87 | 'cp1252', 88 | 'cp1253', 89 | 'cp1254', 90 | 'cp1255', 91 | 'cp1256', 92 | 'cp1257', 93 | 'cp1258', 94 | 95 | 'cp437', 96 | 'cp850', 97 | 'cp852', 98 | 'cp861', 99 | 'cp865', 100 | 'cp866', 101 | 'cp874', 102 | 103 | {$IFnDEF encconv_noasian} 104 | 'shift-jis', 105 | 'gbk', 106 | 'cns', 107 | 'uhc', 108 | 'big5', 109 | 'gb2312', 110 | 'euc-kr', 111 | {$ENDIF} 112 | 113 | 'iso-8859-1', 114 | 'iso-8859-2', 115 | 'iso-8859-3', 116 | 'iso-8859-4', 117 | 'iso-8859-5', 118 | 'iso-8859-7', 119 | 'iso-8859-9', 120 | 'iso-8859-10', 121 | 'iso-8859-13', 122 | 'iso-8859-14', 123 | 'iso-8859-15', 124 | 'iso-8859-16', 125 | 126 | 'mac', 127 | 'koi8r', 128 | 'koi8u', 129 | 'koi8ru' 130 | ); 131 | 132 | function EncConvFindEncoding(const s: string; Default: TEncConvId=eidUTF8): TEncConvId; 133 | 134 | function EncConvertFromUTF8(const S: string; Enc: TEncConvId): string; 135 | function EncConvertToUTF8(const S: string; Enc: TEncConvId): string; 136 | 137 | type 138 | TEncConvTable = array[char] of PChar; 139 | TEncConvUnicodeToCharID = function(Unicode: cardinal): integer; 140 | TEncConvStringFunction = function(const S: string): string; 141 | 142 | type 143 | TEncConvErrorMode = ( 144 | eemSkip, 145 | eemException, 146 | eemReplace, 147 | eemReturnEmpty 148 | ); 149 | 150 | var 151 | EncConvErrorMode: TEncConvErrorMode = eemReplace; 152 | 153 | function EncConvGetANSI: TEncConvId; 154 | function EncConvGetOEM: TEncConvId; 155 | 156 | 157 | implementation 158 | 159 | {$IFnDEF encconv_noasian} 160 | {$include encconv_asiancodepages.inc} 161 | {$include encconv_asiancodepagefunctions.inc} 162 | {$ENDIF} 163 | 164 | {$include encconv_commoncodepages.inc} 165 | {$include encconv_commoncodepagefunctions.inc} 166 | 167 | const 168 | CP_CNS = 20000; 169 | CP_GB2312 = 20936; 170 | //CP_GB2312_HZ = 52936; 171 | //CP_GB18030 = 54936; 172 | //CP_ISO2022_CHS = 50227; 173 | //CP_ISO2022_CHT = 50229; 174 | //CP_EUC_JP = 51932; 175 | CP_EUC_KR = 51949; 176 | //CP_EUC_TW = 51950; 177 | 178 | function StrUTF8ToEnc(const S: string; Enc: TSystemCodePage): string; 179 | var 180 | buf: RawByteString; 181 | begin 182 | if S='' then exit(''); 183 | buf:= S; 184 | SetCodePage(buf, Enc, true); 185 | SetCodePage(buf, CP_UTF8, false); 186 | Result:= buf; 187 | if Result='' then 188 | raise EConvertError.Create('Cannot convert UTF-8 to DBCS code page'); 189 | end; 190 | 191 | function StrEncToUTF8(const S: string; Enc: TSystemCodePage): string; 192 | var 193 | buf: RawByteString; 194 | begin 195 | if S='' then exit(''); 196 | buf:= S; 197 | SetCodePage(buf, Enc, false); 198 | SetCodePage(buf, CP_UTF8, true); 199 | Result:= buf; 200 | if Result='' then 201 | raise EConvertError.Create('Cannot convert DBCS code page to UTF-8'); 202 | end; 203 | 204 | function StrNone(const S: string): string; 205 | begin 206 | Result:= S; 207 | end; 208 | 209 | function SingleByteToUTF8(const s: string; const Table: TEncConvTable): string; 210 | forward; 211 | function UTF8ToSingleByte(const s: string; const UTF8CharConvFunc: TEncConvUnicodeToCharID): string; 212 | forward; 213 | 214 | function UTF8BOMToUTF8(const s: string): string; 215 | begin 216 | Result:=copy(s,4,length(s)); 217 | end; 218 | 219 | function ISO_8859_1ToUTF8(const s: string): string; 220 | begin 221 | Result:=SingleByteToUTF8(s,ArrayISO_8859_1ToUTF8); 222 | end; 223 | 224 | function ISO_8859_2ToUTF8(const s: string): string; 225 | begin 226 | Result:=SingleByteToUTF8(s,ArrayISO_8859_2ToUTF8); 227 | end; 228 | 229 | function ISO_8859_3ToUTF8(const s: string): string; 230 | begin 231 | Result:=SingleByteToUTF8(s,ArrayISO_8859_3ToUTF8); 232 | end; 233 | 234 | function ISO_8859_4ToUTF8(const s: string): string; 235 | begin 236 | Result:=SingleByteToUTF8(s,ArrayISO_8859_4ToUTF8); 237 | end; 238 | 239 | function ISO_8859_5ToUTF8(const s: string): string; 240 | begin 241 | Result:=SingleByteToUTF8(s,ArrayISO_8859_5ToUTF8); 242 | end; 243 | 244 | function ISO_8859_7ToUTF8(const s: string): string; 245 | begin 246 | Result:=SingleByteToUTF8(s,ArrayISO_8859_7ToUTF8); 247 | end; 248 | 249 | function ISO_8859_9ToUTF8(const s: string): string; 250 | begin 251 | Result:=SingleByteToUTF8(s,ArrayISO_8859_9ToUTF8); 252 | end; 253 | 254 | function ISO_8859_10ToUTF8(const s: string): string; 255 | begin 256 | Result:=SingleByteToUTF8(s,ArrayISO_8859_10ToUTF8); 257 | end; 258 | 259 | function ISO_8859_13ToUTF8(const s: string): string; 260 | begin 261 | Result:=SingleByteToUTF8(s,ArrayISO_8859_13ToUTF8); 262 | end; 263 | 264 | function ISO_8859_14ToUTF8(const s: string): string; 265 | begin 266 | Result:=SingleByteToUTF8(s,ArrayISO_8859_14ToUTF8); 267 | end; 268 | 269 | function ISO_8859_15ToUTF8(const s: string): string; 270 | begin 271 | Result:=SingleByteToUTF8(s,ArrayISO_8859_15ToUTF8); 272 | end; 273 | 274 | function ISO_8859_16ToUTF8(const s: string): string; 275 | begin 276 | Result:=SingleByteToUTF8(s,ArrayISO_8859_16ToUTF8); 277 | end; 278 | 279 | function CP1250ToUTF8(const s: string): string; 280 | begin 281 | Result:=SingleByteToUTF8(s,ArrayCP1250ToUTF8); 282 | end; 283 | 284 | function CP1251ToUTF8(const s: string): string; 285 | begin 286 | Result:=SingleByteToUTF8(s,ArrayCP1251ToUTF8); 287 | end; 288 | 289 | function CP1252ToUTF8(const s: string): string; 290 | begin 291 | Result:=SingleByteToUTF8(s,ArrayCP1252ToUTF8); 292 | end; 293 | 294 | function CP1253ToUTF8(const s: string): string; 295 | begin 296 | Result:=SingleByteToUTF8(s,ArrayCP1253ToUTF8); 297 | end; 298 | 299 | function CP1254ToUTF8(const s: string): string; 300 | begin 301 | Result:=SingleByteToUTF8(s,ArrayCP1254ToUTF8); 302 | end; 303 | 304 | function CP1255ToUTF8(const s: string): string; 305 | begin 306 | Result:=SingleByteToUTF8(s,ArrayCP1255ToUTF8); 307 | end; 308 | 309 | function CP1256ToUTF8(const s: string): string; 310 | begin 311 | Result:=SingleByteToUTF8(s,ArrayCP1256ToUTF8); 312 | end; 313 | 314 | function CP1257ToUTF8(const s: string): string; 315 | begin 316 | Result:=SingleByteToUTF8(s,ArrayCP1257ToUTF8); 317 | end; 318 | 319 | function CP1258ToUTF8(const s: string): string; 320 | begin 321 | Result:=SingleByteToUTF8(s,ArrayCP1258ToUTF8); 322 | end; 323 | 324 | function CP437ToUTF8(const s: string): string; 325 | begin 326 | Result:=SingleByteToUTF8(s,ArrayCP437ToUTF8); 327 | end; 328 | 329 | function CP850ToUTF8(const s: string): string; 330 | begin 331 | Result:=SingleByteToUTF8(s,ArrayCP850ToUTF8); 332 | end; 333 | 334 | function CP852ToUTF8(const s: string): string; 335 | begin 336 | Result:=SingleByteToUTF8(s,ArrayCP852ToUTF8); 337 | end; 338 | 339 | function CP861ToUTF8(const s: string): string; 340 | begin 341 | Result:=SingleByteToUTF8(s,ArrayCP861ToUTF8); 342 | end; 343 | 344 | function CP865ToUTF8(const s: string): string; 345 | begin 346 | Result:=SingleByteToUTF8(s,ArrayCP865ToUTF8); 347 | end; 348 | 349 | function CP866ToUTF8(const s: string): string; 350 | begin 351 | Result:=SingleByteToUTF8(s,ArrayCP866ToUTF8); 352 | end; 353 | 354 | function CP874ToUTF8(const s: string): string; 355 | begin 356 | Result:=SingleByteToUTF8(s,ArrayCP874ToUTF8); 357 | end; 358 | 359 | function KOI8RToUTF8(const s: string): string; 360 | begin 361 | Result:=SingleByteToUTF8(s,ArrayKOI8RToUTF8); 362 | end; 363 | 364 | function KOI8UToUTF8(const s: string): string; 365 | begin 366 | Result:=SingleByteToUTF8(s,ArrayKOI8UToUTF8); 367 | end; 368 | 369 | function KOI8RUToUTF8(const s: string): string; 370 | begin 371 | Result:=SingleByteToUTF8(s,ArrayKOI8RUToUTF8); 372 | end; 373 | 374 | function MacintoshToUTF8(const s: string): string; 375 | begin 376 | Result:=SingleByteToUTF8(s,ArrayMacintoshToUTF8); 377 | end; 378 | 379 | function SingleByteToUTF8(const s: string; const Table: TEncConvTable): string; 380 | var 381 | len: Integer; 382 | i: Integer; 383 | Src: PChar; 384 | Dest: PChar; 385 | p: PChar; 386 | c: Char; 387 | begin 388 | if s='' then exit(''); 389 | len:=length(s); 390 | SetLength(Result,len*4);// UTF-8 is at most 4 bytes 391 | Src:=PChar(s); 392 | Dest:=PChar(Result); 393 | for i:=1 to len do begin 394 | c:=Src^; 395 | inc(Src); 396 | if ord(c)<128 then begin 397 | Dest^:=c; 398 | inc(Dest); 399 | end else begin 400 | p:=Table[c]; 401 | if p<>nil then begin 402 | while p^<>#0 do begin 403 | Dest^:=p^; 404 | inc(p); 405 | inc(Dest); 406 | end; 407 | end; 408 | end; 409 | end; 410 | SetLength(Result,{%H-}PtrUInt(Dest)-PtrUInt(Result)); 411 | end; 412 | 413 | function UCS2LEToUTF8(const s: string): string; 414 | var 415 | len: Integer; 416 | Src: PWord; 417 | Dest: PChar; 418 | i: Integer; 419 | c: Word; 420 | begin 421 | len:=length(s) div 2; 422 | if len=0 then 423 | exit(''); 424 | SetLength(Result,len*3);// UTF-8 is at most 3/2 times the size 425 | Src:=PWord(Pointer(s)); 426 | Dest:=PChar(Result); 427 | for i:=1 to len do begin 428 | c:=LEtoN(Src^); 429 | inc(Src); 430 | if ord(c)<128 then begin 431 | Dest^:=chr(c); 432 | inc(Dest); 433 | end else begin 434 | inc(Dest,UnicodeToUTF8SkipErrors(c,Dest)); 435 | end; 436 | end; 437 | len:={%H-}PtrUInt(Dest)-PtrUInt(Result); 438 | if len>length(Result) then 439 | raise Exception.Create(''); 440 | SetLength(Result,len); 441 | end; 442 | 443 | function UCS2BEToUTF8(const s: string): string; 444 | var 445 | len: Integer; 446 | Src: PWord; 447 | Dest: PChar; 448 | i: Integer; 449 | c: Word; 450 | begin 451 | len:=length(s) div 2; 452 | if len=0 then 453 | exit(''); 454 | SetLength(Result,len*3);// UTF-8 is at most three times the size 455 | Src:=PWord(Pointer(s)); 456 | Dest:=PChar(Result); 457 | for i:=1 to len do begin 458 | c:=BEtoN(Src^); 459 | inc(Src); 460 | if ord(c)<128 then begin 461 | Dest^:=chr(c); 462 | inc(Dest); 463 | end else begin 464 | inc(Dest,UnicodeToUTF8SkipErrors(c,Dest)); 465 | end; 466 | end; 467 | len:={%H-}PtrUInt(Dest)-PtrUInt(Result); 468 | if len>length(Result) then 469 | raise Exception.Create(''); 470 | SetLength(Result,len); 471 | end; 472 | 473 | function UTF8ToUTF8BOM(const s: string): string; 474 | const 475 | UTF8BOM = #$EF#$BB#$BF; 476 | begin 477 | Result:=UTF8BOM+s; 478 | end; 479 | 480 | function UTF8ToISO_8859_1(const s: string): string; 481 | begin 482 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_1); 483 | end; 484 | 485 | function UTF8ToISO_8859_2(const s: string): string; 486 | begin 487 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_2); 488 | end; 489 | 490 | function UTF8ToISO_8859_3(const s: string): string; 491 | begin 492 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_3); 493 | end; 494 | 495 | function UTF8ToISO_8859_4(const s: string): string; 496 | begin 497 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_4); 498 | end; 499 | 500 | function UTF8ToISO_8859_5(const s: string): string; 501 | begin 502 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_5); 503 | end; 504 | 505 | function UTF8ToISO_8859_7(const s: string): string; 506 | begin 507 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_7); 508 | end; 509 | 510 | function UTF8ToISO_8859_9(const s: string): string; 511 | begin 512 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_9); 513 | end; 514 | 515 | function UTF8ToISO_8859_10(const s: string): string; 516 | begin 517 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_10); 518 | end; 519 | 520 | function UTF8ToISO_8859_13(const s: string): string; 521 | begin 522 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_13); 523 | end; 524 | 525 | function UTF8ToISO_8859_14(const s: string): string; 526 | begin 527 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_14); 528 | end; 529 | 530 | function UTF8ToISO_8859_15(const s: string): string; 531 | begin 532 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_15); 533 | end; 534 | 535 | function UTF8ToISO_8859_16(const s: string): string; 536 | begin 537 | Result:=UTF8ToSingleByte(s,@UnicodeToISO_8859_16); 538 | end; 539 | 540 | function UTF8ToCP1250(const s: string): string; 541 | begin 542 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1250); 543 | end; 544 | 545 | function UTF8ToCP1251(const s: string): string; 546 | begin 547 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1251); 548 | end; 549 | 550 | function UTF8ToCP1252(const s: string): string; 551 | begin 552 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1252); 553 | end; 554 | 555 | function UTF8ToCP1253(const s: string): string; 556 | begin 557 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1253); 558 | end; 559 | 560 | function UTF8ToCP1254(const s: string): string; 561 | begin 562 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1254); 563 | end; 564 | 565 | function UTF8ToCP1255(const s: string): string; 566 | begin 567 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1255); 568 | end; 569 | 570 | function UTF8ToCP1256(const s: string): string; 571 | begin 572 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1256); 573 | end; 574 | 575 | function UTF8ToCP1257(const s: string): string; 576 | begin 577 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1257); 578 | end; 579 | 580 | function UTF8ToCP1258(const s: string): string; 581 | begin 582 | Result:=UTF8ToSingleByte(s,@UnicodeToCP1258); 583 | end; 584 | 585 | function UTF8ToCP437(const s: string): string; 586 | begin 587 | Result:=UTF8ToSingleByte(s,@UnicodeToCP437); 588 | end; 589 | 590 | function UTF8ToCP850(const s: string): string; 591 | begin 592 | Result:=UTF8ToSingleByte(s,@UnicodeToCP850); 593 | end; 594 | 595 | function UTF8ToCP852(const s: string): string; 596 | begin 597 | Result:=UTF8ToSingleByte(s,@UnicodeToCP852); 598 | end; 599 | 600 | function UTF8ToCP861(const s: string): string; 601 | begin 602 | Result:=UTF8ToSingleByte(s,@UnicodeToCP861); 603 | end; 604 | 605 | function UTF8ToCP865(const s: string): string; 606 | begin 607 | Result:=UTF8ToSingleByte(s,@UnicodeToCP865); 608 | end; 609 | 610 | function UTF8ToCP866(const s: string): string; 611 | begin 612 | Result:=UTF8ToSingleByte(s,@UnicodeToCP866); 613 | end; 614 | 615 | function UTF8ToCP874(const s: string): string; 616 | begin 617 | Result:=UTF8ToSingleByte(s,@UnicodeToCP874); 618 | end; 619 | 620 | function UTF8ToKOI8R(const s: string): string; 621 | begin 622 | Result:=UTF8ToSingleByte(s,@UnicodeToKOI8R); 623 | end; 624 | 625 | function UTF8ToKOI8U(const s: string): string; 626 | begin 627 | Result:=UTF8ToSingleByte(s,@UnicodeToKOI8U); 628 | end; 629 | 630 | function UTF8ToKOI8RU(const s: string): string; 631 | begin 632 | Result:=UTF8ToSingleByte(s,@UnicodeToKOI8RU); 633 | end; 634 | 635 | function UTF8ToMacintosh(const s: string): string; 636 | begin 637 | Result:=UTF8ToSingleByte(s,@UnicodeToMacintosh); 638 | end; 639 | 640 | function CNSToUTF8(const s: string): string; 641 | begin 642 | Result:=StrEncToUTF8(S, CP_CNS); 643 | end; 644 | 645 | function UTF8ToCNS(const S: string): string; 646 | begin 647 | Result:=StrUTF8ToEnc(S, CP_CNS); 648 | end; 649 | 650 | function UTF8ToGB2312(const S: string): string; 651 | begin 652 | Result:=StrUTF8ToEnc(S, CP_GB2312); 653 | end; 654 | 655 | { 656 | function UTF8ToGB2312HZ(const S: string): string; 657 | begin 658 | Result:=StrUTF8ToEnc(S, CP_GB2312_HZ); 659 | end; 660 | 661 | function UTF8ToGB18030(const S: string): string; 662 | begin 663 | Result:=StrUTF8ToEnc(S, CP_GB18030); 664 | end; 665 | 666 | function UTF8ToISO2022CHS(const S: string): string; 667 | begin 668 | Result:=StrUTF8ToEnc(S, CP_ISO2022_CHS); 669 | end; 670 | 671 | function UTF8ToISO2022CHT(const S: string): string; 672 | begin 673 | Result:=StrUTF8ToEnc(S, CP_ISO2022_CHT); 674 | end; 675 | 676 | function UTF8ToEUC_JP(const S: string): string; 677 | begin 678 | Result:=StrUTF8ToEnc(S, CP_EUC_JP); 679 | end; 680 | } 681 | function UTF8ToEUC_KR(const S: string): string; 682 | begin 683 | Result:=StrUTF8ToEnc(S, CP_EUC_KR); 684 | end; 685 | { 686 | function UTF8ToEUC_TW(const S: string): string; 687 | begin 688 | Result:=StrUTF8ToEnc(S, CP_EUC_TW); 689 | end; 690 | } 691 | function GB2312ToUTF8(const S: string): string; 692 | begin 693 | Result:=StrEncToUTF8(S, CP_GB2312); 694 | end; 695 | 696 | { 697 | function GB2312HZToUTF8(const S: string): string; 698 | begin 699 | Result:=StrEncToUTF8(S, CP_GB2312_HZ); 700 | end; 701 | 702 | function GB18030ToUTF8(const S: string): string; 703 | begin 704 | Result:=StrEncToUTF8(S, CP_GB18030); 705 | end; 706 | 707 | function ISO2022CHSToUTF8(const S: string): string; 708 | begin 709 | Result:=StrEncToUTF8(S, CP_ISO2022_CHS); 710 | end; 711 | 712 | function ISO2022CHTToUTF8(const S: string): string; 713 | begin 714 | Result:=StrEncToUTF8(S, CP_ISO2022_CHT); 715 | end; 716 | 717 | function EUC_JPToUTF8(const S: string): string; 718 | begin 719 | Result:=StrEncToUTF8(S, CP_EUC_JP); 720 | end; 721 | } 722 | function EUC_KRToUTF8(const S: string): string; 723 | begin 724 | Result:=StrEncToUTF8(S, CP_EUC_KR); 725 | end; 726 | { 727 | function EUC_TWToUTF8(const S: string): string; 728 | begin 729 | Result:=StrEncToUTF8(S, CP_EUC_TW); 730 | end; 731 | } 732 | 733 | function UTF8ToSingleByte(const s: string; const UTF8CharConvFunc: TEncConvUnicodeToCharID): string; 734 | var 735 | len, i, CharLen: Integer; 736 | Src, Dest: PChar; 737 | c: Char; 738 | Unicode: LongWord; 739 | begin 740 | if s='' then exit(''); 741 | len:=length(s); 742 | SetLength(Result,len); 743 | Src:=PChar(s); 744 | Dest:=PChar(Result); 745 | while len>0 do begin 746 | c:=Src^; 747 | if c<#128 then begin 748 | Dest^:=c; 749 | inc(Dest); 750 | inc(Src); 751 | dec(len); 752 | end else begin 753 | Unicode:=UTF8CodepointToUnicode(Src,CharLen); 754 | inc(Src,CharLen); 755 | dec(len,CharLen); 756 | i:=UTF8CharConvFunc(Unicode); 757 | //writeln('UTF8ToSingleByte Unicode=',Unicode,' CharLen=',CharLen,' c="',copy(s,Src-PChar(s)+1-CharLen,CharLen),'" i=',i); 758 | if i>=0 then begin 759 | Dest^:=chr(i); 760 | inc(Dest); 761 | end 762 | else 763 | case EncConvErrorMode of 764 | eemException: 765 | raise EConvertError.Create('Cannot convert UTF8 to single byte'); 766 | eemReplace: 767 | begin 768 | Dest^ := '?'; 769 | Inc(Dest); 770 | end; 771 | eemReturnEmpty: 772 | exit(''); 773 | end; 774 | end; 775 | end; 776 | SetLength(Result,Dest-PChar(Result)); 777 | end; 778 | 779 | function UTF8ToUCS2LE(const s: string): string; 780 | var 781 | len: Integer; 782 | Src: PChar; 783 | Dest: PWord; 784 | c: Char; 785 | Unicode: LongWord; 786 | CharLen: integer; 787 | begin 788 | if s='' then begin 789 | Result:=''; 790 | exit; 791 | end; 792 | len:=length(s); 793 | SetLength(Result,len*2); 794 | Src:=PChar(s); 795 | Dest:=PWord(Pointer(Result)); 796 | while len>0 do begin 797 | c:=Src^; 798 | if c<#128 then begin 799 | Dest^:=NtoLE(Word(ord(c))); 800 | inc(Dest); 801 | inc(Src); 802 | dec(len); 803 | end else begin 804 | Unicode:=UTF8CodepointToUnicode(Src,CharLen); 805 | inc(Src,CharLen); 806 | dec(len,CharLen); 807 | if Unicode<=$ffff then begin 808 | Dest^:=NtoLE(Word(Unicode)); 809 | inc(Dest); 810 | end; 811 | end; 812 | end; 813 | len:={%H-}PtrUInt(Dest)-PtrUInt(Result); 814 | if len>length(Result) then 815 | raise Exception.Create(''); 816 | SetLength(Result,len); 817 | end; 818 | 819 | function UTF8ToUCS2BE(const s: string): string; 820 | var 821 | len: Integer; 822 | Src: PChar; 823 | Dest: PWord; 824 | c: Char; 825 | Unicode: LongWord; 826 | CharLen: integer; 827 | begin 828 | if s='' then begin 829 | Result:=''; 830 | exit; 831 | end; 832 | len:=length(s); 833 | SetLength(Result,len*2); 834 | Src:=PChar(s); 835 | Dest:=PWord(Pointer(Result)); 836 | while len>0 do begin 837 | c:=Src^; 838 | if c<#128 then begin 839 | Dest^:=NtoBE(Word(ord(c))); 840 | inc(Dest); 841 | inc(Src); 842 | dec(len); 843 | end else begin 844 | Unicode:=UTF8CodepointToUnicode(Src,CharLen); 845 | inc(Src,CharLen); 846 | dec(len,CharLen); 847 | if Unicode<=$ffff then begin 848 | Dest^:=NtoBE(Word(Unicode)); 849 | inc(Dest); 850 | end; 851 | end; 852 | end; 853 | len:={%H-}PtrUInt(Dest)-PtrUInt(Result); 854 | if len>length(Result) then 855 | raise Exception.Create(''); 856 | SetLength(Result,len); 857 | end; 858 | 859 | function EncConvFindEncoding(const s: string; Default: TEncConvId=eidUTF8): TEncConvId; 860 | var 861 | e: TEncConvId; 862 | begin 863 | case s of 864 | 'cp932': 865 | exit(eidCP932); 866 | 'cp936': 867 | exit(eidCP936); 868 | 'cp949': 869 | exit(eidCP949); 870 | 'cp950': 871 | exit(eidCP950); 872 | end; 873 | 874 | for e:= Low(cEncConvNames) to High(cEncConvNames) do 875 | if s=cEncConvNames[e] then 876 | exit(e); 877 | Result:= Default; 878 | end; 879 | 880 | const 881 | FunctionsToUTF8: array[TEncConvId] of TEncConvStringFunction = ( 882 | @StrNone, 883 | @UTF8BOMToUTF8, 884 | @UCS2LEToUTF8, 885 | @UCS2BEToUTF8, 886 | @CP1250ToUTF8, 887 | @CP1251ToUTF8, 888 | @CP1252ToUTF8, 889 | @CP1253ToUTF8, 890 | @CP1254ToUTF8, 891 | @CP1255ToUTF8, 892 | @CP1256ToUTF8, 893 | @CP1257ToUTF8, 894 | @CP1258ToUTF8, 895 | @CP437ToUTF8, 896 | @CP850ToUTF8, 897 | @CP852ToUTF8, 898 | @CP861ToUTF8, 899 | @CP865ToUTF8, 900 | @CP866ToUTF8, 901 | @CP874ToUTF8, 902 | {$IFnDEF encconv_noasian} 903 | @CP932ToUTF8, 904 | @CP936ToUTF8, 905 | @CNSToUTF8, 906 | @CP949ToUTF8, 907 | @CP950ToUTF8, 908 | @GB2312ToUTF8, 909 | //@GB2312HZToUTF8, 910 | //@GB18030ToUTF8, 911 | //@ISO2022CHSToUTF8, 912 | //@ISO2022CHTToUTF8, 913 | //@EUC_JPToUTF8, 914 | @EUC_KRToUTF8, 915 | //@EUC_TWToUTF8, 916 | {$ENDIF} 917 | @ISO_8859_1ToUTF8, 918 | @ISO_8859_2ToUTF8, 919 | @ISO_8859_3ToUTF8, 920 | @ISO_8859_4ToUTF8, 921 | @ISO_8859_5ToUTF8, 922 | @ISO_8859_7ToUTF8, 923 | @ISO_8859_9ToUTF8, 924 | @ISO_8859_10ToUTF8, 925 | @ISO_8859_13ToUTF8, 926 | @ISO_8859_14ToUTF8, 927 | @ISO_8859_15ToUTF8, 928 | @ISO_8859_16ToUTF8, 929 | @MacintoshToUTF8, 930 | @KOI8RToUTF8, 931 | @KOI8UToUTF8, 932 | @KOI8RUToUTF8 933 | ); 934 | 935 | FunctionsFromUTF8: array[TEncConvId] of TEncConvStringFunction = ( 936 | @StrNone, 937 | @UTF8ToUTF8BOM, 938 | @UTF8ToUCS2LE, 939 | @UTF8ToUCS2BE, 940 | @UTF8ToCP1250, 941 | @UTF8ToCP1251, 942 | @UTF8ToCP1252, 943 | @UTF8ToCP1253, 944 | @UTF8ToCP1254, 945 | @UTF8ToCP1255, 946 | @UTF8ToCP1256, 947 | @UTF8ToCP1257, 948 | @UTF8ToCP1258, 949 | @UTF8ToCP437, 950 | @UTF8ToCP850, 951 | @UTF8ToCP852, 952 | @UTF8ToCP861, 953 | @UTF8ToCP865, 954 | @UTF8ToCP866, 955 | @UTF8ToCP874, 956 | {$IFnDEF encconv_noasian} 957 | @UTF8ToCP932, 958 | @UTF8ToCP936, 959 | @UTF8ToCNS, 960 | @UTF8ToCP949, 961 | @UTF8ToCP950, 962 | @UTF8ToGB2312, 963 | //@UTF8ToGB2312HZ, 964 | //@UTF8ToGB18030, 965 | //@UTF8ToISO2022CHS, 966 | //@UTF8ToISO2022CHT, 967 | //@UTF8ToEUC_JP, 968 | @UTF8ToEUC_KR, 969 | //@UTF8ToEUC_TW, 970 | {$ENDIF} 971 | @UTF8ToISO_8859_1, 972 | @UTF8ToISO_8859_2, 973 | @UTF8ToISO_8859_3, 974 | @UTF8ToISO_8859_4, 975 | @UTF8ToISO_8859_5, 976 | @UTF8ToISO_8859_7, 977 | @UTF8ToISO_8859_9, 978 | @UTF8ToISO_8859_10, 979 | @UTF8ToISO_8859_13, 980 | @UTF8ToISO_8859_14, 981 | @UTF8ToISO_8859_15, 982 | @UTF8ToISO_8859_16, 983 | @UTF8ToMacintosh, 984 | @UTF8ToKOI8R, 985 | @UTF8ToKOI8U, 986 | @UTF8ToKOI8RU 987 | ); 988 | 989 | 990 | function EncConvertFromUTF8(const S: string; Enc: TEncConvId): string; 991 | begin 992 | Result:= FunctionsFromUTF8[Enc](S); 993 | end; 994 | 995 | function EncConvertToUTF8(const S: string; Enc: TEncConvId): string; 996 | begin 997 | Result:= FunctionsToUTF8[Enc](S); 998 | end; 999 | 1000 | 1001 | {$ifdef windows} 1002 | var 1003 | _SavedANSI: TEncConvId = eidUTF8; 1004 | _SavedOEM: TEncConvId = eidUTF8; 1005 | {$endif} 1006 | 1007 | function EncConvGetANSI: TEncConvId; 1008 | begin 1009 | {$ifdef windows} 1010 | if _SavedANSI<>eidUTF8 then 1011 | exit(_SavedANSI); 1012 | case Windows.GetACP of 1013 | 1250: Result:= eidCP1250; 1014 | 1251: Result:= eidCP1251; 1015 | 1252: Result:= eidCP1252; 1016 | 1253: Result:= eidCP1253; 1017 | 1254: Result:= eidCP1254; 1018 | 1255: Result:= eidCP1255; 1019 | 1256: Result:= eidCP1256; 1020 | 1257: Result:= eidCP1257; 1021 | 1258: Result:= eidCP1258; 1022 | 874: Result:= eidCP874; 1023 | 932: Result:= eidCP932; 1024 | 936: Result:= eidCP936; 1025 | 949: Result:= eidCP949; 1026 | 950: Result:= eidCP950; 1027 | else Result:= eidCP1252; 1028 | end; 1029 | _SavedANSI:= Result; 1030 | {$else} 1031 | Result:= eidCP1252; 1032 | {$endif} 1033 | end; 1034 | 1035 | function EncConvGetOEM: TEncConvId; 1036 | begin 1037 | {$ifdef windows} 1038 | if _SavedOEM<>eidUTF8 then 1039 | exit(_SavedOEM); 1040 | case Windows.GetOEMCP of 1041 | 437: Result:= eidCP437; 1042 | 850: Result:= eidCP850; 1043 | 852: Result:= eidCP852; 1044 | 866: Result:= eidCP866; 1045 | 874: Result:= eidCP874; 1046 | 932: Result:= eidCP932; 1047 | 936: Result:= eidCP936; 1048 | 949: Result:= eidCP949; 1049 | 950: Result:= eidCP950; 1050 | else Result:= eidCP437; 1051 | end; 1052 | _SavedOEM:= Result; 1053 | {$else} 1054 | Result:= eidCP437; 1055 | {$endif} 1056 | end; 1057 | 1058 | 1059 | end. 1060 | -------------------------------------------------------------------------------- /encconv/encconv_asiancodepagefunctions.inc: -------------------------------------------------------------------------------- 1 | { 2 | ***************************************************************************** 3 | This file is part of LazUtils. 4 | 5 | See the file COPYING.modifiedLGPL.txt, included in this distribution, 6 | for details about the license. 7 | ***************************************************************************** 8 | } 9 | 10 | function DBCSToUTF8(const s: string; const ArrayUni, ArrayCP: array of word; CodeP: integer): string; 11 | const 12 | cp936unodered:array[0..254] of Uint32=($a2ab,$a2ac,$a2ad,$a2ae,$a2af,$a2b0,$a2e3,$a2e4,$a2ef,$a2f0,$a2fd,$a2fe,$a4f4,$a4f5,$a4f6,$a4f7,$a4f8,$a4f9,$a4fa,$a4fb,$a4fc,$a4fd,$a4fe,$a5f7,$a5f8,$a5f9,$a5fa,$a5fb,$a5fc,$a5fd,$a5fe,$a6b9,$a6ba,$a6bb,$a6bc,$a6bd,$a6be,$a6bf,$a6c0,$a6d9,$a6da,$a6db,$a6dc,$a6dd,$a6de,$a6df,$a6ec,$a6ed,$a6f3,$a6f6,$a6f7,$a6f8,$a6f9,$a6fa,$a6fb,$a6fc,$a6fd,$a6fe,$a7c2,$a7c3,$a7c4,$a7c5,$a7c6,$a7c7,$a7c8,$a7c9,$a7ca,$a7cb,$a7cc,$a7cd,$a7ce,$a7cf,$a7d0,$a7f2,$a7f3,$a7f4,$a7f5,$a7f6,$a7f7,$a7f8,$a7f9,$a7fa,$a7fb,$a7fc,$a7fd,$a7fe,$a896,$a897,$a898,$a899,$a89a,$a89b,$a89c,$a89d,$a89e,$a89f,$a8a0,$a8bc,$a8bf,$a8c1,$a8c2,$a8c3,$a8c4,$a8ea,$a8eb,$a8ec,$a8ed,$a8ee,$a8ef,$a8f0,$a8f1,$a8f2,$a8f3,$a8f4,$a8f5,$a8f6,$a8f7,$a8f8,$a8f9,$a8fa,$a8fb,$a8fc,$a8fd,$a8fe,$a958,$a95b,$a95d,$a95e,$a95f,$a989,$a98a,$a98b,$a98c,$a98d,$a98e,$a98f,$a990,$a991,$a992,$a993,$a994,$a995,$a997,$a998,$a999,$a99a,$a99b,$a99c,$a99d,$a99e,$a99f,$a9a0,$a9a1,$a9a2,$a9a3,$a9f0,$a9f1,$a9f2,$a9f3,$a9f4,$a9f5,$a9f6,$a9f7,$a9f8,$a9f9,$a9fa,$a9fb,$a9fc,$a9fd,$a9fe,$d7fa,$d7fb,$d7fc,$d7fd,$d7fe,$fe50,$fe51,$fe52,$fe53,$fe54,$fe55,$fe56,$fe57,$fe58,$fe59,$fe5a,$fe5b,$fe5c,$fe5d,$fe5e,$fe5f,$fe60,$fe61,$fe62,$fe63,$fe64,$fe65,$fe66,$fe67,$fe68,$fe69,$fe6a,$fe6b,$fe6c,$fe6d,$fe6e,$fe6f,$fe70,$fe71,$fe72,$fe73,$fe74,$fe75,$fe76,$fe77,$fe78,$fe79,$fe7a,$fe7b,$fe7c,$fe7d,$fe7e,$fe80,$fe81,$fe82,$fe83,$fe84,$fe85,$fe86,$fe87,$fe88,$fe89,$fe8a,$fe8b,$fe8c,$fe8d,$fe8e,$fe8f,$fe90,$fe91,$fe92,$fe93,$fe94,$fe95,$fe96,$fe97,$fe98,$fe99,$fe9a,$fe9b,$fe9c,$fe9d,$fe9e,$fe9f,$fea0); 13 | cp936unoderedstart:Uint32=$e766; 14 | var 15 | len, l,i: Integer; 16 | Src, Dest: PChar; 17 | c: char; 18 | code,code1: word; 19 | Hbyte,Lbyte:byte; 20 | begin 21 | if s = '' then exit(''); 22 | len := length(s); 23 | SetLength(Result, len * 4);// Asia UTF-8 is at most 4 bytes 24 | Src := PChar(s); 25 | Dest := PChar(Result); 26 | repeat 27 | c := Src^; 28 | Hbyte := byte(Src^); 29 | Inc(Src); 30 | 31 | if Ord(c) < 128 then 32 | begin 33 | if (c=#0) and (Src-PChar(s)>=len) then break; 34 | Dest^ := c; 35 | Inc(Dest); 36 | end 37 | else 38 | begin 39 | // shift-jis halfwidth 40 | if ((CodeP=932) and (c in [#$a0..#$df,#$fd,#$fe,#$ff])) then 41 | begin 42 | code := Byte(c); 43 | code1:= code; 44 | end 45 | else 46 | begin 47 | code := Byte(c) shl 8; 48 | c:=Src^; 49 | Lbyte := byte(Src^); 50 | if (c=#0) and (Src-PChar(s)>=len) then break; 51 | code := code + Byte(c); 52 | code1:=code; 53 | Inc(Src); 54 | end; 55 | 56 | code := ArrayUni[SearchTable(ArrayCP, code)]; 57 | if code=0 then 58 | begin 59 | case CodeP of 60 | 936: 61 | begin 62 | 63 | if (HByte>=$AA) and (HByte<=$AF) and (LByte>=$A1) and (LByte<=$FE) then 64 | begin 65 | code:= $e000 + (94 * (HByte-$aa)) + (LByte-$a1); 66 | end 67 | else 68 | if (HByte>=$F8) and (HByte<=$FE) and (LByte>=$A1) and (LByte<=$FE) then 69 | begin 70 | code:= $e234 + (94 * (HByte-$f8)) + (LByte-$a1); 71 | end 72 | else 73 | if (HByte>=$A1) and (HByte<=$A7) and (LByte>=$40) and (LByte<=$A0) then 74 | begin 75 | code:= $e4C6 + (97 * (HByte-$A1)) + (LByte-$40); 76 | end 77 | else 78 | begin 79 | for i:=0 to length(cp936unodered)-1 do 80 | begin 81 | if code1=cp936unodered[i] then 82 | begin 83 | code:=cp936unoderedstart+i; 84 | break; 85 | end; 86 | end; 87 | end; 88 | end; 89 | 950: 90 | begin 91 | if (HByte>=$81) and (HByte<=$8d) and (LByte>=$40) and (LByte<=$FE) then 92 | begin 93 | code:= $eeb8 + (157 * (Hbyte-$81)) ; 94 | if (Lbyte<$80) then 95 | code:=code + (Lbyte-$40) 96 | else 97 | code:=code + (Lbyte-$62); 98 | end 99 | else 100 | if (HByte>=$8e) and (HByte<=$a0) and (LByte>=$40) and (LByte<=$FE) then 101 | begin 102 | code:= $e311 + (157 * (Hbyte-$8e)); 103 | if (Lbyte<$80) then 104 | code:=code + (Lbyte-$40) 105 | else 106 | code:=code + (Lbyte-$62); 107 | end 108 | else 109 | if (HByte>=$c6) and (HByte<=$c8) and (LByte>=$a1) and (LByte<=$FE) then 110 | begin 111 | code:= $f672 + (157 * (Hbyte-$c6)) ; 112 | if (Lbyte<$80) then 113 | code:=code + (Lbyte-$40) 114 | else 115 | code:=code + (Lbyte-$62); 116 | end 117 | else 118 | if (HByte>=$fa) and (HByte<=$fe) and (LByte>=$40) and (LByte<=$FE) then 119 | begin 120 | code:= $e000 + (157 * (Hbyte-$fa)) ; 121 | if (Lbyte<$80) then 122 | code:=code + (Lbyte-$40) 123 | else 124 | code:=code + (Lbyte-$62); 125 | end; 126 | end; 127 | 949: 128 | begin 129 | if (HByte=$c9) and (LByte>=$a1) and (LByte<=$fe) then 130 | begin 131 | code:= $e000 + (94 * (HByte-$c9)) + (LByte-$a1) ; 132 | end 133 | else 134 | if (HByte=$fe) and (LByte>=$a1) and (LByte<=$fe) then 135 | begin 136 | code:= $e05e + (94 * (HByte-$fe)) + (LByte-$a1) ; 137 | end 138 | else 139 | if code1=$ff then 140 | begin 141 | code:= $f8f7; 142 | end; 143 | end; 144 | 932: 145 | begin 146 | if (HByte>=$f0) and (HByte<=$f9) and (LByte>=$40) and (LByte<=$fc) then 147 | begin 148 | code:= $e000 + (188 * (HByte-$f0)) + (LByte-$40) ; 149 | if LByte>$7f then 150 | code:=code-1; 151 | end 152 | else 153 | begin 154 | case code1 of 155 | $00a0:code:=$f8f0; 156 | $00fd:code:=$f8f1; 157 | $00fe:code:=$f8f2; 158 | $00ff:code:=$f8f3; 159 | end; 160 | 161 | end; 162 | end 163 | else 164 | code := 0; 165 | end; 166 | end; 167 | if code>0 then 168 | begin 169 | l:=UnicodeToUTF8Inline(code,Dest); 170 | inc(Dest,l); 171 | end 172 | else 173 | case EncConvErrorMode of 174 | eemSkip: 175 | begin end; 176 | eemException: 177 | raise EConvertError.Create('Cannot convert DBCS code page to UTF-8'); 178 | eemReplace: 179 | begin 180 | Dest^:='?'; 181 | Inc(Dest); 182 | end; 183 | eemReturnEmpty: 184 | Exit(''); 185 | end; 186 | end; 187 | until false; 188 | SetLength(Result, {%H-}PtrUInt(Dest) - PtrUInt(Result)); 189 | end; 190 | 191 | function CP936ToUTF8(const s: string): string; 192 | begin 193 | Result := DBCSToUTF8(s, Uni936C, CP936CC,936); 194 | end; 195 | 196 | function CP950ToUTF8(const s: string): string; 197 | begin 198 | Result := DBCSToUTF8(s, Uni950C, CP950CC,950); 199 | end; 200 | 201 | function CP949ToUTF8(const s: string): string; 202 | begin 203 | Result := DBCSToUTF8(s, Uni949C, CP949CC,949); 204 | end; 205 | 206 | function CP932ToUTF8(const s: string): string; 207 | begin 208 | Result := DBCSToUTF8(s, Uni932C, CP932CC,932); 209 | end; 210 | 211 | function UnicodeToCP936(Unicode: cardinal): integer; 212 | begin 213 | case Unicode of 214 | 0..127: Result := Unicode; 215 | else 216 | Result := CP936CU[SearchTable(Uni936U, Unicode)]; 217 | end; 218 | end; 219 | 220 | function UnicodeToCP950(Unicode: cardinal): integer; 221 | begin 222 | case Unicode of 223 | 0..127: Result := Unicode; 224 | else 225 | Result := CP950CU[SearchTable(Uni950U, Unicode)]; 226 | end; 227 | end; 228 | 229 | function UnicodeToCP949(Unicode: cardinal): integer; 230 | begin 231 | case Unicode of 232 | 0..127: Result := Unicode; 233 | else 234 | Result := CP949CU[SearchTable(Uni949U, Unicode)]; 235 | end; 236 | end; 237 | 238 | function UnicodeToCP932(Unicode: cardinal): integer; 239 | begin 240 | case Unicode of 241 | 0..127: Result := Unicode; 242 | else 243 | Result := CP932CU[SearchTable(Uni932U, Unicode)]; 244 | end; 245 | end; 246 | 247 | function UTF8ToDBCS(const s: string; const UTF8CharConvFunc: TEncConvUnicodeToCharID): string; 248 | var 249 | len, i, CharLen: integer; 250 | Src, Dest: PChar; 251 | c: char; 252 | Unicode: longword; 253 | begin 254 | if s = '' then exit(''); 255 | len := length(s); 256 | SetLength(Result, len); // DBCS needs at most space as UTF-8 257 | Src := PChar(s); 258 | Dest := PChar(Result); 259 | repeat 260 | c := Src^; 261 | if c < #128 then 262 | begin 263 | if (c=#0) and (Src-PChar(s)>=len) then break; 264 | Dest^ := c; 265 | Inc(Dest); 266 | Inc(Src); 267 | end 268 | else 269 | begin 270 | Unicode := UTF8CodepointToUnicode(Src, CharLen); 271 | Inc(Src, CharLen); 272 | i := UTF8CharConvFunc(Unicode); 273 | //writeln(Format('%X', [i])); 274 | if i >= 0 then 275 | begin 276 | if i > $ff then 277 | begin 278 | Dest^ := chr(i shr 8); 279 | Inc(Dest); 280 | Dest^ := chr(i); 281 | end 282 | else 283 | Dest^ := chr(i); 284 | Inc(Dest); 285 | end 286 | else 287 | case EncConvErrorMode of 288 | eemException: 289 | raise EConvertError.Create('Cannot convert UTF-8 to DBCS code page'); 290 | eemReplace: 291 | begin 292 | Dest^ := '?'; 293 | Inc(Dest); 294 | end; 295 | eemReturnEmpty: 296 | exit(''); 297 | end; 298 | end; 299 | until false; 300 | //SetLength(Result, Dest - PChar(Result)); 301 | SetLength(Result, {%H-}PtrUInt(Dest) - PtrUInt(Result)); 302 | end; 303 | 304 | function UTF8ToCP932(const s: string): string; 305 | begin 306 | Result := UTF8ToDBCS(s, @UnicodeToCP932); 307 | end; 308 | 309 | function UTF8ToCP936(const s: string): string; 310 | begin 311 | Result := UTF8ToDBCS(s, @UnicodeToCP936); 312 | end; 313 | 314 | function UTF8ToCP949(const s: string): string; 315 | begin 316 | Result := UTF8ToDBCS(s, @UnicodeToCP949); 317 | end; 318 | 319 | function UTF8ToCP950(const s: string): string; 320 | begin 321 | Result := UTF8ToDBCS(s, @UnicodeToCP950); 322 | end; 323 | 324 | 325 | -------------------------------------------------------------------------------- /encconv/encconv_commoncodepagefunctions.inc: -------------------------------------------------------------------------------- 1 | function UnicodeToCP1256(Unicode: cardinal): integer; 2 | begin 3 | case Unicode of 4 | 0..127: Result:=Unicode; 5 | 160: Result:=160; 6 | 162..169: Result:=Unicode; 7 | 171..185: Result:=Unicode; 8 | 187..190: Result:=Unicode; 9 | 215: Result:=215; 10 | 224: Result:=224; 11 | 226: Result:=226; 12 | 231..235: Result:=Unicode; 13 | 238..239: Result:=Unicode; 14 | 244: Result:=244; 15 | 247: Result:=247; 16 | 249: Result:=249; 17 | 251..252: Result:=Unicode; 18 | 338: Result:=140; 19 | 339: Result:=156; 20 | 402: Result:=131; 21 | 710: Result:=136; 22 | 1548: Result:=161; 23 | 1563: Result:=186; 24 | 1567: Result:=191; 25 | 1569..1590: Result:=Unicode-1376; 26 | 1591..1594: Result:=Unicode-1375; 27 | 1600..1603: Result:=Unicode-1380; 28 | 1604: Result:=225; 29 | 1605..1608: Result:=Unicode-1378; 30 | 1609..1610: Result:=Unicode-1373; 31 | 1611..1614: Result:=Unicode-1371; 32 | 1615..1616: Result:=Unicode-1370; 33 | 1617: Result:=248; 34 | 1618: Result:=250; 35 | 1657: Result:=138; 36 | 1662: Result:=129; 37 | 1670: Result:=141; 38 | 1672: Result:=143; 39 | 1681: Result:=154; 40 | 1688: Result:=142; 41 | 1705: Result:=152; 42 | 1711: Result:=144; 43 | 1722: Result:=159; 44 | 1726: Result:=170; 45 | 1729: Result:=192; 46 | 1746: Result:=255; 47 | 8204..8205: Result:=Unicode-8047; 48 | 8206..8207: Result:=Unicode-7953; 49 | 8211..8212: Result:=Unicode-8061; 50 | 8216..8217: Result:=Unicode-8071; 51 | 8218: Result:=130; 52 | 8220..8221: Result:=Unicode-8073; 53 | 8222: Result:=132; 54 | 8224..8225: Result:=Unicode-8090; 55 | 8226: Result:=149; 56 | 8230: Result:=133; 57 | 8240: Result:=137; 58 | 8249: Result:=139; 59 | 8250: Result:=155; 60 | 8364: Result:=128; 61 | 8482: Result:=153; 62 | else Result:=-1; 63 | end; 64 | end; 65 | 66 | function UnicodeToCP437(Unicode: cardinal): integer; 67 | begin 68 | case Unicode of 69 | 0..127: Result:=Unicode; 70 | 160: Result:=255; 71 | 161: Result:=173; 72 | 162..163: Result:=Unicode-7; 73 | 165: Result:=157; 74 | 170: Result:=166; 75 | 171: Result:=174; 76 | 172: Result:=170; 77 | 176: Result:=248; 78 | 177: Result:=241; 79 | 178: Result:=253; 80 | 181: Result:=230; 81 | 183: Result:=250; 82 | 186: Result:=167; 83 | 187: Result:=175; 84 | 188: Result:=172; 85 | 189: Result:=171; 86 | 191: Result:=168; 87 | 196..197: Result:=Unicode-54; 88 | 198: Result:=146; 89 | 199: Result:=128; 90 | 201: Result:=144; 91 | 209: Result:=165; 92 | 214: Result:=153; 93 | 220: Result:=154; 94 | 223: Result:=225; 95 | 224: Result:=133; 96 | 225: Result:=160; 97 | 226: Result:=131; 98 | 228: Result:=132; 99 | 229: Result:=134; 100 | 230: Result:=145; 101 | 231: Result:=135; 102 | 232: Result:=138; 103 | 233: Result:=130; 104 | 234..235: Result:=Unicode-98; 105 | 236: Result:=141; 106 | 237: Result:=161; 107 | 238: Result:=140; 108 | 239: Result:=139; 109 | 241: Result:=164; 110 | 242: Result:=149; 111 | 243: Result:=162; 112 | 244: Result:=147; 113 | 246: Result:=148; 114 | 247: Result:=246; 115 | 249: Result:=151; 116 | 250: Result:=163; 117 | 251: Result:=150; 118 | 252: Result:=129; 119 | 255: Result:=152; 120 | 262: Result := 93; 121 | 263: Result := 125; 122 | 268: Result := 94; 123 | 269: Result := 126; 124 | 272: Result := 92; 125 | 273: Result := 124; 126 | 381: Result := 64; 127 | 382: Result := 96; 128 | 352: Result := 91; 129 | 353: Result := 123; 130 | 402: Result:=159; 131 | 915: Result:=226; 132 | 920: Result:=233; 133 | 931: Result:=228; 134 | 934: Result:=232; 135 | 937: Result:=234; 136 | 945: Result:=224; 137 | 948: Result:=235; 138 | 949: Result:=238; 139 | 960: Result:=227; 140 | 963: Result:=229; 141 | 964: Result:=231; 142 | 966: Result:=237; 143 | 8319: Result:=252; 144 | 8359: Result:=158; 145 | 8729: Result:=249; 146 | 8730: Result:=251; 147 | 8734: Result:=236; 148 | 8745: Result:=239; 149 | 8776: Result:=247; 150 | 8801: Result:=240; 151 | 8804: Result:=243; 152 | 8805: Result:=242; 153 | 8976: Result:=169; 154 | 8992..8993: Result:=Unicode-8748; 155 | 9472: Result:=196; 156 | 9474: Result:=179; 157 | 9484: Result:=218; 158 | 9488: Result:=191; 159 | 9492: Result:=192; 160 | 9496: Result:=217; 161 | 9500: Result:=195; 162 | 9508: Result:=180; 163 | 9516: Result:=194; 164 | 9524: Result:=193; 165 | 9532: Result:=197; 166 | 9552: Result:=205; 167 | 9553: Result:=186; 168 | 9554..9555: Result:=Unicode-9341; 169 | 9556: Result:=201; 170 | 9557: Result:=184; 171 | 9558: Result:=183; 172 | 9559: Result:=187; 173 | 9560: Result:=212; 174 | 9561: Result:=211; 175 | 9562: Result:=200; 176 | 9563: Result:=190; 177 | 9564: Result:=189; 178 | 9565: Result:=188; 179 | 9566..9567: Result:=Unicode-9368; 180 | 9568: Result:=204; 181 | 9569..9570: Result:=Unicode-9388; 182 | 9571: Result:=185; 183 | 9572..9573: Result:=Unicode-9363; 184 | 9574: Result:=203; 185 | 9575..9576: Result:=Unicode-9368; 186 | 9577: Result:=202; 187 | 9578: Result:=216; 188 | 9579: Result:=215; 189 | 9580: Result:=206; 190 | 9600: Result:=223; 191 | 9604: Result:=220; 192 | 9608: Result:=219; 193 | 9612: Result:=221; 194 | 9616: Result:=222; 195 | 9617..9619: Result:=Unicode-9441; 196 | 9632: Result:=254; 197 | else Result:=-1; 198 | end; 199 | end; 200 | 201 | function UnicodeToCP850(Unicode: cardinal): integer; 202 | begin 203 | case Unicode of 204 | 0..127: Result:=Unicode; 205 | 160: Result:=255; 206 | 161: Result:=173; 207 | 162: Result:=189; 208 | 163: Result:=156; 209 | 164: Result:=207; 210 | 165: Result:=190; 211 | 166: Result:=221; 212 | 167: Result:=245; 213 | 168: Result:=249; 214 | 169: Result:=184; 215 | 170: Result:=166; 216 | 171: Result:=174; 217 | 172: Result:=170; 218 | 173: Result:=240; 219 | 174: Result:=169; 220 | 175: Result:=238; 221 | 176: Result:=248; 222 | 177: Result:=241; 223 | 178: Result:=253; 224 | 179: Result:=252; 225 | 180: Result:=239; 226 | 181: Result:=230; 227 | 182: Result:=244; 228 | 183: Result:=250; 229 | 184: Result:=247; 230 | 185: Result:=251; 231 | 186: Result:=167; 232 | 187: Result:=175; 233 | 188: Result:=172; 234 | 189: Result:=171; 235 | 190: Result:=243; 236 | 191: Result:=168; 237 | 192: Result:=183; 238 | 193..194: Result:=Unicode-12; 239 | 195: Result:=199; 240 | 196..197: Result:=Unicode-54; 241 | 198: Result:=146; 242 | 199: Result:=128; 243 | 200: Result:=212; 244 | 201: Result:=144; 245 | 202..203: Result:=Unicode+8; 246 | 204: Result:=222; 247 | 205..207: Result:=Unicode+9; 248 | 208: Result:=209; 249 | 209: Result:=165; 250 | 210: Result:=227; 251 | 211: Result:=224; 252 | 212: Result:=226; 253 | 213: Result:=229; 254 | 214: Result:=153; 255 | 215: Result:=158; 256 | 216: Result:=157; 257 | 217: Result:=235; 258 | 218..219: Result:=Unicode+15; 259 | 220: Result:=154; 260 | 221: Result:=237; 261 | 222: Result:=232; 262 | 223: Result:=225; 263 | 224: Result:=133; 264 | 225: Result:=160; 265 | 226: Result:=131; 266 | 227: Result:=198; 267 | 228: Result:=132; 268 | 229: Result:=134; 269 | 230: Result:=145; 270 | 231: Result:=135; 271 | 232: Result:=138; 272 | 233: Result:=130; 273 | 234..235: Result:=Unicode-98; 274 | 236: Result:=141; 275 | 237: Result:=161; 276 | 238: Result:=140; 277 | 239: Result:=139; 278 | 240: Result:=208; 279 | 241: Result:=164; 280 | 242: Result:=149; 281 | 243: Result:=162; 282 | 244: Result:=147; 283 | 245: Result:=228; 284 | 246: Result:=148; 285 | 247: Result:=246; 286 | 248: Result:=155; 287 | 249: Result:=151; 288 | 250: Result:=163; 289 | 251: Result:=150; 290 | 252: Result:=129; 291 | 253: Result:=236; 292 | 254: Result:=231; 293 | 255: Result:=152; 294 | 305: Result:=213; 295 | 402: Result:=159; 296 | 8215: Result:=242; 297 | 9472: Result:=196; 298 | 9474: Result:=179; 299 | 9484: Result:=218; 300 | 9488: Result:=191; 301 | 9492: Result:=192; 302 | 9496: Result:=217; 303 | 9500: Result:=195; 304 | 9508: Result:=180; 305 | 9516: Result:=194; 306 | 9524: Result:=193; 307 | 9532: Result:=197; 308 | 9552: Result:=205; 309 | 9553: Result:=186; 310 | 9556: Result:=201; 311 | 9559: Result:=187; 312 | 9562: Result:=200; 313 | 9565: Result:=188; 314 | 9568: Result:=204; 315 | 9571: Result:=185; 316 | 9574: Result:=203; 317 | 9577: Result:=202; 318 | 9580: Result:=206; 319 | 9600: Result:=223; 320 | 9604: Result:=220; 321 | 9608: Result:=219; 322 | 9617..9619: Result:=Unicode-9441; 323 | 9632: Result:=254; 324 | else Result:=-1; 325 | end; 326 | end; 327 | 328 | // ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/CP852.TXT 329 | function UnicodeToCP852(Unicode: cardinal): integer; 330 | begin 331 | case Unicode of 332 | 0..127: Result:=Unicode; 333 | 160: Result:=255; 334 | 164: Result:=207; 335 | 167: Result:=245; 336 | 168: Result:=249; 337 | 171: Result:=174; 338 | 172: Result:=170; 339 | 173: Result:=240; 340 | 176: Result:=248; 341 | 180: Result:=239; 342 | 184: Result:=247; 343 | 187: Result:=175; 344 | 193..194: Result:=Unicode-12; 345 | 196: Result:=142; 346 | 199: Result:=128; 347 | 201: Result:=144; 348 | 203: Result:=211; 349 | 205..206: Result:=Unicode+9; 350 | 211: Result:=224; 351 | 212: Result:=226; 352 | 214: Result:=153; 353 | 215: Result:=158; 354 | 218: Result:=233; 355 | 220: Result:=154; 356 | 221: Result:=237; 357 | 223: Result:=225; 358 | 225: Result:=160; 359 | 226: Result:=131; 360 | 228: Result:=132; 361 | 231: Result:=135; 362 | 233: Result:=130; 363 | 235: Result:=137; 364 | 237: Result:=161; 365 | 238: Result:=140; 366 | 243: Result:=162; 367 | 244: Result:=147; 368 | 246: Result:=148; 369 | 247: Result:=246; 370 | 250: Result:=163; 371 | 252: Result:=129; 372 | 253: Result:=236; 373 | 258..259: Result:=Unicode-60; 374 | 260..261: Result:=Unicode-96; 375 | 262: Result:=143; 376 | 263: Result:=134; 377 | 268: Result:=172; 378 | 269: Result:=159; 379 | 270: Result:=210; 380 | 271: Result:=212; 381 | 272: Result:=209; 382 | 273: Result:=208; 383 | 280..281: Result:=Unicode-112; 384 | 282: Result:=183; 385 | 283: Result:=216; 386 | 313..314: Result:=Unicode-168; 387 | 317..318: Result:=Unicode-168; 388 | 321: Result:=157; 389 | 322: Result:=136; 390 | 323..324: Result:=Unicode-96; 391 | 327: Result:=213; 392 | 328: Result:=229; 393 | 336..337: Result:=Unicode-198; 394 | 340: Result:=232; 395 | 341: Result:=234; 396 | 344..345: Result:=Unicode-92; 397 | 346..347: Result:=Unicode-195; 398 | 350: Result:=184; 399 | 351: Result:=173; 400 | 352..353: Result:=Unicode-122; 401 | 354: Result:=221; 402 | 355: Result:=238; 403 | 356..357: Result:=Unicode-201; 404 | 366: Result:=222; 405 | 367: Result:=133; 406 | 368: Result:=235; 407 | 369: Result:=251; 408 | 377: Result:=141; 409 | 378: Result:=171; 410 | 379..380: Result:=Unicode-190; 411 | 381..382: Result:=Unicode-215; 412 | 711: Result:=243; 413 | 728: Result:=244; 414 | 729: Result:=250; 415 | 731: Result:=242; 416 | 733: Result:=241; 417 | 9472: Result:=196; 418 | 9474: Result:=179; 419 | 9484: Result:=218; 420 | 9488: Result:=191; 421 | 9492: Result:=192; 422 | 9496: Result:=217; 423 | 9500: Result:=195; 424 | 9508: Result:=180; 425 | 9516: Result:=194; 426 | 9524: Result:=193; 427 | 9532: Result:=197; 428 | 9552: Result:=205; 429 | 9553: Result:=186; 430 | 9556: Result:=201; 431 | 9559: Result:=187; 432 | 9562: Result:=200; 433 | 9565: Result:=188; 434 | 9568: Result:=204; 435 | 9571: Result:=185; 436 | 9574: Result:=203; 437 | 9577: Result:=202; 438 | 9580: Result:=206; 439 | 9600: Result:=223; 440 | 9604: Result:=220; 441 | 9608: Result:=219; 442 | 9617..9619: Result:=Unicode-9441; 443 | 9632: Result:=254; 444 | else Result:=-1; 445 | end; 446 | end; 447 | 448 | function UnicodeToCP861(Unicode: cardinal): integer; 449 | begin 450 | case Unicode of 451 | 0..127: Result:=Unicode; 452 | 160: Result:=255; 453 | 161: Result:=173; 454 | 163: Result:=163-7; 455 | 171: Result:=174; 456 | 172: Result:=170; 457 | 176: Result:=248; 458 | 177: Result:=241; 459 | 178: Result:=253; 460 | 181: Result:=230; 461 | 183: Result:=250; 462 | 187: Result:=$AF; 463 | 188: Result:=172; 464 | 189: Result:=171; 465 | 191: Result:=168; 466 | 193: Result:=$A4; 467 | 196..197: Result:=Unicode-54; 468 | 198: Result:=146; 469 | 199: Result:=128; 470 | 201: Result:=144; 471 | 205: Result:=$A5; 472 | 208: Result:=$8B; 473 | 211: Result:=$A6; 474 | 214: Result:=153; 475 | 216: Result:=$9D; 476 | 218: Result:=$A7; 477 | 220: Result:=154; 478 | 221: Result:=$97; 479 | 222: Result:=$8D; 480 | 223: Result:=225; 481 | 224: Result:=133; 482 | 225: Result:=160; 483 | 226: Result:=131; 484 | 228: Result:=132; 485 | 229: Result:=134; 486 | 230: Result:=145; 487 | 231: Result:=135; 488 | 232: Result:=138; 489 | 233: Result:=130; 490 | 234..235: Result:=Unicode-98; 491 | 237: Result:=161; 492 | 240: Result:=$8C; 493 | 243: Result:=162; 494 | 244: Result:=147; 495 | 246: Result:=148; 496 | 247: Result:=246; 497 | 248: Result:=$9B; 498 | 250: Result:=163; 499 | 251: Result:=150; 500 | 252: Result:=129; 501 | 253: Result:=$98; 502 | 254: Result:=$95; 503 | 262: Result := 93; 504 | 263: Result := 125; 505 | 268: Result := 94; 506 | 269: Result := 126; 507 | 272: Result := 92; 508 | 273: Result := 124; 509 | 381: Result := 64; 510 | 382: Result := 96; 511 | 352: Result := 91; 512 | 353: Result := 123; 513 | 402: Result:=159; 514 | 915: Result:=226; 515 | 920: Result:=233; 516 | 931: Result:=228; 517 | 934: Result:=232; 518 | 937: Result:=234; 519 | 945: Result:=224; 520 | 948: Result:=235; 521 | 949: Result:=238; 522 | 960: Result:=227; 523 | 963: Result:=229; 524 | 964: Result:=231; 525 | 966: Result:=237; 526 | 8319: Result:=252; 527 | 8359: Result:=158; 528 | 8729: Result:=249; 529 | 8730: Result:=251; 530 | 8734: Result:=236; 531 | 8745: Result:=239; 532 | 8776: Result:=247; 533 | 8801: Result:=240; 534 | 8804: Result:=243; 535 | 8805: Result:=242; 536 | 8976: Result:=169; 537 | 8992..8993: Result:=Unicode-8748; 538 | 9472: Result:=196; 539 | 9474: Result:=179; 540 | 9484: Result:=218; 541 | 9488: Result:=191; 542 | 9492: Result:=192; 543 | 9496: Result:=217; 544 | 9500: Result:=195; 545 | 9508: Result:=180; 546 | 9516: Result:=194; 547 | 9524: Result:=193; 548 | 9532: Result:=197; 549 | 9552: Result:=205; 550 | 9553: Result:=186; 551 | 9554..9555: Result:=Unicode-9341; 552 | 9556: Result:=201; 553 | 9557: Result:=184; 554 | 9558: Result:=183; 555 | 9559: Result:=187; 556 | 9560: Result:=212; 557 | 9561: Result:=211; 558 | 9562: Result:=200; 559 | 9563: Result:=190; 560 | 9564: Result:=189; 561 | 9565: Result:=188; 562 | 9566..9567: Result:=Unicode-9368; 563 | 9568: Result:=204; 564 | 9569..9570: Result:=Unicode-9388; 565 | 9571: Result:=185; 566 | 9572..9573: Result:=Unicode-9363; 567 | 9574: Result:=203; 568 | 9575..9576: Result:=Unicode-9368; 569 | 9577: Result:=202; 570 | 9578: Result:=216; 571 | 9579: Result:=215; 572 | 9580: Result:=206; 573 | 9600: Result:=223; 574 | 9604: Result:=220; 575 | 9608: Result:=219; 576 | 9612: Result:=221; 577 | 9616: Result:=222; 578 | 9617..9619: Result:=Unicode-9441; 579 | 9632: Result:=254; 580 | else Result:=-1; 581 | end; 582 | end; 583 | 584 | function UnicodeToCP865(Unicode: cardinal): integer; 585 | begin 586 | case Unicode of 587 | 0..127: Result:=Unicode; 588 | 160: Result:=255; 589 | 161: Result:=173; 590 | 163: Result:=163-7; 591 | 164: Result:=$AF; 592 | 170: Result:=166; 593 | 171: Result:=174; 594 | 172: Result:=170; 595 | 176: Result:=248; 596 | 177: Result:=241; 597 | 178: Result:=253; 598 | 181: Result:=230; 599 | 183: Result:=250; 600 | 186: Result:=167; 601 | 188: Result:=172; 602 | 189: Result:=171; 603 | 191: Result:=168; 604 | 196..197: Result:=Unicode-54; 605 | 198: Result:=146; 606 | 199: Result:=128; 607 | 201: Result:=144; 608 | 209: Result:=165; 609 | 214: Result:=153; 610 | 216: Result:=$9D; 611 | 220: Result:=154; 612 | 223: Result:=225; 613 | 224: Result:=133; 614 | 225: Result:=160; 615 | 226: Result:=131; 616 | 228: Result:=132; 617 | 229: Result:=134; 618 | 230: Result:=145; 619 | 231: Result:=135; 620 | 232: Result:=138; 621 | 233: Result:=130; 622 | 234..235: Result:=Unicode-98; 623 | 236: Result:=141; 624 | 237: Result:=161; 625 | 238: Result:=140; 626 | 239: Result:=139; 627 | 241: Result:=164; 628 | 242: Result:=149; 629 | 243: Result:=162; 630 | 244: Result:=147; 631 | 246: Result:=148; 632 | 247: Result:=246; 633 | 248: Result:=$9B; 634 | 249: Result:=151; 635 | 250: Result:=163; 636 | 251: Result:=150; 637 | 252: Result:=129; 638 | 255: Result:=152; 639 | 262: Result := 93; 640 | 263: Result := 125; 641 | 268: Result := 94; 642 | 269: Result := 126; 643 | 272: Result := 92; 644 | 273: Result := 124; 645 | 381: Result := 64; 646 | 382: Result := 96; 647 | 352: Result := 91; 648 | 353: Result := 123; 649 | 402: Result:=159; 650 | 915: Result:=226; 651 | 920: Result:=233; 652 | 931: Result:=228; 653 | 934: Result:=232; 654 | 937: Result:=234; 655 | 945: Result:=224; 656 | 948: Result:=235; 657 | 949: Result:=238; 658 | 960: Result:=227; 659 | 963: Result:=229; 660 | 964: Result:=231; 661 | 966: Result:=237; 662 | 8319: Result:=252; 663 | 8359: Result:=158; 664 | 8729: Result:=249; 665 | 8730: Result:=251; 666 | 8734: Result:=236; 667 | 8745: Result:=239; 668 | 8776: Result:=247; 669 | 8801: Result:=240; 670 | 8804: Result:=243; 671 | 8805: Result:=242; 672 | 8976: Result:=169; 673 | 8992..8993: Result:=Unicode-8748; 674 | 9472: Result:=196; 675 | 9474: Result:=179; 676 | 9484: Result:=218; 677 | 9488: Result:=191; 678 | 9492: Result:=192; 679 | 9496: Result:=217; 680 | 9500: Result:=195; 681 | 9508: Result:=180; 682 | 9516: Result:=194; 683 | 9524: Result:=193; 684 | 9532: Result:=197; 685 | 9552: Result:=205; 686 | 9553: Result:=186; 687 | 9554..9555: Result:=Unicode-9341; 688 | 9556: Result:=201; 689 | 9557: Result:=184; 690 | 9558: Result:=183; 691 | 9559: Result:=187; 692 | 9560: Result:=212; 693 | 9561: Result:=211; 694 | 9562: Result:=200; 695 | 9563: Result:=190; 696 | 9564: Result:=189; 697 | 9565: Result:=188; 698 | 9566..9567: Result:=Unicode-9368; 699 | 9568: Result:=204; 700 | 9569..9570: Result:=Unicode-9388; 701 | 9571: Result:=185; 702 | 9572..9573: Result:=Unicode-9363; 703 | 9574: Result:=203; 704 | 9575..9576: Result:=Unicode-9368; 705 | 9577: Result:=202; 706 | 9578: Result:=216; 707 | 9579: Result:=215; 708 | 9580: Result:=206; 709 | 9600: Result:=223; 710 | 9604: Result:=220; 711 | 9608: Result:=219; 712 | 9612: Result:=221; 713 | 9616: Result:=222; 714 | 9617..9619: Result:=Unicode-9441; 715 | 9632: Result:=254; 716 | else Result:=-1; 717 | end; 718 | end; 719 | 720 | function UnicodeToCP866(Unicode: cardinal): integer; 721 | begin 722 | case Unicode of 723 | 0..127: Result:=Unicode; 724 | 1040..1087 : Result := Unicode-912; 725 | 9617..9619 : Result := Unicode-9441; 726 | 9474 : Result := 179; 727 | 9508 : Result := 180; 728 | 9569 : Result := 181; 729 | 9570 : Result := 182; 730 | 9558 : Result := 183; 731 | 9557 : Result := 184; 732 | 9571 : Result := 185; 733 | 9553 : Result := 186; 734 | 9559 : Result := 187; 735 | 9565 : Result := 188; 736 | 9564 : Result := 189; 737 | 9563 : Result := 190; 738 | 9488 : Result := 191; 739 | 9492 : Result := 192; 740 | 9524 : Result := 193; 741 | 9516 : Result := 194; 742 | 9500 : Result := 195; 743 | 9472 : Result := 196; 744 | 9532 : Result := 197; 745 | 9566 : Result := 198; 746 | 9567 : Result := 199; 747 | 9562 : Result := 200; 748 | 9556 : Result := 201; 749 | 9577 : Result := 202; 750 | 9574 : Result := 203; 751 | 9568 : Result := 204; 752 | 9552 : Result := 205; 753 | 9580 : Result := 206; 754 | 9575 : Result := 207; 755 | 9576 : Result := 208; 756 | 9572 : Result := 209; 757 | 9573 : Result := 210; 758 | 9561 : Result := 211; 759 | 9560 : Result := 212; 760 | 9554 : Result := 213; 761 | 9555 : Result := 214; 762 | 9579 : Result := 215; 763 | 9578 : Result := 216; 764 | 9496 : Result := 217; 765 | 9484 : Result := 218; 766 | 9608 : Result := 219; 767 | 9604 : Result := 220; 768 | 9612 : Result := 221; 769 | 9616 : Result := 222; 770 | 9600 : Result := 223; 771 | 1088..1103 : Result := Unicode-864; 772 | 1025 : Result := 240; 773 | 1105 : Result := 241; 774 | 1028 : Result := 242; 775 | 1108 : Result := 243; 776 | 1031 : Result := 244; 777 | 1111 : Result := 245; 778 | 1038 : Result := 246; 779 | 1118 : Result := 247; 780 | 176 : Result := 248; 781 | 8729 : Result := 249; 782 | 183 : Result := 250; 783 | 8730 : Result := 251; 784 | 8470 : Result := 252; 785 | 164 : Result := 253; 786 | 9632 : Result := 254; 787 | 160 : Result := 255; 788 | else Result:=-1; 789 | end; 790 | end; 791 | 792 | function UnicodeToKOI8R(Unicode: cardinal): integer; 793 | begin 794 | case Unicode of 795 | 0..127: Result:=Unicode; 796 | 160: Result:=154; 797 | 169: Result:=191; 798 | 176: Result:=156; 799 | 178: Result:=157; 800 | 183: Result:=158; 801 | 247: Result:=159; 802 | 1025: Result:=179; 803 | 1040..1041: Result:=Unicode-815; 804 | 1042: Result:=247; 805 | 1043: Result:=231; 806 | 1044..1045: Result:=Unicode-816; 807 | 1046: Result:=246; 808 | 1047: Result:=250; 809 | 1048..1055: Result:=Unicode-815; 810 | 1056..1059: Result:=Unicode-814; 811 | 1060: Result:=230; 812 | 1061: Result:=232; 813 | 1062: Result:=227; 814 | 1063: Result:=254; 815 | 1064: Result:=251; 816 | 1065: Result:=253; 817 | 1066: Result:=255; 818 | 1067: Result:=249; 819 | 1068: Result:=248; 820 | 1069: Result:=252; 821 | 1070: Result:=224; 822 | 1071: Result:=241; 823 | 1072..1073: Result:=Unicode-879; 824 | 1074: Result:=215; 825 | 1075: Result:=199; 826 | 1076..1077: Result:=Unicode-880; 827 | 1078: Result:=214; 828 | 1079: Result:=218; 829 | 1080..1087: Result:=Unicode-879; 830 | 1088..1091: Result:=Unicode-878; 831 | 1092: Result:=198; 832 | 1093: Result:=200; 833 | 1094: Result:=195; 834 | 1095: Result:=222; 835 | 1096: Result:=219; 836 | 1097: Result:=221; 837 | 1098: Result:=223; 838 | 1099: Result:=217; 839 | 1100: Result:=216; 840 | 1101: Result:=220; 841 | 1102: Result:=192; 842 | 1103: Result:=209; 843 | 1105: Result:=163; 844 | 8729: Result:=149; 845 | 8730: Result:=150; 846 | 8776: Result:=151; 847 | 8804: Result:=152; 848 | 8805: Result:=153; 849 | 8992: Result:=147; 850 | 8993: Result:=155; 851 | 9472: Result:=128; 852 | 9474: Result:=129; 853 | 9484: Result:=130; 854 | 9488: Result:=131; 855 | 9492: Result:=132; 856 | 9496: Result:=133; 857 | 9500: Result:=134; 858 | 9508: Result:=135; 859 | 9516: Result:=136; 860 | 9524: Result:=137; 861 | 9532: Result:=138; 862 | 9552..9554: Result:=Unicode-9392; 863 | 9555..9569: Result:=Unicode-9391; 864 | 9570..9580: Result:=Unicode-9390; 865 | 9600: Result:=139; 866 | 9604: Result:=140; 867 | 9608: Result:=141; 868 | 9612: Result:=142; 869 | 9616..9619: Result:=Unicode-9473; 870 | 9632: Result:=148; 871 | else Result:=-1; 872 | end; 873 | end; 874 | 875 | function UnicodeToKOI8U(Unicode: cardinal): integer; 876 | begin 877 | case Unicode of 878 | 1028: Result:=180; 879 | 1030..1031: Result:=Unicode-848; 880 | 1108: Result:=164; 881 | 1110..1111: Result:=Unicode-944; 882 | 1168: Result:=189; 883 | 1169: Result:=173; 884 | else 885 | Result:=UnicodeToKOI8R(Unicode); 886 | end; 887 | end; 888 | 889 | function UnicodeToKOI8RU(Unicode: cardinal): integer; 890 | begin 891 | case Unicode of 892 | 164 : Result:=159; 893 | 171 : Result:=157; 894 | 174 : Result:=156; 895 | 187 : Result:=155; 896 | 1038: Result:=190; 897 | 1118: Result:=174; 898 | 8212: Result:=151; 899 | 8220: Result:=147; 900 | 8221: Result:=150; 901 | 8470: Result:=152; 902 | 8482: Result:=153; 903 | else 904 | Result:=UnicodeToKOI8U(Unicode); 905 | end; 906 | end; 907 | 908 | function UnicodeToISO_8859_1(Unicode: cardinal): integer; 909 | begin 910 | case Unicode of 911 | 0..255: Result:=Unicode; 912 | else Result:=-1; 913 | end; 914 | end; 915 | 916 | function UnicodeToISO_8859_3(Unicode: cardinal): integer; 917 | begin 918 | case Unicode of 919 | 0..255: Result:= Unicode; 920 | $126: Result:= $A1; 921 | $2D8: Result:= $A2; 922 | $124: Result:= $A6; 923 | $130: Result:= $A9; 924 | $15E: Result:= $AA; 925 | $11E: Result:= $AB; 926 | $134: Result:= $AC; 927 | $17B: Result:= $AF; 928 | $127: Result:= $B1; 929 | $125: Result:= $B6; 930 | $131: Result:= $B9; 931 | $15F: Result:= $BA; 932 | $11F: Result:= $BB; 933 | $135: Result:= $BC; 934 | $17C: Result:= $BF; 935 | $10A: Result:= $C5; 936 | $108: Result:= $C6; 937 | $120: Result:= $D5; 938 | $11C: Result:= $D8; 939 | $16C: Result:= $DD; 940 | $15C: Result:= $DE; 941 | $10B: Result:= $E5; 942 | $109: Result:= $E6; 943 | $121: Result:= $F5; 944 | $11D: Result:= $F8; 945 | $16D: Result:= $FD; 946 | $15D: Result:= $FE; 947 | $2D9: Result:= $FF; 948 | else Result:= -1; 949 | end; 950 | end; 951 | 952 | function UnicodeToISO_8859_4(Unicode: cardinal): integer; 953 | begin 954 | case Unicode of 955 | 0..$A0, $A4, $A7, $A8, $AD, $AF, 956 | $B0, $B4, $B8, 957 | $C1..$C6, $C9, $CB, $CD, $CE, 958 | $D4..$D8, $DA..$DC, $DF, 959 | $E1..$E6, $E9, $EB, $ED, $EE, 960 | $F4..$F9, $FA..$FC: Result:= Unicode; 961 | $104: Result:= $A1; 962 | $138: Result:= $A2; 963 | $156: Result:= $A3; 964 | $128: Result:= $A5; 965 | $13B: Result:= $A6; 966 | $160: Result:= $A9; 967 | $112: Result:= $AA; 968 | $122: Result:= $AB; 969 | $166: Result:= $AC; 970 | $17D: Result:= $AE; 971 | $105: Result:= $B1; 972 | $2DB: Result:= $B2; 973 | $157: Result:= $B3; 974 | $129: Result:= $B5; 975 | $13C: Result:= $B6; 976 | $2C7: Result:= $B7; 977 | $161: Result:= $B9; 978 | $113: Result:= $BA; 979 | $123: Result:= $BB; 980 | $167: Result:= $BC; 981 | $14A: Result:= $BD; 982 | $17E: Result:= $BE; 983 | $14B: Result:= $BF; 984 | $100: Result:= $C0; 985 | $12E: Result:= $C7; 986 | $10C: Result:= $C8; 987 | $118: Result:= $CA; 988 | $116: Result:= $CC; 989 | $12A: Result:= $CF; 990 | $110: Result:= $D0; 991 | $145: Result:= $D1; 992 | $14C: Result:= $D2; 993 | $136: Result:= $D3; 994 | $172: Result:= $D9; 995 | $168: Result:= $DD; 996 | $16A: Result:= $DE; 997 | $101: Result:= $E0; 998 | $12F: Result:= $E7; 999 | $10D: Result:= $E8; 1000 | $119: Result:= $EA; 1001 | $117: Result:= $EC; 1002 | $12B: Result:= $EF; 1003 | $111: Result:= $F0; 1004 | $146: Result:= $F1; 1005 | $14D: Result:= $F2; 1006 | $137: Result:= $F3; 1007 | $173: Result:= $F9; 1008 | $169: Result:= $FD; 1009 | $16B: Result:= $FE; 1010 | $2D9: Result:= $FF; 1011 | else Result:= -1; 1012 | end; 1013 | end; 1014 | 1015 | function UnicodeToISO_8859_9(Unicode: cardinal): integer; 1016 | begin 1017 | case Unicode of 1018 | 0..255: Result:=Unicode; 1019 | $011E: Result:= $D0; 1020 | $0130: Result:= $DD; 1021 | $015E: Result:= $DE; 1022 | $011F: Result:= $F0; 1023 | $0131: Result:= $FD; 1024 | $015F: Result:= $FE; 1025 | else Result:=-1; 1026 | end; 1027 | end; 1028 | 1029 | function UnicodeToISO_8859_10(Unicode: cardinal): integer; 1030 | begin 1031 | case Unicode of 1032 | 0..255: Result:= Unicode; 1033 | $104: Result:= $A1; 1034 | $112: Result:= $A2; 1035 | $122: Result:= $A3; 1036 | $12A: Result:= $A4; 1037 | $128: Result:= $A5; 1038 | $136: Result:= $A6; 1039 | $13B: Result:= $A8; 1040 | $110: Result:= $A9; 1041 | $160: Result:= $AA; 1042 | $166: Result:= $AB; 1043 | $17D: Result:= $AC; 1044 | $16A: Result:= $AE; 1045 | $14A: Result:= $AF; 1046 | $105: Result:= $B1; 1047 | $113: Result:= $B2; 1048 | $123: Result:= $B3; 1049 | $12B: Result:= $B4; 1050 | $129: Result:= $B5; 1051 | $137: Result:= $B6; 1052 | $13C: Result:= $B8; 1053 | $111: Result:= $B9; 1054 | $161: Result:= $BA; 1055 | $167: Result:= $BB; 1056 | $17E: Result:= $BC; 1057 | $2015: Result:= $BD; 1058 | $16B: Result:= $BE; 1059 | $14B: Result:= $BF; 1060 | $100: Result:= $C0; 1061 | $12E: Result:= $C7; 1062 | $10C: Result:= $C8; 1063 | $118: Result:= $CA; 1064 | $116: Result:= $CC; 1065 | $145: Result:= $D1; 1066 | $14C: Result:= $D2; 1067 | $168: Result:= $D7; 1068 | $172: Result:= $D9; 1069 | $101: Result:= $E0; 1070 | $12F: Result:= $E7; 1071 | $10D: Result:= $E8; 1072 | $119: Result:= $EA; 1073 | $117: Result:= $EC; 1074 | $146: Result:= $F1; 1075 | $14D: Result:= $F2; 1076 | $169: Result:= $F7; 1077 | $173: Result:= $F9; 1078 | $138: Result:= $FF; 1079 | else Result:=-1; 1080 | end; 1081 | end; 1082 | 1083 | function UnicodeToISO_8859_13(Unicode: cardinal): integer; 1084 | begin 1085 | case Unicode of 1086 | 0..$A0, 1087 | $A2, $A3, $A4, $A6, $A7, $A9, $AB, $AC, $AD, $AE, 1088 | $B0..$B3, $B5..$B7, $B9, $BB..$BE, 1089 | $C4, $C5, $C9, 1090 | $D3, $D5..$D7, $DC, $DF, 1091 | $E4, $E5, $E9, 1092 | $F3, $F5..$F7, $FC: Result:= Unicode; 1093 | $201D: Result:= $A1; 1094 | $201E: Result:= $A5; 1095 | $D8: Result:= $A8; 1096 | $156: Result:= $AA; 1097 | $C6: Result:= $AF; 1098 | $201C: Result:= $B4; 1099 | $F8: Result:= $B8; 1100 | $157: Result:= $BA; 1101 | $E6: Result:= $BF; 1102 | $104: Result:= $C0; 1103 | $12E: Result:= $C1; 1104 | $100: Result:= $C2; 1105 | $106: Result:= $C3; 1106 | $118: Result:= $C6; 1107 | $112: Result:= $C7; 1108 | $10C: Result:= $C8; 1109 | $179: Result:= $CA; 1110 | $116: Result:= $CB; 1111 | $122: Result:= $CC; 1112 | $136: Result:= $CD; 1113 | $12A: Result:= $CE; 1114 | $13B: Result:= $CF; 1115 | $160: Result:= $D0; 1116 | $143: Result:= $D1; 1117 | $145: Result:= $D2; 1118 | $14C: Result:= $D4; 1119 | $172: Result:= $D8; 1120 | $141: Result:= $D9; 1121 | $15A: Result:= $DA; 1122 | $16A: Result:= $DB; 1123 | $17B: Result:= $DD; 1124 | $17D: Result:= $DE; 1125 | $105: Result:= $E0; 1126 | $12F: Result:= $E1; 1127 | $101: Result:= $E2; 1128 | $107: Result:= $E3; 1129 | $119: Result:= $E6; 1130 | $113: Result:= $E7; 1131 | $10D: Result:= $E8; 1132 | $17A: Result:= $EA; 1133 | $117: Result:= $EB; 1134 | $123: Result:= $EC; 1135 | $137: Result:= $ED; 1136 | $12B: Result:= $EE; 1137 | $13C: Result:= $EF; 1138 | $161: Result:= $F0; 1139 | $144: Result:= $F1; 1140 | $146: Result:= $F2; 1141 | $14D: Result:= $F4; 1142 | $173: Result:= $F8; 1143 | $142: Result:= $F9; 1144 | $15B: Result:= $FA; 1145 | $16B: Result:= $FB; 1146 | $17C: Result:= $FD; 1147 | $17E: Result:= $FE; 1148 | $2019: Result:= $FF; 1149 | else Result:= -1; 1150 | end; 1151 | end; 1152 | 1153 | function UnicodeToISO_8859_14(Unicode: cardinal): integer; 1154 | begin 1155 | case Unicode of 1156 | 0..$A0: Result:=Unicode; 1157 | $A3, 1158 | $A7, 1159 | $A9, 1160 | $AD, 1161 | $AE, 1162 | $B6: Result:= Unicode; 1163 | $1E02: Result:= $A1; 1164 | $1E03: Result:= $A2; 1165 | $10A: Result:= $A4; 1166 | $10B: Result:= $A5; 1167 | $1E0A: Result:= $A6; 1168 | $1E80: Result:= $A8; 1169 | $1E82: Result:= $AA; 1170 | $1E0B: Result:= $AB; 1171 | $1EF2: Result:= $AC; 1172 | $178: Result:= $AF; 1173 | $1E1E: Result:= $B0; 1174 | $1E1F: Result:= $B1; 1175 | $120: Result:= $B2; 1176 | $121: Result:= $B3; 1177 | $1E40: Result:= $B4; 1178 | $1E41: Result:= $B5; 1179 | $1E56: Result:= $B7; 1180 | $1E81: Result:= $B8; 1181 | $1E57: Result:= $B9; 1182 | $1E83: Result:= $BA; 1183 | $1E60: Result:= $BB; 1184 | $1EF3: Result:= $BC; 1185 | $1E84: Result:= $BD; 1186 | $1E85: Result:= $BE; 1187 | $1E61: Result:= $BF; 1188 | $C0..$CF: Result:= Unicode; 1189 | $174: Result:= $D0; 1190 | $D1..$D6: Result:= Unicode; 1191 | $1E6A: Result:= $D7; 1192 | $D8..$DD: Result:= Unicode; 1193 | $176: Result:= $DE; 1194 | $DF..$EF: Result:= Unicode; 1195 | $175: Result:= $F0; 1196 | $F1..$F6: Result:= Unicode; 1197 | $1E6B: Result:= $F7; 1198 | $F8..$FD: Result:= Unicode; 1199 | $177: Result:= $FE; 1200 | $FF: Result:= $FF; 1201 | else Result:=-1; 1202 | end; 1203 | end; 1204 | 1205 | 1206 | function UnicodeToISO_8859_15(Unicode: cardinal): integer; 1207 | begin 1208 | case Unicode of 1209 | 0..255: Result:=Unicode; 1210 | 8364: Result:=164; 1211 | 352: Result:=166; 1212 | 353: Result:=168; 1213 | 381: Result:=180; 1214 | 382: Result:=184; 1215 | 338: Result:=188; 1216 | 339: Result:=189; 1217 | 376: Result:=190; 1218 | else Result:=-1; 1219 | end; 1220 | end; 1221 | 1222 | function UnicodeToISO_8859_16(Unicode: cardinal): integer; 1223 | begin 1224 | case Unicode of 1225 | 0..255: Result:=Unicode; 1226 | $104: Result:= $A1; 1227 | $105: Result:= $A2; 1228 | $141: Result:= $A3; 1229 | $20AC: Result:= $A4; 1230 | $201E: Result:= $A5; 1231 | $160: Result:= $A6; 1232 | $161: Result:= $A8; 1233 | $218: Result:= $AA; 1234 | $179: Result:= $AC; 1235 | $17A: Result:= $AE; 1236 | $17B: Result:= $AF; 1237 | $10C: Result:= $B2; 1238 | $142: Result:= $B3; 1239 | $17D: Result:= $B4; 1240 | $201D: Result:= $B5; 1241 | $17E: Result:= $B8; 1242 | $10D: Result:= $B9; 1243 | $219: Result:= $BA; 1244 | $152: Result:= $BC; 1245 | $153: Result:= $BD; 1246 | $178: Result:= $BE; 1247 | $17C: Result:= $BF; 1248 | $102: Result:= $C3; 1249 | $106: Result:= $C5; 1250 | $110: Result:= $D0; 1251 | $143: Result:= $D1; 1252 | $150: Result:= $D5; 1253 | $15A: Result:= $D7; 1254 | $170: Result:= $D8; 1255 | $118: Result:= $DD; 1256 | $21A: Result:= $DE; 1257 | $103: Result:= $E3; 1258 | $107: Result:= $E5; 1259 | $111: Result:= $F0; 1260 | $144: Result:= $F1; 1261 | $151: Result:= $F5; 1262 | $15B: Result:= $F7; 1263 | $171: Result:= $F8; 1264 | $119: Result:= $FD; 1265 | $21B: Result:= $FE; 1266 | else Result:=-1; 1267 | end; 1268 | end; 1269 | 1270 | function UnicodeToISO_8859_2(Unicode: cardinal): integer; 1271 | begin 1272 | case Unicode of 1273 | 0..127: Result:=Unicode; 1274 | 128..160: Result:=Unicode; 1275 | 164: Result:=164; 1276 | 167..168: Result:=Unicode; 1277 | 173: Result:=173; 1278 | 176: Result:=176; 1279 | 180: Result:=180; 1280 | 184: Result:=184; 1281 | 193..194: Result:=Unicode; 1282 | 196: Result:=196; 1283 | 199: Result:=199; 1284 | 201: Result:=201; 1285 | 203: Result:=203; 1286 | 205..206: Result:=Unicode; 1287 | 211..212: Result:=Unicode; 1288 | 214..215: Result:=Unicode; 1289 | 218: Result:=218; 1290 | 220..221: Result:=Unicode; 1291 | 223: Result:=223; 1292 | 225..226: Result:=Unicode; 1293 | 228: Result:=228; 1294 | 231: Result:=231; 1295 | 233: Result:=233; 1296 | 235: Result:=235; 1297 | 237..238: Result:=Unicode; 1298 | 243..244: Result:=Unicode; 1299 | 246..247: Result:=Unicode; 1300 | 250: Result:=250; 1301 | 252..253: Result:=Unicode; 1302 | 258: Result:=195; 1303 | 259: Result:=227; 1304 | 260: Result:=161; 1305 | 261: Result:=177; 1306 | 262: Result:=198; 1307 | 263: Result:=230; 1308 | 268: Result:=200; 1309 | 269: Result:=232; 1310 | 270: Result:=207; 1311 | 271: Result:=239; 1312 | 272: Result:=208; 1313 | 273: Result:=240; 1314 | 280: Result:=202; 1315 | 281: Result:=234; 1316 | 282: Result:=204; 1317 | 283: Result:=236; 1318 | 313: Result:=197; 1319 | 314: Result:=229; 1320 | 317: Result:=165; 1321 | 318: Result:=181; 1322 | 321: Result:=163; 1323 | 322: Result:=179; 1324 | 323: Result:=209; 1325 | 324: Result:=241; 1326 | 327: Result:=210; 1327 | 328: Result:=242; 1328 | 336: Result:=213; 1329 | 337: Result:=245; 1330 | 340: Result:=192; 1331 | 341: Result:=224; 1332 | 344: Result:=216; 1333 | 345: Result:=248; 1334 | 346: Result:=166; 1335 | 347: Result:=182; 1336 | 350: Result:=170; 1337 | 351: Result:=186; 1338 | 352: Result:=169; 1339 | 353: Result:=185; 1340 | 354: Result:=222; 1341 | 355: Result:=254; 1342 | 356: Result:=171; 1343 | 357: Result:=187; 1344 | 366: Result:=217; 1345 | 367: Result:=249; 1346 | 368: Result:=219; 1347 | 369: Result:=251; 1348 | 377: Result:=172; 1349 | 378: Result:=188; 1350 | 379: Result:=175; 1351 | 380: Result:=191; 1352 | 381: Result:=174; 1353 | 382: Result:=190; 1354 | 711: Result:=183; 1355 | 728: Result:=162; 1356 | 729: Result:=255; 1357 | 731: Result:=178; 1358 | 733: Result:=189; 1359 | else Result:=-1; 1360 | end; 1361 | end; 1362 | 1363 | function UnicodeToISO_8859_5(Unicode: cardinal): integer; 1364 | begin 1365 | case Unicode of 1366 | 0..$A6, 1367 | $A8..$FF: Result:= Unicode; 1368 | $401..$40C, 1369 | $40E..$44F: Result:= Unicode-($401-$A1); 1370 | $2116: Result:= $F0; 1371 | $451..$45C, 1372 | $45E..$45F: Result:= Unicode-($451-$F1); 1373 | $A7: Result:= $FD; 1374 | else Result:= -1; 1375 | end; 1376 | end; 1377 | 1378 | function UnicodeToISO_8859_7(Unicode: cardinal): integer; 1379 | begin 1380 | case Unicode of 1381 | 0..$A0, 1382 | $A3, $A6..$A9, $AB..$AE, 1383 | $B0..$B3, $B7, $BB, $BD, 1384 | $D2, $FF: Result:= Unicode; 1385 | $2BD: Result:= $A1; 1386 | $2BC: Result:= $A2; 1387 | $20AC: Result:= $A4; 1388 | $20AF: Result:= $A5; 1389 | $37A: Result:= $AA; 1390 | $2015: Result:= $AF; 1391 | $384..$386, $388..$38A, $38C, 1392 | $38E..$3A1, $3A3..$3CE: Result:= Unicode-($384-$B4); 1393 | else Result:= -1; 1394 | end; 1395 | end; 1396 | 1397 | function UnicodeToMacintosh(Unicode: cardinal): integer; 1398 | begin 1399 | case Unicode of 1400 | 0..127: Result:=Unicode; 1401 | 160: Result:=202; 1402 | 161: Result:=193; 1403 | 162..163: Result:=Unicode; 1404 | 165: Result:=180; 1405 | 167: Result:=164; 1406 | 168: Result:=172; 1407 | 169: Result:=169; 1408 | 170: Result:=187; 1409 | 171: Result:=199; 1410 | 172: Result:=194; 1411 | 174: Result:=168; 1412 | 175: Result:=248; 1413 | 176: Result:=161; 1414 | 177: Result:=177; 1415 | 180: Result:=171; 1416 | 181: Result:=181; 1417 | 182: Result:=166; 1418 | 183: Result:=225; 1419 | 184: Result:=252; 1420 | 186: Result:=188; 1421 | 187: Result:=200; 1422 | 191: Result:=192; 1423 | 192: Result:=203; 1424 | 193: Result:=231; 1425 | 194: Result:=229; 1426 | 195: Result:=204; 1427 | 196..197: Result:=Unicode-68; 1428 | 198: Result:=174; 1429 | 199: Result:=130; 1430 | 200: Result:=233; 1431 | 201: Result:=131; 1432 | 202: Result:=230; 1433 | 203: Result:=232; 1434 | 204: Result:=237; 1435 | 205..207: Result:=Unicode+29; 1436 | 209: Result:=132; 1437 | 210: Result:=241; 1438 | 211..212: Result:=Unicode+27; 1439 | 213: Result:=205; 1440 | 214: Result:=133; 1441 | 216: Result:=175; 1442 | 217: Result:=244; 1443 | 218..219: Result:=Unicode+24; 1444 | 220: Result:=134; 1445 | 223: Result:=167; 1446 | 224: Result:=136; 1447 | 225: Result:=135; 1448 | 226: Result:=137; 1449 | 227: Result:=139; 1450 | 228: Result:=138; 1451 | 229: Result:=140; 1452 | 230: Result:=190; 1453 | 231: Result:=141; 1454 | 232: Result:=143; 1455 | 233: Result:=142; 1456 | 234..235: Result:=Unicode-90; 1457 | 236: Result:=147; 1458 | 237: Result:=146; 1459 | 238..239: Result:=Unicode-90; 1460 | 241: Result:=150; 1461 | 242: Result:=152; 1462 | 243: Result:=151; 1463 | 244: Result:=153; 1464 | 245: Result:=155; 1465 | 246: Result:=154; 1466 | 247: Result:=214; 1467 | 248: Result:=191; 1468 | 249: Result:=157; 1469 | 250: Result:=156; 1470 | 251..252: Result:=Unicode-93; 1471 | 255: Result:=216; 1472 | 305: Result:=245; 1473 | 338..339: Result:=Unicode-132; 1474 | 376: Result:=217; 1475 | 402: Result:=196; 1476 | 710: Result:=246; 1477 | 711: Result:=255; 1478 | 728..730: Result:=Unicode-479; 1479 | 731: Result:=254; 1480 | 732: Result:=247; 1481 | 733: Result:=253; 1482 | 916: Result:=198; 1483 | 937: Result:=189; 1484 | 960: Result:=185; 1485 | 8211..8212: Result:=Unicode-8003; 1486 | 8216..8217: Result:=Unicode-8004; 1487 | 8218: Result:=226; 1488 | 8220..8221: Result:=Unicode-8010; 1489 | 8222: Result:=227; 1490 | 8224: Result:=160; 1491 | 8225: Result:=224; 1492 | 8226: Result:=165; 1493 | 8230: Result:=201; 1494 | 8240: Result:=228; 1495 | 8249..8250: Result:=Unicode-8029; 1496 | 8260: Result:=218; 1497 | 8364: Result:=219; 1498 | 8482: Result:=170; 1499 | 8706: Result:=182; 1500 | 8719: Result:=184; 1501 | 8721: Result:=183; 1502 | 8730: Result:=195; 1503 | 8734: Result:=176; 1504 | 8747: Result:=186; 1505 | 8776: Result:=197; 1506 | 8800: Result:=173; 1507 | 8804..8805: Result:=Unicode-8626; 1508 | 9674: Result:=215; 1509 | 57374: Result:=240; 1510 | 64257..64258: Result:=Unicode-64035; 1511 | else Result:=-1; 1512 | end; 1513 | end; 1514 | 1515 | function UnicodeToCP1250(Unicode: cardinal): integer; 1516 | begin 1517 | case Unicode of 1518 | 0..127,129,131,136,144,152: Result:=Unicode; 1519 | 160: Result:=160; 1520 | 164: Result:=164; 1521 | 166..169: Result:=Unicode; 1522 | 171..174: Result:=Unicode; 1523 | 176..177: Result:=Unicode; 1524 | 180..184: Result:=Unicode; 1525 | 187: Result:=187; 1526 | 193..194: Result:=Unicode; 1527 | 196: Result:=196; 1528 | 199: Result:=199; 1529 | 201: Result:=201; 1530 | 203: Result:=203; 1531 | 205..206: Result:=Unicode; 1532 | 211..212: Result:=Unicode; 1533 | 214..215: Result:=Unicode; 1534 | 218: Result:=218; 1535 | 220..221: Result:=Unicode; 1536 | 223: Result:=223; 1537 | 225..226: Result:=Unicode; 1538 | 228: Result:=228; 1539 | 231: Result:=231; 1540 | 233: Result:=233; 1541 | 235: Result:=235; 1542 | 237..238: Result:=Unicode; 1543 | 243..244: Result:=Unicode; 1544 | 246..247: Result:=Unicode; 1545 | 250: Result:=250; 1546 | 252..253: Result:=Unicode; 1547 | 258: Result:=195; 1548 | 259: Result:=227; 1549 | 260: Result:=165; 1550 | 261: Result:=185; 1551 | 262: Result:=198; 1552 | 263: Result:=230; 1553 | 268: Result:=200; 1554 | 269: Result:=232; 1555 | 270: Result:=207; 1556 | 271: Result:=239; 1557 | 272: Result:=208; 1558 | 273: Result:=240; 1559 | 280: Result:=202; 1560 | 281: Result:=234; 1561 | 282: Result:=204; 1562 | 283: Result:=236; 1563 | 313: Result:=197; 1564 | 314: Result:=229; 1565 | 317: Result:=188; 1566 | 318: Result:=190; 1567 | 321: Result:=163; 1568 | 322: Result:=179; 1569 | 323: Result:=209; 1570 | 324: Result:=241; 1571 | 327: Result:=210; 1572 | 328: Result:=242; 1573 | 336: Result:=213; 1574 | 337: Result:=245; 1575 | 340: Result:=192; 1576 | 341: Result:=224; 1577 | 344: Result:=216; 1578 | 345: Result:=248; 1579 | 346: Result:=140; 1580 | 347: Result:=156; 1581 | 350: Result:=170; 1582 | 351: Result:=186; 1583 | 352: Result:=138; 1584 | 353: Result:=154; 1585 | 354: Result:=222; 1586 | 355: Result:=254; 1587 | 356: Result:=141; 1588 | 357: Result:=157; 1589 | 366: Result:=217; 1590 | 367: Result:=249; 1591 | 368: Result:=219; 1592 | 369: Result:=251; 1593 | 377: Result:=143; 1594 | 378: Result:=159; 1595 | 379: Result:=175; 1596 | 380: Result:=191; 1597 | 381: Result:=142; 1598 | 382: Result:=158; 1599 | 711: Result:=161; 1600 | 728: Result:=162; 1601 | 729: Result:=255; 1602 | 731: Result:=178; 1603 | 733: Result:=189; 1604 | 8211..8212: Result:=Unicode-8061; 1605 | 8216..8217: Result:=Unicode-8071; 1606 | 8218: Result:=130; 1607 | 8220..8221: Result:=Unicode-8073; 1608 | 8222: Result:=132; 1609 | 8224..8225: Result:=Unicode-8090; 1610 | 8226: Result:=149; 1611 | 8230: Result:=133; 1612 | 8240: Result:=137; 1613 | 8249: Result:=139; 1614 | 8250: Result:=155; 1615 | 8364: Result:=128; 1616 | 8482: Result:=153; 1617 | else Result:=-1; 1618 | end; 1619 | end; 1620 | 1621 | function UnicodeToCP1251(Unicode: cardinal): integer; 1622 | begin 1623 | case Unicode of 1624 | 0..127,152: Result:=Unicode; 1625 | 160: Result:=160; 1626 | 164: Result:=164; 1627 | 166..167: Result:=Unicode; 1628 | 169: Result:=169; 1629 | 171..174: Result:=Unicode; 1630 | 176..177: Result:=Unicode; 1631 | 181..183: Result:=Unicode; 1632 | 187: Result:=187; 1633 | 1025: Result:=168; 1634 | 1026..1027: Result:=Unicode-898; 1635 | 1028: Result:=170; 1636 | 1029: Result:=189; 1637 | 1030: Result:=178; 1638 | 1031: Result:=175; 1639 | 1032: Result:=163; 1640 | 1033: Result:=138; 1641 | 1034: Result:=140; 1642 | 1035: Result:=142; 1643 | 1036: Result:=141; 1644 | 1038: Result:=161; 1645 | 1039: Result:=143; 1646 | 1040..1103: Result:=Unicode-848; 1647 | 1105: Result:=184; 1648 | 1106: Result:=144; 1649 | 1107: Result:=131; 1650 | 1108: Result:=186; 1651 | 1109: Result:=190; 1652 | 1110: Result:=179; 1653 | 1111: Result:=191; 1654 | 1112: Result:=188; 1655 | 1113: Result:=154; 1656 | 1114: Result:=156; 1657 | 1115: Result:=158; 1658 | 1116: Result:=157; 1659 | 1118: Result:=162; 1660 | 1119: Result:=159; 1661 | 1168: Result:=165; 1662 | 1169: Result:=180; 1663 | 8211..8212: Result:=Unicode-8061; 1664 | 8216..8217: Result:=Unicode-8071; 1665 | 8218: Result:=130; 1666 | 8220..8221: Result:=Unicode-8073; 1667 | 8222: Result:=132; 1668 | 8224..8225: Result:=Unicode-8090; 1669 | 8226: Result:=149; 1670 | 8230: Result:=133; 1671 | 8240: Result:=137; 1672 | 8249: Result:=139; 1673 | 8250: Result:=155; 1674 | 8364: Result:=136; 1675 | 8470: Result:=185; 1676 | 8482: Result:=153; 1677 | else Result:=-1; 1678 | end; 1679 | end; 1680 | 1681 | function UnicodeToCP1252(Unicode: cardinal): integer; 1682 | begin 1683 | case Unicode of 1684 | 0..127,129,141,143,144,157: Result:=Unicode; 1685 | 160..255: Result:=Unicode; 1686 | 338: Result:=140; 1687 | 339: Result:=156; 1688 | 352: Result:=138; 1689 | 353: Result:=154; 1690 | 376: Result:=159; 1691 | 381: Result:=142; 1692 | 382: Result:=158; 1693 | 402: Result:=131; 1694 | 710: Result:=136; 1695 | 732: Result:=152; 1696 | 8211..8212: Result:=Unicode-8061; 1697 | 8216..8217: Result:=Unicode-8071; 1698 | 8218: Result:=130; 1699 | 8220..8221: Result:=Unicode-8073; 1700 | 8222: Result:=132; 1701 | 8224..8225: Result:=Unicode-8090; 1702 | 8226: Result:=149; 1703 | 8230: Result:=133; 1704 | 8240: Result:=137; 1705 | 8249: Result:=139; 1706 | 8250: Result:=155; 1707 | 8364: Result:=128; 1708 | 8482: Result:=153; 1709 | else Result:=-1; 1710 | end; 1711 | end; 1712 | 1713 | function UnicodeToCP1253(Unicode: cardinal): integer; 1714 | begin 1715 | case Unicode of 1716 | 0..127,129,136,138,140,141,142,143,144,152,154,156,157,158,159,170: Result:=Unicode; 1717 | 160: Result:=160; 1718 | 163..169: Result:=Unicode; 1719 | 171..174: Result:=Unicode; 1720 | 176..179: Result:=Unicode; 1721 | 181..183: Result:=Unicode; 1722 | 187: Result:=187; 1723 | 189: Result:=189; 1724 | 402: Result:=131; 1725 | 900: Result:=180; 1726 | 901..902: Result:=Unicode-740; 1727 | 904..906: Result:=Unicode-720; 1728 | 908: Result:=188; 1729 | 910..975: Result:=Unicode-720; 1730 | 8211..8212: Result:=Unicode-8061; 1731 | 8213: Result:=175; 1732 | 8216..8217: Result:=Unicode-8071; 1733 | 8218: Result:=130; 1734 | 8220..8221: Result:=Unicode-8073; 1735 | 8222: Result:=132; 1736 | 8224..8225: Result:=Unicode-8090; 1737 | 8226: Result:=149; 1738 | 8230: Result:=133; 1739 | 8240: Result:=137; 1740 | 8249: Result:=139; 1741 | 8250: Result:=155; 1742 | 8364: Result:=128; 1743 | 8482: Result:=153; 1744 | else Result:=-1; 1745 | end; 1746 | end; 1747 | 1748 | function UnicodeToCP1254(Unicode: cardinal): integer; 1749 | begin 1750 | case Unicode of 1751 | 0..127,129,141,142,143,144,157,158: Result:=Unicode; 1752 | 160..207: Result:=Unicode; 1753 | 209..220: Result:=Unicode; 1754 | 223..239: Result:=Unicode; 1755 | 241..252: Result:=Unicode; 1756 | 255: Result:=255; 1757 | 286: Result:=208; 1758 | 287: Result:=240; 1759 | 304: Result:=221; 1760 | 305: Result:=253; 1761 | 338: Result:=140; 1762 | 339: Result:=156; 1763 | 350: Result:=222; 1764 | 351: Result:=254; 1765 | 352: Result:=138; 1766 | 353: Result:=154; 1767 | 376: Result:=159; 1768 | 402: Result:=131; 1769 | 710: Result:=136; 1770 | 732: Result:=152; 1771 | 8211..8212: Result:=Unicode-8061; 1772 | 8216..8217: Result:=Unicode-8071; 1773 | 8218: Result:=130; 1774 | 8220..8221: Result:=Unicode-8073; 1775 | 8222: Result:=132; 1776 | 8224..8225: Result:=Unicode-8090; 1777 | 8226: Result:=149; 1778 | 8230: Result:=133; 1779 | 8240: Result:=137; 1780 | 8249: Result:=139; 1781 | 8250: Result:=155; 1782 | 8364: Result:=128; 1783 | 8482: Result:=153; 1784 | else Result:=-1; 1785 | end; 1786 | end; 1787 | 1788 | function UnicodeToCP1255(Unicode: cardinal): integer; 1789 | begin 1790 | case Unicode of 1791 | 0..127,129,138,140..144,154: Result:=Unicode; 1792 | 156..163: Result:=Unicode; 1793 | 165..169: Result:=Unicode; 1794 | 171..185: Result:=Unicode; 1795 | 187..191: Result:=Unicode; 1796 | 215: Result:=170; 1797 | 247: Result:=186; 1798 | 402: Result:=131; 1799 | 710: Result:=136; 1800 | 732: Result:=152; 1801 | 1456..1475: Result:=Unicode-1264; 1802 | 1488..1516: Result:=Unicode-1264; 1803 | 1517: Result:=255; 1804 | 1520..1535: Result:=Unicode-1308; 1805 | 8206..8207: Result:=Unicode-7953; 1806 | 8211..8212: Result:=Unicode-8061; 1807 | 8216..8217: Result:=Unicode-8071; 1808 | 8218: Result:=130; 1809 | 8220..8221: Result:=Unicode-8073; 1810 | 8222: Result:=132; 1811 | 8224..8225: Result:=Unicode-8090; 1812 | 8226: Result:=149; 1813 | 8230: Result:=133; 1814 | 8240: Result:=137; 1815 | 8249: Result:=139; 1816 | 8250: Result:=155; 1817 | 8362: Result:=164; 1818 | 8364: Result:=128; 1819 | 8482: Result:=153; 1820 | else Result:=-1; 1821 | end; 1822 | end; 1823 | 1824 | function UnicodeToCP1257(Unicode: cardinal): integer; 1825 | begin 1826 | case Unicode of 1827 | 0..127: Result:=Unicode; 1828 | 129: Result:=129; 1829 | 131: Result:=131; 1830 | 136: Result:=136; 1831 | 138: Result:=138; 1832 | 140: Result:=140; 1833 | 144: Result:=144; 1834 | 152: Result:=152; 1835 | 154: Result:=154; 1836 | 156: Result:=156; 1837 | 159..167: Result:=Unicode; 1838 | 168: Result:=141; 1839 | 169: Result:=169; 1840 | 171..174: Result:=Unicode; 1841 | 175: Result:=157; 1842 | 176..183: Result:=Unicode; 1843 | 184: Result:=143; 1844 | 185: Result:=185; 1845 | 187..190: Result:=Unicode; 1846 | 196..197: Result:=Unicode; 1847 | 198: Result:=175; 1848 | 201: Result:=201; 1849 | 211: Result:=211; 1850 | 213..215: Result:=Unicode; 1851 | 216: Result:=168; 1852 | 220: Result:=220; 1853 | 223: Result:=223; 1854 | 228..229: Result:=Unicode; 1855 | 230: Result:=191; 1856 | 233: Result:=233; 1857 | 243: Result:=243; 1858 | 245..247: Result:=Unicode; 1859 | 248: Result:=184; 1860 | 252: Result:=252; 1861 | 256: Result:=194; 1862 | 257: Result:=226; 1863 | 260: Result:=192; 1864 | 261: Result:=224; 1865 | 262: Result:=195; 1866 | 263: Result:=227; 1867 | 268: Result:=200; 1868 | 269: Result:=232; 1869 | 274: Result:=199; 1870 | 275: Result:=231; 1871 | 278: Result:=203; 1872 | 279: Result:=235; 1873 | 280: Result:=198; 1874 | 281: Result:=230; 1875 | 290: Result:=204; 1876 | 291: Result:=236; 1877 | 298: Result:=206; 1878 | 299: Result:=238; 1879 | 302: Result:=193; 1880 | 303: Result:=225; 1881 | 310: Result:=205; 1882 | 311: Result:=237; 1883 | 315: Result:=207; 1884 | 316: Result:=239; 1885 | 321: Result:=217; 1886 | 322: Result:=249; 1887 | 323: Result:=209; 1888 | 324: Result:=241; 1889 | 325: Result:=210; 1890 | 326: Result:=242; 1891 | 332: Result:=212; 1892 | 333: Result:=244; 1893 | 342: Result:=170; 1894 | 343: Result:=186; 1895 | 346: Result:=218; 1896 | 347: Result:=250; 1897 | 352: Result:=208; 1898 | 353: Result:=240; 1899 | 362: Result:=219; 1900 | 363: Result:=251; 1901 | 370: Result:=216; 1902 | 371: Result:=248; 1903 | 377: Result:=202; 1904 | 378: Result:=234; 1905 | 379: Result:=221; 1906 | 380: Result:=253; 1907 | 381: Result:=222; 1908 | 382: Result:=254; 1909 | 711: Result:=142; 1910 | 729: Result:=255; 1911 | 731: Result:=158; 1912 | 8211..8212: Result:=Unicode-8061; 1913 | 8216..8217: Result:=Unicode-8071; 1914 | 8218: Result:=130; 1915 | 8220..8221: Result:=Unicode-8073; 1916 | 8222: Result:=132; 1917 | 8224..8225: Result:=Unicode-8090; 1918 | 8226: Result:=149; 1919 | 8230: Result:=133; 1920 | 8240: Result:=137; 1921 | 8249: Result:=139; 1922 | 8250: Result:=155; 1923 | 8364: Result:=128; 1924 | 8482: Result:=153; 1925 | else Result:=-1; 1926 | end; 1927 | end; 1928 | 1929 | function UnicodeToCP1258(Unicode: cardinal): integer; 1930 | begin 1931 | case Unicode of 1932 | 0..127: Result:=Unicode; 1933 | 129: Result:=129; 1934 | 138: Result:=138; 1935 | 141..144: Result:=Unicode; 1936 | 154: Result:=154; 1937 | 157..158: Result:=Unicode; 1938 | 160..194: Result:=Unicode; 1939 | 196..203: Result:=Unicode; 1940 | 205..207: Result:=Unicode; 1941 | 209: Result:=209; 1942 | 211..212: Result:=Unicode; 1943 | 214..220: Result:=Unicode; 1944 | 223..226: Result:=Unicode; 1945 | 228..235: Result:=Unicode; 1946 | 237..239: Result:=Unicode; 1947 | 241: Result:=241; 1948 | 243..244: Result:=Unicode; 1949 | 246..252: Result:=Unicode; 1950 | 255: Result:=255; 1951 | 258: Result:=195; 1952 | 259: Result:=227; 1953 | 272: Result:=208; 1954 | 273: Result:=240; 1955 | 338: Result:=140; 1956 | 339: Result:=156; 1957 | 376: Result:=159; 1958 | 402: Result:=131; 1959 | 416: Result:=213; 1960 | 417: Result:=245; 1961 | 431: Result:=221; 1962 | 432: Result:=253; 1963 | 710: Result:=136; 1964 | 732: Result:=152; 1965 | 768: Result:=204; 1966 | 769: Result:=236; 1967 | 771: Result:=222; 1968 | 777: Result:=210; 1969 | 803: Result:=242; 1970 | 8211..8212: Result:=Unicode-8061; 1971 | 8216..8217: Result:=Unicode-8071; 1972 | 8218: Result:=130; 1973 | 8220..8221: Result:=Unicode-8073; 1974 | 8222: Result:=132; 1975 | 8224..8225: Result:=Unicode-8090; 1976 | 8226: Result:=149; 1977 | 8230: Result:=133; 1978 | 8240: Result:=137; 1979 | 8249: Result:=139; 1980 | 8250: Result:=155; 1981 | 8363: Result:=254; 1982 | 8364: Result:=128; 1983 | 8482: Result:=153; 1984 | else Result:=-1; 1985 | end; 1986 | end; 1987 | 1988 | function UnicodeToCP874(Unicode: cardinal): integer; 1989 | begin 1990 | case Unicode of 1991 | 0..127: Result:=Unicode; 1992 | 129..132: Result:=Unicode; 1993 | 134..144: Result:=Unicode; 1994 | 152..160: Result:=Unicode; 1995 | 219..222: Result:=Unicode; 1996 | 252..255: Result:=Unicode; 1997 | 3585..3642: Result:=Unicode-3424; 1998 | 3647..3675: Result:=Unicode-3424; 1999 | 8211..8212: Result:=Unicode-8061; 2000 | 8216..8217: Result:=Unicode-8071; 2001 | 8220..8221: Result:=Unicode-8073; 2002 | 8226: Result:=149; 2003 | 8230: Result:=133; 2004 | 8364: Result:=128; 2005 | else Result:=-1; 2006 | end; 2007 | end; 2008 | -------------------------------------------------------------------------------- /encconv/encconv_package.lpk: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <CONFIG> 3 | <Package Version="5"> 4 | <Name Value="encconv_package"/> 5 | <Author Value="Alexey Torgashin"/> 6 | <CompilerOptions> 7 | <Version Value="11"/> 8 | <SearchPaths> 9 | <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> 10 | </SearchPaths> 11 | </CompilerOptions> 12 | <Description Value="Library to convert encoding inside strings. Modified LConvEncoding to give simpler API."/> 13 | <License Value="MPL 2.0, LGPL"/> 14 | <Version Major="1" Minor="1"/> 15 | <Files Count="1"> 16 | <Item1> 17 | <Filename Value="encconv.pas"/> 18 | <UnitName Value="EncConv"/> 19 | </Item1> 20 | </Files> 21 | <CompatibilityMode Value="True"/> 22 | <RequiredPkgs Count="2"> 23 | <Item1> 24 | <PackageName Value="LazUtils"/> 25 | </Item1> 26 | <Item2> 27 | <PackageName Value="FCL"/> 28 | </Item2> 29 | </RequiredPkgs> 30 | <UsageOptions> 31 | <UnitPath Value="$(PkgOutDir)"/> 32 | </UsageOptions> 33 | <PublishOptions> 34 | <Version Value="2"/> 35 | <UseFileFilters Value="True"/> 36 | </PublishOptions> 37 | </Package> 38 | </CONFIG> 39 | -------------------------------------------------------------------------------- /encconv/encconv_package.pas: -------------------------------------------------------------------------------- 1 | { This file was automatically created by Lazarus. Do not edit! 2 | This source is only used to compile and install the package. 3 | } 4 | 5 | unit encconv_package; 6 | 7 | {$warn 5023 off : no warning about unused units} 8 | interface 9 | 10 | uses 11 | EncConv; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | EncConv is simplified code of LConvEncoding from Lazarus. 2 | it uses the same codepage tables. 3 | 4 | changes: 5 | - type of encoding ID is now enum 6 | - removed using of FPC string convertion API, removed using of Unix iconv; 7 | so unit must work the same way on all platforms and FPC versions 8 | - removed optional changing of CodePage for resulting string 9 | - renamed most of functions, except simple functions like UTF8ToNNN, NNNToUTF8 10 | - added EncConvErrorMode global var, which has 4 possible values 11 | (LConvEncoding global var had 2 values): 12 | raise exception, skip chars, replace chars with '?', return empty string 13 | - removed parameter Encoded of functions 14 | 15 | author: Alexey Torgashin 16 | license: same as for Lazarus 17 | -------------------------------------------------------------------------------- /testfiles/test-euc-jp.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexey-T/EncConv/8caaa6b9838b2587d1d0a007dbc4a728a1306a72/testfiles/test-euc-jp.txt -------------------------------------------------------------------------------- /testfiles/test-euc-tw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexey-T/EncConv/8caaa6b9838b2587d1d0a007dbc4a728a1306a72/testfiles/test-euc-tw.txt -------------------------------------------------------------------------------- /testfiles/test-gb18030.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexey-T/EncConv/8caaa6b9838b2587d1d0a007dbc4a728a1306a72/testfiles/test-gb18030.txt -------------------------------------------------------------------------------- /testfiles/test-gb2312-hz.txt: -------------------------------------------------------------------------------- 1 | ~{<rLeVPND~} gb2312-hz ~{1`Bk2bJT!#~} 2 | 3 | Simplified Chinese gb2312-hz encoding test. -------------------------------------------------------------------------------- /testfiles/test-iso2022.txt: -------------------------------------------------------------------------------- 1 | $)A<rLeVPND iso2022 1`Bk2bJT!# 2 | 3 | Simplified Chinese iso2022 encoding test. --------------------------------------------------------------------------------