core :: Text :: to_snake_case
self
and converts it to snake caseassert "randomMethodId".to_snake_case == "random_method_id"
The rules are the following:
An uppercase is always converted to a lowercase
assert "HELLO_WORLD".to_snake_case == "hello_world"
An uppercase that follows a lowercase is prefixed with an underscore
assert "HelloTheWORLD".to_snake_case == "hello_the_world"
An uppercase that follows an uppercase and is followed by a lowercase, is prefixed with an underscore
assert "HelloTHEWorld".to_snake_case == "hello_the_world"
All other characters are kept as is; self
does not need to be a proper CamelCased string.
assert "=-_H3ll0Th3W0rld_-=".to_snake_case == "=-_h3ll0th3w0rld_-="
# Takes a camel case `self` and converts it to snake case
#
# ~~~
# assert "randomMethodId".to_snake_case == "random_method_id"
# ~~~
#
# The rules are the following:
#
# An uppercase is always converted to a lowercase
#
# ~~~
# assert "HELLO_WORLD".to_snake_case == "hello_world"
# ~~~
#
# An uppercase that follows a lowercase is prefixed with an underscore
#
# ~~~
# assert "HelloTheWORLD".to_snake_case == "hello_the_world"
# ~~~
#
# An uppercase that follows an uppercase and is followed by a lowercase, is prefixed with an underscore
#
# ~~~
# assert "HelloTHEWorld".to_snake_case == "hello_the_world"
# ~~~
#
# All other characters are kept as is; `self` does not need to be a proper CamelCased string.
#
# ~~~
# assert "=-_H3ll0Th3W0rld_-=".to_snake_case == "=-_h3ll0th3w0rld_-="
# ~~~
fun to_snake_case: SELFTYPE is abstract
lib/core/text/abstract_text.nit:1318,2--1349,40
redef fun to_snake_case do
var ret = clone
ret.snake_case
return ret
end
lib/core/text/abstract_text.nit:1789,2--1793,4