[Delphi (Object Pascal)] Dephi 判断数据流是否包含unicode字符 →→→→→进入此内容的聊天室

来自 , 2021-04-02, 写在 Delphi (Object Pascal), 查看 166 次.
URL http://www.code666.cn/view/c96e6519
  1. function IsUnicodeStream(const Stm: Classes.TStream): Boolean;
  2. var
  3.   StmPos: LongInt;      // current position in stream
  4.   UnicodeMarker: Word;  // marker that indicates a unicode stream
  5. begin
  6.   // Record current location in stream
  7.   StmPos := Stm.Position;
  8.   // Check if stream large enough to contain unicode marker
  9.   if StmPos <= Stm.Size - SizeOf(Word) then
  10.   begin
  11.     // Read first word and check if it is the unicode marker
  12.     Stm.ReadBuffer(UnicodeMarker, SizeOf(UnicodeMarker));
  13.     Result := (UnicodeMarker = $FEFF);
  14.     // Restore stream positions
  15.     Stm.Position := StmPos;
  16.   end
  17.   else
  18.     // Stream too small: can't be unicode
  19.     Result := False;
  20. end;
  21. //delphi/2231

回复 "Dephi 判断数据流是否包含unicode字符"

这儿你可以回复上面这条便签

captcha