From eb080db15330d264fc5f8c22a6e3f4a6a0912116 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 20 May 2016 09:33:03 +0100 Subject: [PATCH] urlencode, urldecode --- etc/profile.d/functions | 16 ++++++++++++++++ etc/vim/templates/perl.tt | 16 +++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/etc/profile.d/functions b/etc/profile.d/functions index def095a2..b0e16f4f 100644 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -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}" +} diff --git a/etc/vim/templates/perl.tt b/etc/vim/templates/perl.tt index 08536385..5715cd0f 100755 --- a/etc/vim/templates/perl.tt +++ b/etc/vim/templates/perl.tt @@ -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 -- 2.47.3