blob: 64a12dd0086d1551db98c65d3858a982312be542 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
"""
Utility methods. Should not be imported from outside of :module:`configlib`
"""
import re
from typing import List
def parse_case(any_case: str) -> List[str]:
"""
parses a multiword string from cases like PascalCase or snake_case
:param any_case: the multi-word string
:return: the words lowercased as an array
"""
if '_' in any_case:
return any_case.lower().split('_')
if '-' in any_case:
return any_case.lower().split('-')
return [word.lower() for word in re.sub('(?<=[a-z0-9])(?=[A-Z])', '\n', any_case).split('\n')]
def snake_case(any_case: str) -> str:
"""
parses a multiword string from cases like PascalCase or snake_case
:param any_case: the multi-word string
:return: the words in snake_case
"""
return '_'.join(parse_case(any_case))
def pascal_case(any_case: str) -> str:
"""
parses a multiword string from cases like PascalCase or snake_case
:param any_case: the multi-word string
:return: the words in PascalCase
"""
return ''.join(word.capitalize() for word in parse_case(any_case))
|