#!/bin/ash
#161213 sfs
#http://askubuntu.com/questions/53770/how-can-i-encode-and-decode-percent-encoded-strings-on-the-command-line
#http://unix.stackexchange.com/questions/159253/decoding-url-encoding-percent-encoding
echo "$@" |awk '
  function encodeURIComponent(str,   start, j) {
    for (i = 0; i <= 255; i++)
      charCodeAt[sprintf("%c", i)] = i
    while (i = substr(str, ++start, 1))
      if (i ~ /[[:alnum:]_.~-]/ || i ~ /[;\/?:@=#&]/)
        j = j i
      else
        j = j "%" sprintf("%02X", charCodeAt[i])
    return j
  }
  END {
    print  encodeURIComponent($0)
  }
'