test-client-godot/assets/Scripts/Tools/url_encoding.gd

52 lines
1.8 KiB
GDScript3
Raw Normal View History

2019-11-20 20:20:14 +00:00
# Class to encode string with escape web code
#
# Copyright (C) 2019 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class url_encoding:
2019-11-20 20:20:14 +00:00
func _init():
pass
func web_encode(value):
var ret = value
ret = ret.replace("%", "%25")
ret = ret.replace(" ", "%20")
ret = ret.replace("\"","%22")
ret = ret.replace("<", "%3C")
ret = ret.replace(">", "%3E")
ret = ret.replace("#", "%23")
ret = ret.replace("{", "%7B")
ret = ret.replace("}", "%7D")
ret = ret.replace("|", "%7C")
ret = ret.replace("\\","%5C")
ret = ret.replace("^", "%5E")
ret = ret.replace("~", "%7E")
ret = ret.replace("[", "%5B")
ret = ret.replace("]", "%5D")
ret = ret.replace("`", "%60")
ret = ret.replace("@", "%40")
ret = ret.replace("$", "%24")
ret = ret.replace("&", "%26")
ret = ret.replace("+", "%2B")
ret = ret.replace(",", "%2C")
ret = ret.replace("/", "%2F")
ret = ret.replace(":", "%3A")
ret = ret.replace(";", "%3B")
ret = ret.replace("=", "%3D")
ret = ret.replace("?", "%3F")
ret = ret.replace("'", "%27")
return ret