Last active
January 4, 2016 21:19
-
-
Save freeonterminate/8680239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ToCharCode(const iText: String; const iUTF8: Boolean): String; | |
var | |
M: TMarshaller; | |
function ToHexString(const iByte: TPtrWrapper): String; | |
var | |
Chars: PByteArray; | |
i: Integer; | |
SB: TStringBuilder; | |
begin | |
Result := ''; | |
Chars := iByte.ToPointer; | |
SB := TStringBuilder.Create; | |
try | |
i := 0; | |
while (Chars[i] <> 0) do begin | |
SB.Append(' '); | |
SB.Append(IntToHex(Chars[i], 2)); | |
Inc(i); | |
end; | |
Result := SB.ToString; | |
if (Result.StartsWith(' ')) then | |
Result := Result.Substring(1); | |
finally | |
SB.Free; | |
end; | |
end; | |
begin | |
if (iUTF8) then | |
Result := ToHexString(M.AsUtf8(iText)) | |
else | |
Result := ToHexString(M.AsAnsi(iText)); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment