python-telegram-bot/tests/auxil/string_manipulation.py
Aditya Yadav 03d2359061
API 7.0 (#4034, #4038)
Co-authored-by: poolitzer <github@poolitzer.eu>
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: aelkheir <arelkheir@gmail.com>
Co-authored-by: aelkheir <90580077+aelkheir@users.noreply.github.com>
2024-02-08 17:12:00 +01:00

15 lines
527 B
Python

import re
def to_camel_case(snake_str):
"""https://stackoverflow.com/a/19053800"""
components = snake_str.split("_")
# We capitalize the first letter of each component except the first one
# with the 'title' method and join them together.
return components[0] + "".join(x.title() for x in components[1:])
def to_snake_case(camel_str):
"""https://stackoverflow.com/a/1176023"""
name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", camel_str)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", name).lower()