Delphi7中Unicode,ANSI,UTF編碼問題


注解:
  ANSI     'American Standard Code for Information Interchange' 美國信息互換標准代碼 ANSI的'Ascii'編碼
  Unicode 'Universal Multiple-Octet Coded Character Set' 簡稱 UCS, 俗稱 'Unicode'
  UTF       'UCS Transfer Format'
  DBCS    'Double Byte Charecter Set' 雙字節字符集

相關重要函數過程:
WinAPI:
  MultiByteToWideChar WideCharToMultiByte
  相關參數(CodePage)

    CP_ACP ANSI code page
    CP_MACCP Not supported
    CP_OEMCP OEM code page
    CP_SYMBOL Not supported
    CP_THREAD_ACP Not supported
    CP_UTF7 UTF-7 code page
    CP_UTF8 UTF-8 code page

單元System.pas:
function StringToWideChar(const Source: string; Dest: PWideChar; DestSize: Integer): PWideChar;
function WideCharToString(Source: PWideChar): string;
function WideCharLenToString(Source: PWideChar; SourceLen: Integer): string;
procedure WideCharToStrVar(Source: PWideChar; var Dest: string);
procedure WideCharLenToStrVar(Source: PWideChar; SourceLen: Integer; var Dest: string);

type
  UCS2Char = WideChar; PUCS2Char = PWideChar;
  UCS4Char = type LongWord;
  UCS4String = array of UCS4Char;
function PUCS4Chars(const S: UCS4String): PUCS4Char;
function WideStringToUCS4String(const S: WideString): UCS4String;
function UCS4StringToWideString(const S: UCS4String): WideString;

function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: Integer): Integer; overload; deprecated;
function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: Integer): Integer; overload; deprecated;

function UnicodeToUtf8(Dest: PChar; MaxDestBytes: Cardinal; Source: PWideChar; SourceChars: Cardinal): Cardinal; overload;
function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: Cardinal; Source: PChar; SourceBytes: Cardinal): Cardinal; overload;
function UTF8Encode(const WS: WideString): UTF8String;
function UTF8Decode(const S: UTF8String): WideString;

function AnsiToUtf8(const S: string): UTF8String;
function Utf8ToAnsi(const S: UTF8String): string;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM