Permalink
Browse files

HexStrToBytes의 파라미터가 EmptyStr일 경우 Dest Array가 []를 리턴하도록 변경

  • Loading branch information...
1 parent c1c46c3 commit 0fe8761a3ca9d76cee82896fbe11cce0ea4f384c @gomsun2 committed Feb 24, 2014
Showing with 17 additions and 10 deletions.
  1. +17 −10 source/utils/mSysUtilsEx.pas
View
27 source/utils/mSysUtilsEx.pas
@@ -49,20 +49,27 @@ function BytesToHexStr(const AValue: TBytes; const StrIdx, ALength: Integer): St
end;
procedure HexStrToBytes(const Source: String; var Dest: TBytes);
+const
+ SOURCE_LEN_MIN = 2;
var
i, LIdxOfDest, LBytesLen: Integer;
begin
- LBytesLen := Length(Source) div 2;
- SetLength(Dest, LBytesLen);
-
- LIdxOfDest := 0;
- for i := 0 to Length(Source) - 1 do
+ if Source.Length < SOURCE_LEN_MIN then
+ SetLength(Dest, 0)
+ else
begin
- if i mod 2 = 0 then
- Continue;
-
- Dest[LIdxOfDest] := Byte(Char(StrToInt('$' + Source[i] + Source[i+1])));
- Inc(LIdxOfDest);
+ LBytesLen := Source.Length div 2;
+ SetLength(Dest, LBytesLen);
+
+ LIdxOfDest := 0;
+ for i := 0 to Source.Length - 1 do
+ begin
+ if i mod 2 = 0 then
+ Continue;
+
+ Dest[LIdxOfDest] := Byte(Char(StrToInt('$' + Source[i] + Source[i+1])));
+ Inc(LIdxOfDest);
+ end;
end;
end;

0 comments on commit 0fe8761

Please sign in to comment.