Skip to content

Instantly share code, notes, and snippets.

@soh335
Created April 6, 2010 10:32
Show Gist options
  • Save soh335/357447 to your computer and use it in GitHub Desktop.
Save soh335/357447 to your computer and use it in GitHub Desktop.
"reference from String::CamelCase
function! camelcase#wordsplit(str)
return split(a:str, '[_\s]\|[A-Z]\@<![A-Z]\@=\|[A-Z]\@<=[A-Z][a-z]\@=')
endfunction
function! camelcase#camelize(str)
return join(map(split(a:str, '[A-Za-z]\@<=_[A-Za-z]\@='), 'toupper(v:val[0]).v:val[1:]'), '')
endfunction
function! camelcase#decamelize(str)
return join(map(split(a:str, '[A-Z]\@<![A-Z]\@=\|[A-Z]\@<=[A-Z][a-z]\@='), 'tolower(v:val)'), '_')
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment