Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created August 24, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilleiguaran/3c6af5b808e6f9113505 to your computer and use it in GitHub Desktop.
Save guilleiguaran/3c6af5b808e6f9113505 to your computer and use it in GitHub Desktop.
def camelize(""),
do: ""
def camelize(<<?_, t :: binary>>),
do: camelize(t)
def camelize(<<h, t :: binary>>),
do: <<to_upper_char(h)>> <> do_camelize(t)
defp do_camelize(<<?_, ?_, t :: binary>>),
do: do_camelize(<< ?_, t :: binary >>)
defp do_camelize(<<?_, h, t :: binary>>) when h in ?a..?z,
do: <<to_upper_char(h)>> <> do_camelize(t)
defp do_camelize(<<?_>>),
do: <<>>
defp do_camelize(<<?/, t :: binary>>),
do: <<?.>> <> camelize(t)
defp do_camelize(<<h, t :: binary>>),
do: <<h>> <> do_camelize(t)
defp do_camelize(<<>>),
do: <<>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment