Extension of CVCode Share Transfer: GBK and BIG5 Conversion

xiaoxiao2021-03-06  80

CVCode uses a code table control to achieve a simple transformation, and today there is still its practical meaning today. More common applications are, there are Taiwan employees in the enterprise, and there are mainland employees, and the Simplified and Traditional OS are used, so how to ensure GB2312, GBK and BIG5 in the MIS system can be used normally, and the data entered by BIG5 is The GBK system should be displayed properly and can match the characters entered in GB2312 (in the query, query is the most common). In response to this application, CVCode provides a code table control method. In theory, as long as it defines a code table, you can really let BIG5 and GB2312 "interoperability"

But in CVCode, just GB2312 and BIG5 conversion, today in the GBK input method, GB2312 is obviously not enough. And the BIG5 character set is much greater than GB2312, so extending CVCODE makes it a must-have GBK and BIG5 conversion function.

The character range of GBK is as follows:

GBK character set range

Partition high low position <

----------------------------------------------

● GBK / 1: GB2312 non-Chinese characters: A1 ~ A9 || A1 ~ Fe

● GBK / 2: GB2312 Chinese characters: B0 ~ F7 || A1 ~ Fe

● GBK / 3: Expansion Chinese characters: 81 ~ A0 || 40 ~ Fe

● GBK / 4: Expansion Chinese characters: aa ~ fe || 40 ~ A0

● GBK / 5: Expansion non-Chinese characters: A8 ~ A9 || 40 ~ A0

1 and 2 are corresponding GB2312 character sets.

How to let CVCode support GBK, 3 issues: 1. Judgment whether the GB code 2. Calculate the character sequence 3. Compatible with the original code table

The first question is to modify the ISGB as follows:

Function isgb (Value: string): boolean;

VAR

MHigh, Mlow: Integer;

Begin

IF (Length> = 2) THEN

Begin

MHigh: = ORD (Value [1]);

mlow: = ORD (Value [2]);

Result: = FALSE;

// ● GBK / 1: GB2312 non-Chinese characters: A1 ~ A9 || A1 ~ Fe

IF (MHigh in [$ A1 .. $ f])..

// ● GBK / 2: GB2312 Chinese characters: B0 ~ F7 || A1 ~ Fe

IF (Mhigh in [$ A1 .. $ Fe]) The Result: = true

// ● GBK / 3: Expansion Chinese characters: 81 ~ A0 || 40 ~ Fe

IF (MiGH IN [$ 81 .. $ f]).

// ● GBK / 4: Expand Chinese character: aa ~ fe || 40 ~ A0

IF (MHigh In [$ 40 .. $ a0]).

// ● GBK / 5: Expansion non-Chinese characters: A8 ~ A9 || 40 ~ A0

IF (MHigh in [$ A8 .. $ A9) and (Mlow IN [$ 40 .. $ a0]) THEN RESULT: = True;

end

Else

RESULT: = TRUE;

{// This is the original, only based on GB2312 as a basis

IF (Length> = 2) thenbegin

IF (Value [1] <= # 161) and (value [1]> = # 247) THEN

Result: = FALSE

Else

IF (Value [2] <= # 161) and (value [2]> = # 254) THEN

Result: = FALSE

Else

Result: = TRUE

end

Else

RESULT: = TRUE;

}

END;

The second compatibility is compatible with the original code table - actually compatible is mainly in the order:

Function GBOFFSET (Value: String): Integer;

VAR

MHigh, Mlow: Integer;

MGBK1, MGBK2, MGBK3, MGBK4, MGBK5: Integer

Begin

{// This is the original ---

if Length> = 2 THEN

Result: = (Value [1]) - $ A1) * $ 5e (ORD (Value [2]) - $ A1)

Else

RESULT: = -1;

}

RESULT: = -1;

if Length> = 2 THEN

Begin

MHigh: = ORD (Value [1]);

mlow: = ORD (Value [2]);

// How many Chinese characters have each zone?

// mgbk1: = ($ A9 - $ A1 1) * ($ Fe - $ A1 1); // = 846 = $ 34e

// MGBK2: = ($ F7 - $ B0 1) * ($ Fe - $ A1 1); // = 6768 = $ 1A70

// mgbk3: = ($ A0 - $ 81 1) * ($ Fe - $ 40 1);

// MGBK4: = ($ Fe - $ AA 1) * ($ A0 - $ 40 1);

// mgbk5: = ($ A9 - $ A8 1) * ($ A0 - $ 40 1);

MGBK1: = $ 34E; // 846

MGBK1: = MGBK1 ($ B0 - $ A9-1) * ($ FE - $ A1 1); // This is to compatible with the previous code table

MGBK2: = $ 1A70; // 6768

MGBK3: = $ 17E0; // 6112

MGBK4: = $ 2035; // 8245

MGBK5: = $ C2; // 194

// ● GBK / 1: GB2312 non-Chinese characters: A1 ~ A9 || A1 ~ Fe

IF (MHigh in [$ a1 .. $ a9]) and (mlow IN [$ a1 .. $ f]).

Result: = (MHigh - $ A1) * ($ Fe - $ A1 1) (MLOW - $ A1)

// ● GBK / 2: GB2312 Chinese characters: B0 ~ F7 || A1 ~ Fe

Else IF (MHigh in [$ A1 .. $ f])......................................................................................................................................................................................................................................................

Result: = mgbk1

(MHigh - $ b0) * ($ Fe - $ A1 1) (MLOW - $ A1)

// ● GBK / 3: Expansion Chinese characters: 81 ~ A0 || 40 ~ Fe

Else IF (MHigh in [$ 40 .. $ f]) THEN

Result: = MGBK1 MGBK2 (MHigh - $ 81) * ($ Fe - $ 40 1) (MLOW - $ 40)

// ● GBK / 4: Expand Chinese character: aa ~ fe || 40 ~ A0

Else IF (MHigh in [$ 40 .. $ a0]).

Result: = MgBK1 MGBK2 MGBK3

(MHigh - $ AA) * ($ A0 - $ 40 1) (MLOW - $ 40)

// ● GBK / 5: Expansion non-Chinese characters: A8 ~ A9 || 40 ~ A0

Else if ($ A8 .. $ A9]) And (Mlow IN [$ 40 .. $ a0]).

Result: = MgBK1 MGBK2 MGBK3 MGBK4

(MHigh - $ A8) * ($ A0 - $ 40 1) (MLOW - $ 40);

end

END;

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

New Post(0)