Created
August 31, 2013 11:55
-
-
Save jpluimers/6397795 to your computer and use it in GitHub Desktop.
NEXTGEN compatible GetShortStringString.
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 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