[Proposal] Macro.camelize support lower camel case

102 views
Skip to first unread message

최병욱

unread,
Apr 11, 2022, 11:05:56 AM4/11/22
to elixir-lang-core
Hi everyone,

Background
Macro.camelize/1 is convert string to upper camel case (pascal case).
How do I convert lower camel case (camel case with the first letter lowercase) 

Proposal
@spec camelize(String.t(), boolean()) :: String.t()
  def camelize(string, upper? \\ true)

Example
Macro.camelize("foo_bar")
> "FooBar"
Macro.camelize("foo_bar", false)
> "fooBar"
Macro.camelize("d_day", false)
> "dDay"

What is your opinion :)

Andrey Yugai

unread,
Apr 11, 2022, 11:28:14 AM4/11/22
to elixir-l...@googlegroups.com
Hey there, I think that would be a nice addition in general, but Macro.camelize/1 has a very specific purpose:
This function was designed to camelize language identifiers/tokens, that's why it belongs to the Macro module. Do not use it as a general mechanism for camelizing strings as it does not support Unicode or characters that are not valid in Elixir identifiers.
If you take look at the source code, you will see that camelization will work only on ASCII strings, and with "_" as delimiters, but it shouldn't too hard to write camelize/2 that suits your needs.



------- Original Message -------
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d476c06c-3c91-44ce-8c73-15f26e97eb07n%40googlegroups.com.

allen...@gmail.com

unread,
Jun 6, 2022, 12:14:42 AM6/6/22
to elixir-lang-core
Hi,

I'm using inflex for this. You can take a look at the package.

Reply all
Reply to author
Forward
0 new messages