Created
April 19, 2011 01:00
-
-
Save mitechie/926619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:encodeURIComponent(instr) | |
let instr = iconv(a:instr, &enc, "utf-8") | |
let len = strlen(instr) | |
let i = 0 | |
let outstr = '' | |
while i < len | |
let ch = instr[i] | |
if ch =~# '[0-9A-Za-z-._~!''()*]' | |
let outstr = outstr . ch | |
elseif ch == ' ' | |
let outstr = outstr . '+' | |
else | |
let outstr = outstr . '%' . substitute('0' . s:nr2hex(char2nr(ch)), '^.*\(..\)$', '\1', '') | |
endif | |
let i = i + 1 | |
endwhile | |
return outstr | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment