diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-04 20:43:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-04 20:43:10 -0500 |
| commit | 23b7f20a0d88b54d430820baeb4a6da0316a009a (patch) | |
| tree | f3e780515b3bbb9973d2b94338be6194b5ec0af3 /codegen/lib/utils.py | |
| parent | 827d943c3f27c65724ff83689b40c87d1cd1838c (diff) | |
| download | azalea-drasl-23b7f20a0d88b54d430820baeb4a6da0316a009a.tar.xz | |
Default components (#232)
* add default components
* remove debug prints
* clippy
* use default components
* fix tests
Diffstat (limited to 'codegen/lib/utils.py')
| -rw-r--r-- | codegen/lib/utils.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/codegen/lib/utils.py b/codegen/lib/utils.py index fd1e553b..8d1e8756 100644 --- a/codegen/lib/utils.py +++ b/codegen/lib/utils.py @@ -5,18 +5,21 @@ import os def to_snake_case(name: str): - s = re.sub('([A-Z])', r'_\1', name) - return s.lower().strip('_') + s = re.sub("([A-Z])", r"_\1", name).replace(".", "_").replace("/", "_") + return s.lower().strip("_") def to_camel_case(name: str): - s = re.sub(r'[_ ](\w)', lambda m: m.group(1).upper(), - name.replace('.', '_').replace('/', '_')) + s = re.sub( + r"[_ ](\w)", + lambda m: m.group(1).upper(), + name.replace(".", "_").replace("/", "_"), + ) 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}' + s = f"_{s}" return s @@ -25,7 +28,7 @@ def upper_first_letter(name: str): def padded_hex(n: int): - return f'0x{n:02X}' + return f"0x{n:02X}" class PacketIdentifier: @@ -35,16 +38,20 @@ class PacketIdentifier: self.state = state def __eq__(self, other): - return self.packet_id == other.packet_id and self.direction == other.direction and self.state == other.state + return ( + self.packet_id == other.packet_id + and self.direction == other.direction + and self.state == other.state + ) def __hash__(self): return hash((self.packet_id, self.direction, self.state)) def __str__(self): - return f'{self.packet_id} {self.direction} {self.state}' + return f"{self.packet_id} {self.direction} {self.state}" def __repr__(self): - return f'PacketIdentifier({self.packet_id}, {self.direction}, {self.state})' + return f"PacketIdentifier({self.packet_id}, {self.direction}, {self.state})" def group_packets(packets: list[PacketIdentifier]): |
