Commits

luastoned  committed c12f1de

Added url.unescape()

  • Participants
  • Parent commits 7c9db9e

Comments (0)

Files changed (1)

File facepunch/url.lua

 --			Gregor Steiner
 -------------------------------------------------------------------------------
 local string = string
+local tonumber = tonumber
 
 module( "facepunch.url" )
 
 function escape( s )
 	return string.gsub( s, "([^A-Za-z0-9_])", function( c )
 		return string.format( "%%%02x", string.byte( c ) )
-	end)
+	end )
 end
+
+-------------------------------------------------------------------------------
+-- url.unescape()
+-- Purpose: Decodes a string into its unescaped representation
+-- Input: s - binary string to be decoded
+-- Output: unescaped representation of string binary
+-------------------------------------------------------------------------------
+function unescape( s )
+    return string.gsub( s, "%%(%x%x)", function( hex )
+        return string.char( tonumber( hex, 16 ) )
+    end )
+end