|
盒子资源分类 |
|
|
|
|
uEncoding字符串UNICODE处理单元 |
|
关键字:TEncoding UTF8 UTF16 UTF32 BIG5 GB UNICODE |
来 自:原创 |
平 台:Win2k/XP/NT,Win2003 |
下载所需:0 火柴 |
深浅度:中级 |
完成时间:2009/1/30 |
发布者:senfore |
发布时间:2009/2/4 |
编辑器:D2007 |
语 种:简体中文 |
分 类:字符串 |
下载浏览:889/15595 |
|
|
|
|
{* |<PRE> ========== * 软件名称:FcpEditor * 单元名称:uEncoding * 单元作者:Senfore * 备 注:UNICODE读写支持 * 开发平台:Windows Xp Sp3 + Delphi 2007/Delphi2009 * 兼容测试: * 本 地 化:使Delphi2007能使用Delphi2009的Encoding方式处理文本 * 单元标识:$Id: uEncoding.pas,v 1.1 2009/01/28 * 修改记录: * 2009.01.28 V1.1 * 让Delphi2007环境下支持UTF32格式读写 * 2009.01.06 V1.0 * 创建单元,实现功能 ========== |</PRE>}
unit uEncoding;
{$DEFINE UCS4_ENCODING_SUPPORT}
interface
uses Classes,Windows,SysUtils;
{$IFNDEF UNICODE} function InterlockedCompareExchangePointer(var Destination: Pointer; Exchange: Pointer; Comperand: Pointer): Pointer; {$ENDIF}
{$IFNDEF UNICODE} type UnicodeString=WideString; RawByteString=AnsiString; {$ENDIF}
{$IFNDEF UNICODE} type TCharArray = array of Char;
EEncodingError = class(Exception);
TEncoding = class strict private class var FASCIIEncoding: TEncoding; FBigEndianUnicodeEncoding: TEncoding; FDefaultEncoding: TEncoding; FUnicodeEncoding: TEncoding; FUTF7Encoding: TEncoding; FUTF8Encoding: TEncoding; class function GetASCII: TEncoding; static; class function GetBigEndianUnicode: TEncoding; static; class function GetDefault: TEncoding; static; class function GetUnicode: TEncoding; static; class function GetUTF7: TEncoding; static; class function GetUTF8: TEncoding; static; strict protected FIsSingleByte: Boolean; FMaxCharSize: Integer; function GetByteCount(Chars: PChar; CharCount: Integer): Integer; overload; virtual; abstract; function GetBytes(Chars: PChar; CharCount: Integer; Bytes: PByte; ByteCount: Integer): Integer; overload; virtual; abstract; function GetCharCount(Bytes: PByte; ByteCount: Integer): Integer; overload; virtual; abstract; function GetChars(Bytes: PByte; ByteCount: Integer; Chars: PChar; CharCount: Integer): Integer; overload; virtual; abstract; public class function Convert(Source, Destination: TEncoding; Bytes: TBytes): TBytes; overload; class function Convert(Source, Destination: TEncoding; Bytes: TBytes; StartIndex, Count: Integer): TBytes; overload; class procedure FreeEncodings; class function IsStandardEncoding(AEncoding: TEncoding): Boolean; static; class function GetBufferEncoding(const Buffer: TBytes; var AEncoding: TEncoding): Integer; static; function GetByteCount(const Chars: TCharArray): Integer; overload; function GetByteCount(const Chars: TCharArray; CharIndex, CharCount: Integer): Integer; overload; function GetByteCount(const S: string): Integer; overload; function GetByteCount(const S: string; CharIndex, CharCount: Integer): Integer; overload; function GetBytes(const Chars: TCharArray): TBytes; overload; function GetBytes(const Chars: TCharArray; CharIndex, CharCount: Integer; var Bytes: TBytes; ByteIndex: Integer): Integer; overload; function GetBytes(const S: string): TBytes; overload; function GetBytes(const S: string; CharIndex, CharCount: Integer; var Bytes: TBytes; ByteIndex: Integer): Integer; overload; function GetCharCount(const Bytes: TBytes): Integer; overload; function GetCharCount(const Bytes: TBytes; ByteIndex, ByteCount: Integer): Integer; overload; function GetChars(const Bytes: TBytes): TCharArray; overload; function GetChars(const Bytes: TBytes; ByteIndex, ByteCount: Integer): TCharArray; overload; function GetChars(const Bytes: TBytes; ByteIndex, ByteCount: Integer; var Chars: TCharArray; CharIndex: Integer): Integer; overload; class function GetEncoding(CodePage: Integer): TEncoding; static; function GetMaxByteCount(CharCount: Integer): Integer; virtual; abstract; function GetMaxCharCount(ByteCount: Integer): Integer; virtual; abstract; function GetPreamble: TBytes; virtual; abstract; function GetString(const Bytes: TBytes): string; overload; function GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): string; overload; class property ASCII: TEncoding read GetASCII; class property BigEndianUnicode: TEncoding read GetBigEndianUnicode; class property Default: TEncoding read GetDefault; property IsSingleByte: Boolean read FIsSingleByte; class property Unicode: TEncoding read GetUnicode; class property UTF7: TEncoding read GetUTF7; class property UTF8: TEncoding read GetUTF8; end;
是一个进行UNICODE格式读写处理的单元,仿照Delphi2009的TEncoding类编写,可以进行UTF8、UTF16、UTF32或指定代码页对文本进行读写。 |
|
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们! |
相关文章 |
|
|
|
相关评论 |
|
|
|
|