#!/bin/sh

md5() {
  if [ -f "$1" ] ; then
    md5sum "$1" | awk '{print $1}'
  else
    echo -n "$1" | md5sum | awk '{print $1}'
  fi
}

upper() {
  [ -z "$1" ] && exit
  echo "$1" | tr '[a-z]' '[A-Z]'
}

encodeURIComponent() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for pos in `seq 0 $((strlen - 1))` ; do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               o=`printf '%%%02x' "'$c"`
     esac
     encoded="${encoded}${o}"
  done
  echo "${encoded}"
}
