Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.17 KB | None | 0 0
  1. #include-once
  2.  
  3. ;===============================================================================
  4. ; _UnicodeURLEncode()
  5. ; Description: : Encodes an unicode string to be URL-friendly
  6. ; Parameter(s): : $UnicodeURL - The Unicode String to Encode
  7. ; Return Value(s): : The URL encoded string
  8. ; Author(s): : Dhilip89
  9. ; Note(s): : -
  10. ;
  11. ;===============================================================================
  12.  
  13. Func _UnicodeURLEncode($UnicodeURL)
  14.     $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
  15.     $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
  16.     $UnicodeBinaryLength = StringLen($UnicodeBinary2)
  17.     Local $EncodedString
  18.     For $i = 1 To $UnicodeBinaryLength Step 2
  19.         $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
  20.         If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
  21.             $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
  22.         Else
  23.             $EncodedString &= '%' & $UnicodeBinaryChar
  24.         EndIf
  25.     Next
  26.     Return $EncodedString
  27. EndFunc   ;==>_UnicodeURLEncode
  28.  
  29.  
  30.  
  31. ;===============================================================================
  32. ; _UnicodeURLDecode()
  33. ; Description: : Tranlates a URL-friendly string to a normal string
  34. ; Parameter(s): : $toDecode - The URL-friendly string to decode
  35. ; Return Value(s): : The URL decoded string
  36. ; Author(s): : nfwu, Dhilip89
  37. ; Note(s): : Modified from _URLDecode() that's only support non-unicode.
  38. ;
  39. ;===============================================================================
  40. Func _UnicodeURLDecode($toDecode)
  41.     Local $strChar = "", $iOne, $iTwo
  42.     Local $aryHex = StringSplit($toDecode, "")
  43.     For $i = 1 To $aryHex[0]
  44.         If $aryHex[$i] = "%" Then
  45.             $i = $i + 1
  46.             $iOne = $aryHex[$i]
  47.             $i = $i + 1
  48.             $iTwo = $aryHex[$i]
  49.             $strChar = $strChar & Chr(Dec($iOne & $iTwo))
  50.         Else
  51.             $strChar = $strChar & $aryHex[$i]
  52.         EndIf
  53.     Next
  54.     $Process = StringToBinary (StringReplace($strChar, "+", " "))
  55.     $DecodedString = BinaryToString ($Process, 4)
  56.     Return $DecodedString
  57. EndFunc   ;==>_UnicodeURLDecode
  58. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement