FString UMyGameInstance::UrlEncode(const FString &UnencodedString)
{
FTCHARToUTF8 Converter(*UnencodedString); //url encoding must be encoded over each utf-8 byte
const UTF8CHAR* UTF8Data = (UTF8CHAR*)Converter.Get(); //converter uses ANSI instead of UTF8CHAR - not sure why - but other code seems to just do this cast. In this case it really doesn't matter
FString EncodedString = TEXT("");
TCHAR Buffer[2] = { 0, 0 };
for (int32 ByteIdx = 0, Length = Converter.Length(); ByteIdx < Length; ++ByteIdx)
{
UTF8CHAR ByteToEncode = UTF8Data[ByteIdx];
if (ByteToEncode != ' '&& IsAllowedChar(ByteToEncode))
{
Buffer[0] = ByteToEncode;
FString TmpString = Buffer;
EncodedString += TmpString;
}
else if (ByteToEncode == ' ')
{
EncodedString += "+";
}
else if (ByteToEncode != '\0')
{
EncodedString += TEXT("%");
EncodedString += FString::Printf(TEXT("%.2X"), ByteToEncode);
}
}
return EncodedString;
}
URL编码
最新推荐文章于 2025-03-13 11:29:18 发布