]> git.nbdom.net Git - nb.git/commitdiff
urlencode, urldecode
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 20 May 2016 08:33:03 +0000 (09:33 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 20 May 2016 08:33:03 +0000 (09:33 +0100)
etc/profile.d/functions
etc/vim/templates/perl.tt

index def095a287b0e07769cc7f3c9031bd177cba050f..b0e16f4f072bd7d32b5704e19e5e6f63cef87dab 100644 (file)
@@ -501,3 +501,19 @@ ssl_cert_create() {
   sudo openssl x509 -req -days 365 -in $name.csr -signkey $name.key -out $name.crt
   cat $name.crt $name.key > $name.pem
 }
+
+urlencode() {
+  local length="${#1}"
+  for (( i = 0; i < length; i++ )); do
+    local c="${1:i:1}"
+    case $c in
+      [a-zA-Z0-9.~_-]) printf "$c" ;;
+      *) printf '%%%02X' "'$c"
+    esac
+  done
+}
+
+urldecode() {
+  local url_encoded="${1//+/ }"
+  printf '%b\n' "${url_encoded//%/\\x}"
+}
index 0853638519bc6e042c4ce0ccea4812d7ef8c8f21..5715cd0fe4c49c7692b008292edaefd23b52bbd6 100755 (executable)
@@ -25,7 +25,9 @@ my ($NAME) = $0 =~ m,([^/]+)$,;
 my $VERBOSE = $main::VERBOSE = 1;
 my $DEBUG = $main::DEBUG = 0;
 
-my %Opt; get_options(\%Opt);
+my %Opt = (
+);
+get_options(\%Opt);
 help() unless @ARGV;
 $main::_DATA_ = undef;
 
@@ -63,7 +65,7 @@ sub help {
                return $v;
        }
 
-       $main::_DATA_ =~ s/([@\$][A-Z_]+)/pod_env($1)/eg;
+       $main::_DATA_ =~ s/([@\$][A-Z_a-z\{\}]+)/pod_env($1)/eg;
 
        # Create tmp
   my $in_file = (-e '/dev/shm' ? '/dev/shm' : '/tmp')."/$NAME.$$";
@@ -150,11 +152,11 @@ Quick usage:
 
 =head1 OPTIONS
 
- option[verbose|v+] Verbose mode: increase the verbosity level.
- option[debug+]     Debug mode: increase the verbosity level.
- option[version|V]  Print version (default: $VERSION)
- option[help|h|?]   Print a brief help message and exits.
- option[man]        Print the manual page and exits.
-option[verbose|v+] Verbose mode: increase the verbosity level.
-option[debug+]     Debug mode: increase the verbosity level.
-option[version|V]  Print version (default: $VERSION)
-option[help|h|?]   Print a brief help message and exits.
-option[man]        Print the manual page and exits.
 
 =cut