Skip to content

Commit 40e4efd

Browse files
committed
feat: option to set encoding for ZkString
1 parent cdd7260 commit 40e4efd

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/zenkit/_native.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212

1313
class ZkString(c_char_p):
14+
_encoding = "windows-1252"
15+
16+
@classmethod
17+
def set_encoding(cls, encoding: str) -> None:
18+
cls._encoding = encoding
19+
1420
@property
1521
def value(self) -> str:
1622
value = super().value
@@ -19,7 +25,7 @@ def value(self) -> str:
1925
error = "Failed to load native string"
2026
raise ValueError(error)
2127

22-
return value.decode("windows-1252")
28+
return value.decode(self._encoding)
2329

2430

2531
class ZkPointer(c_void_p):
@@ -28,10 +34,13 @@ def value(self) -> c_void_p:
2834
return c_void_p(super().value)
2935

3036

31-
def load(load: str, src: PathOrFileLike, *args: Any) -> c_void_p:
37+
def load(load: str, src: PathOrFileLike, *args: Any, encoding: str = None) -> c_void_p:
3238
if src is None:
3339
return c_void_p(None)
3440

41+
if encoding is not None:
42+
ZkString.set_encoding(encoding)
43+
3544
rd: Read
3645
if isinstance(src, VfsNode):
3746
rd = src.open()

src/zenkit/daedalus_script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def __init__(self, **kwargs: Any) -> None:
253253
self._keepalive = kwargs.pop("_keepalive", DLL)
254254

255255
@staticmethod
256-
def load(path_or_file_like: PathOrFileLike) -> "DaedalusScript":
257-
handle = _native.load("ZkDaedalusScript_load", path_or_file_like)
256+
def load(path_or_file_like: PathOrFileLike, encoding: str = None) -> "DaedalusScript":
257+
handle = _native.load("ZkDaedalusScript_load", path_or_file_like, encoding=encoding)
258258
return DaedalusScript(_handle=handle, _delete=True)
259259

260260
@property

0 commit comments

Comments
 (0)