Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created August 31, 2013 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/6397795 to your computer and use it in GitHub Desktop.
Save jpluimers/6397795 to your computer and use it in GitHub Desktop.
NEXTGEN compatible GetShortStringString.
function GetShortStringString(const ShortStringPointer: PByte): string;
var
ShortStringLength: Byte;
FirstShortStringCharacter: MarshaledAString;
ConvertedLength: Cardinal;
UnicodeCharacters: array[Byte] of Char; // cannot be more than 255 characters, reserve 1 character for terminating null
begin
if not Assigned(ShortStringPointer) then
Result := ''
else
begin
ShortStringLength := ShortStringPointer^;
if ShortStringLength = 0 then
Result := ''
else
begin
FirstShortStringCharacter := MarshaledAString(ShortStringPointer+1);
ConvertedLength := UTF8ToUnicode(
UnicodeCharacters,
Length(UnicodeCharacters),
FirstShortStringCharacter,
ShortStringLength
);
// UTF8ToUnicode will always include the null terminator character in the Result:
ConvertedLength := ConvertedLength-1;
SetString(Result, UnicodeCharacters, ConvertedLength);
end;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment