function to decode HTML special characters

This commit is contained in:
Nathaniel Landau
2015-07-22 08:52:36 -04:00
parent 92e5eb47a5
commit f8f12cf8a7

View File

@@ -514,9 +514,16 @@ progressBar() {
tput cnorm tput cnorm
} }
# URL encoding/decoding from: https://gist.github.com/cdown/1163649 htmlDecode() {
# Decode HTML characters with sed
# Usage: htmlDecode <string>
echo "${1}" | sed -f "${SOURCEPATH}/htmlDecode.sed"
}
urlencode() { urlencode() {
# urlencode <string> # URL encoding/decoding from: https://gist.github.com/cdown/1163649
# Usage: urlencode <string>
local length="${#1}" local length="${#1}"
for (( i = 0; i < length; i++ )); do for (( i = 0; i < length; i++ )); do
@@ -529,7 +536,7 @@ urlencode() {
} }
urldecode() { urldecode() {
# urldecode <string> # Usage: urldecode <string>
local url_encoded="${1//+/ }" local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\x}" printf '%b' "${url_encoded//%/\x}"