Working principle of Chinese transcoder

xiaoxiao2021-03-06  110

Recently, I have made Simplified and Traditional Transformation under Delphi, I found that Windows2000 comes with "Chinese transcoder" is very easy to use, not only can transpose (BIG5 -> GBK), but also convert traditional characters to Simple characters (such as : East -> East).

It is relatively simple to turn the internal code. Use MultibyTetowideCha to transfer Simplified / Traditional (GBK / BIG5) to Unicode, and then use WideChartomultibyte from Unicode to Traditional / Simplified (BIG5 / GBK).

EX:

Function BIG52GB (Abig5String: String): String;

{BIG5 TO GBK: BIG5 ==> Unicode ==> GBK}

VAR

MWSTRING: Array [0..1024] of widechar;

Cchwidechar: integer;

MlongBool: longbool;

Begin

Result: = Abig5String; // Assign space

MlongBool: = true;

// 1. First get the length of the need

Cchwidechar: = MultibyTetowideChar (950, 0, Pchar (Abig5String), Length (Abig5String), @mwstring, 0);

// SETLENGTH (Mwstring, CchwideChar 1);

//2.big5 to unicode

MultibyToWideChar (950, 0, Pchar (Abig5String), Length (Abig5String), @mwstring, cchwidechar;

//3.Unicode to GBK

Widechartomultibyte (936, 0, @mwstring, cchwidechar, pchar (result), length (result), '?', @Mlongbool)

END;

After the above steps, the BIG5 code can be converted to the GBK code, but the word in the traditional is because most of the GBK have corresponding (traditional glyphs), and thus, the above-mentioned traditional glyphs corresponding to the BIG5, such as the BIG5 code " The word "East" ($ 967c) is "East" ($ 1567), rather than the most common "East" ($ B6AB) in China.

In the Chinese transcoder, the last page provides options for turning shape, it can do it! Then we should also be available! After debugging, it turns out that it is called lcmapstringw!

In Windows.Pas, three such functions are defined:

Function LCMapString (Locale: LCID; DWMAPFLAGS: DWORD; LPSRCSTR: PCHAR; cchsrc: integer; lpdeststr: pchar; cchdest: integer: integer; stdcall;

Function LCMapStringa (Locale: LCID; DWMAPFLAGS: DWORD; LPSRCSTR: PANSICHAR; CCHSRC: Integer; lpdeststr: Pansichar; cchdest: integer: integer; stdcall;

Function LCMapStringw (LPSRCSTR: PWIDECHAR; CCHSRC: PWIDECHAR; CCHDESTSTR: PWIDECHAR; CCHDEST: Integer: Integer; stdcall;

转载请注明原文地址:https://www.9cbs.com/read-123486.html

New Post(0)