aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/utils.py
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-20 06:22:16 +0000
committerGitHub <noreply@github.com>2022-06-20 06:22:16 +0000
commita1484f66290517b6c36f2e82c92613f23d2c4935 (patch)
treef0a590ef6deac0c23c932773354fc4f75903953a /codegen/lib/utils.py
parente2553bbaf2a550f4941b924e703a922345a1389f (diff)
parent405a00c0d1908a4b3fbd8e6684c77dfb178ac55d (diff)
downloadazalea-drasl-a1484f66290517b6c36f2e82c92613f23d2c4935.tar.xz
Merge branch 'main' into 1.19.1
Diffstat (limited to 'codegen/lib/utils.py')
-rw-r--r--codegen/lib/utils.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/codegen/lib/utils.py b/codegen/lib/utils.py
index c185c0e5..3887bb35 100644
--- a/codegen/lib/utils.py
+++ b/codegen/lib/utils.py
@@ -1,4 +1,5 @@
import re
+import os
# utilities that could be used for things other than codegen
@@ -10,8 +11,15 @@ def to_snake_case(name: str):
def to_camel_case(name: str):
s = re.sub('_([a-z])', lambda m: m.group(1).upper(), name)
- return s[0].upper() + s[1:]
+ s = upper_first_letter(s)
+ # if the first character is a number, we need to add an underscore
+ # maybe we could convert it to the number name (like 2 would become "two")?
+ if s[0].isdigit():
+ s = f'_{s}'
+ return s
+def upper_first_letter(name: str):
+ return name[0].upper() + name[1:]
def padded_hex(n: int):
return f'0x{n:02x}'
@@ -44,3 +52,7 @@ def group_packets(packets: list[PacketIdentifier]):
packet_groups[key] = []
packet_groups[key].append(packet.packet_id)
return packet_groups
+
+
+def get_dir_location(name: str):
+ return os.path.join(os.path.dirname(__file__), '..', name)