URL编码

来源:互联网 发布:java aspectj 异常 编辑:程序博客网 时间:2024/06/09 14:54
FString UMyGameInstance::UrlEncode(const FString &UnencodedString){FTCHARToUTF8 Converter(*UnencodedString);//url encoding must be encoded over each utf-8 byteconst 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 matterFString 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;}

原创粉丝点击