Internal code conversion unit

Source: Internet
Author: User
Unit senfore;

Interface

Uses
Windows;

Function big52gb (big5str: string): ansistring;
Function gb2big5 (gbstr: string): ansistring;
Function gbcht2chs (gbstr: string): ansistring;
Function gbchs2cht (gbstr: string): ansistring;

Implementation

Function big52gb (big5str: string): ansistring;
{Convert big5 to GB internal code}
VaR
Len: integer;
Pbig5char: pchar;
Pgbchschar: pchar;
Pgbchtchar: pchar;
Punicodechar: pwidechar;
Begin
// String-> pchar
Pbig5char: = pchar (big5str );
Len: = multibytetowidechar (950,0, pbig5char,-1, nil, 0 );
Getmem (punicodechar, Len * 2 );
Zeromemory (punicodechar, Len * 2 );
// Big5-> Unicode
Multibytetowidechar (950,0, pbig5char,-1, punicodechar, Len );
Len: = widechartomultibyte (936,0, punicodechar,-1, nil, 0, nil, nil );
Getmem (pgbchtchar, Len * 2 );
Getmem (pgbchschar, Len * 2 );
Zeromemory (pgbchtchar, Len * 2 );
Zeromemory (pgbchschar, Len * 2 );
// Unicode-> GB CHT
Widechartomultibyte (936,0, punicodechar,-1, pgbchtchar, Len, nil, nil );
// Gb cht-> GB CHS
Lcmapstring ($804, lcmap_simplified_chinese, pgbchtchar,-1, pgbchschar, Len );
Result: = string (pgbchschar );
Freemem (pgbchtchar );
Freemem (pgbchschar );
Freemem (punicodechar );
End;

Function gb2big5 (gbstr: string): ansistring;
{Convert GB to big5 internal code}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Punicodechar: pwidechar;
Pbig5char: pchar;
Begin
Pgbchschar: = pchar (gbstr );
Len: = multibytetowidechar (936,0, pgbchschar,-1, nil, 0 );
Getmem (pgbchtchar, Len * 2 + 1 );
Zeromemory (pgbchtchar, Len * 2 + 1 );
// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_traditional_chinese, pgbchschar,-1, pgbchtchar, Len * 2 );
Getmem (punicodechar, Len * 2 );
Zeromemory (punicodechar, Len * 2 );
// Gb cht-> Unicode
Multibytetowidechar (936,0, pgbchtchar,-1, punicodechar, Len * 2 );
Len: = widechartomultibyte (950,0, punicodechar,-1, nil, 0, nil, nil );
Getmem (pbig5char, Len );
Zeromemory (pbig5char, Len );
// Unicode-> big5
Widechartomultibyte (950,0, punicodechar,-1, pbig5char, Len, nil, nil );
Result: = string (pbig5char );
Freemem (pbig5char );
Freemem (pgbchtchar );
Freemem (punicodechar );
End;

Function gbcht2chs (gbstr: string): ansistring;
{Convert GBK to simplified Chinese}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Begin
Pgbchtchar: = pchar (gbstr );
Len: = multibytetowidechar (936,0, pgbchtchar,-1, nil, 0 );
Getmem (pgbchschar, Len * 2 + 1 );
Zeromemory (pgbchschar, Len * 2 + 1 );
// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_simplified_chinese, pgbchtchar,-1, pgbchschar, Len * 2 );
Result: = string (pgbchschar );
// Freemem (pgbchtchar );
Freemem (pgbchschar );
End;

Function gbchs2cht (gbstr: string): ansistring;
{Convert GBK to traditional Chinese}
VaR
Len: integer;
Pgbchtchar: pchar;
Pgbchschar: pchar;
Begin
Pgbchschar: = pchar (gbstr );
Len: = multibytetowidechar (936,0, pgbchschar,-1, nil, 0 );
Getmem (pgbchtchar, Len * 2 + 1 );
Zeromemory (pgbchtchar, Len * 2 + 1 );
// Gb chs-> GB CHT
Lcmapstring ($804, lcmap_traditional_chinese, pgbchschar,-1, pgbchtchar, Len * 2 );
Result: = string (pgbchtchar );
Freemem (pgbchtchar );
// Freemem (pgbchschar );
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.