Skip to content

Instantly share code, notes, and snippets.

@mitechie
Created April 19, 2011 01:00
Show Gist options
  • Save mitechie/926619 to your computer and use it in GitHub Desktop.
Save mitechie/926619 to your computer and use it in GitHub Desktop.
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