1
{%MainUnit ../lconvencoding.pp}
3
{******************************************************************************
4
Asian Unicode Functions
5
******************************************************************************
7
*****************************************************************************
9
* This file is part of the Lazarus Component Library (LCL) *
11
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
12
* for details about the copyright. *
14
* This program is distributed in the hope that it will be useful, *
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18
*****************************************************************************
20
The clipboard is able to work with the windows and gtk behaviour/features.
23
function DBCSToUTF8(const s: string; CodeP: integer): string;
38
SetLength(Result, len * 4);// Asia UTF-8 is at most 4 bytes
40
Dest := PChar(Result);
46
if (c=#0) and (Src-PChar(s)>=len) then break;
52
code := Byte(c) shl 8;
54
if (c=#0) and (Src-PChar(s)>=len) then break;
55
code := code + Byte(c);
60
code := Uni936C[SearchTable(CP936CC, code)];
62
code := Uni950C[SearchTable(CP950CC, code)];
64
code := Uni949C[SearchTable(CP949CC, code)];
66
code := Uni932C[SearchTable(CP932CC, code)];
73
l:=UnicodeToUTF8Inline(code,Dest);
78
SetLength(Result, {%H-}PtrUInt(Dest) - PtrUInt(Result));
81
function CP936ToUTF8(const s: string): string;
83
Result := DBCSToUTF8(s, 936);
86
function CP950ToUTF8(const s: string): string;
88
Result := DBCSToUTF8(s, 950);
91
function CP949ToUTF8(const s: string): string;
93
Result := DBCSToUTF8(s, 949);
96
function CP932ToUTF8(const s: string): string;
98
Result := DBCSToUTF8(s, 932);
101
function UnicodeToCP936(Unicode: cardinal): integer;
104
0..127: Result := Unicode;
106
Result := CP936CU[SearchTable(Uni936U, Unicode)];
110
function UnicodeToCP950(Unicode: cardinal): integer;
113
0..127: Result := Unicode;
115
Result := CP950CU[SearchTable(Uni950U, Unicode)];
119
function UnicodeToCP949(Unicode: cardinal): integer;
122
0..127: Result := Unicode;
124
Result := CP949CU[SearchTable(Uni949U, Unicode)];
128
function UnicodeToCP932(Unicode: cardinal): integer;
131
0..127: Result := Unicode;
133
Result := CP932CU[SearchTable(Uni932U, Unicode)];
137
function UTF8ToDBCS(const s: string;
138
const UTF8CharConvFunc: TUnicodeToCharID): string;
154
SetLength(Result, len); // DBCS needs at most space as UTF-8
156
Dest := PChar(Result);
161
if (c=#0) and (Src-PChar(s)>=len) then break;
168
Unicode := UTF8CharacterToUnicode(Src, CharLen);
170
i := UTF8CharConvFunc(Unicode);
171
//writeln(Format('%X', [i]));
176
Dest^ := chr(i shr 8);
186
//SetLength(Result, Dest - PChar(Result));
187
SetLength(Result, {%H-}PtrUInt(Dest) - PtrUInt(Result));
190
function UTF8ToCP936(const s: string): string;
192
Result := UTF8ToDBCS(s, @UnicodeToCP936);
195
function UTF8ToCP950(const s: string): string;
197
Result := UTF8ToDBCS(s, @UnicodeToCP950);
200
function UTF8ToCP949(const s: string): string;
202
Result := UTF8ToDBCS(s, @UnicodeToCP949);
205
function UTF8ToCP932(const s: string): string;
207
Result := UTF8ToDBCS(s, @UnicodeToCP932);