Skip to content

Commit 824d553

Browse files
committed
๐Ÿ—“ Apr 15, 2025 8:14:16โ€ฏPM
โœจ to/from italics
1 parent 2f7c539 commit 824d553

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

โ€Žchepy/chepy_pluginsโ€Ž

โ€Žchepy/modules/dataformat.pyโ€Ž

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,9 @@ def remove_nonprintable(self, replace_with: Union[str, bytes] = b"") -> DataForm
15921592
return self
15931593

15941594
@ChepyDecorators.call_stack
1595-
def swap_endianness(self, word_length: int = 4, pad_incomplete: bool=True) -> DataFormatT:
1595+
def swap_endianness(
1596+
self, word_length: int = 4, pad_incomplete: bool = True
1597+
) -> DataFormatT:
15961598
"""Swap endianness.
15971599
15981600
Args:
@@ -1614,7 +1616,7 @@ def swap_endianness(self, word_length: int = 4, pad_incomplete: bool=True) -> Da
16141616
swapped_data += struct.pack("B" * word_length, *swapped_word)
16151617

16161618
if not pad_incomplete:
1617-
swapped_data = swapped_data.replace(b'\x00', b'')
1619+
swapped_data = swapped_data.replace(b"\x00", b"")
16181620
self.state = swapped_data
16191621
return self
16201622

@@ -2389,3 +2391,31 @@ def parse_sqlite(self, query: str) -> DataFormatT:
23892391

23902392
self.state = hold
23912393
return self
2394+
2395+
@ChepyDecorators.call_stack
2396+
def to_italics(self) -> DataFormatT:
2397+
"""Convert string alphabets to italics
2398+
2399+
Returns:
2400+
Chepy: The Chepy object.
2401+
"""
2402+
text = self._convert_to_str()
2403+
normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2404+
italic = "๐˜ข๐˜ฃ๐˜ค๐˜ฅ๐˜ฆ๐˜ง๐˜จ๐˜ฉ๐˜ช๐˜ซ๐˜ฌ๐˜ญ๐˜ฎ๐˜ฏ๐˜ฐ๐˜ฑ๐˜ฒ๐˜ณ๐˜ด๐˜ต๐˜ถ๐˜ท๐˜ธ๐˜น๐˜บ๐˜ป๐˜ˆ๐˜‰๐˜Š๐˜‹๐˜Œ๐˜๐˜Ž๐˜๐˜๐˜‘๐˜’๐˜“๐˜”๐˜•๐˜–๐˜—๐˜˜๐˜™๐˜š๐˜›๐˜œ๐˜๐˜ž๐˜Ÿ๐˜ ๐˜ก"
2405+
translation_table = str.maketrans(normal, italic)
2406+
self.state = text.translate(translation_table)
2407+
return self
2408+
2409+
@ChepyDecorators.call_stack
2410+
def from_italics(self) -> DataFormatT:
2411+
"""Convert italic string alphabets to ascii
2412+
2413+
Returns:
2414+
Chepy: The Chepy object.
2415+
"""
2416+
text = self._convert_to_str()
2417+
normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2418+
italic = "๐˜ข๐˜ฃ๐˜ค๐˜ฅ๐˜ฆ๐˜ง๐˜จ๐˜ฉ๐˜ช๐˜ซ๐˜ฌ๐˜ญ๐˜ฎ๐˜ฏ๐˜ฐ๐˜ฑ๐˜ฒ๐˜ณ๐˜ด๐˜ต๐˜ถ๐˜ท๐˜ธ๐˜น๐˜บ๐˜ป๐˜ˆ๐˜‰๐˜Š๐˜‹๐˜Œ๐˜๐˜Ž๐˜๐˜๐˜‘๐˜’๐˜“๐˜”๐˜•๐˜–๐˜—๐˜˜๐˜™๐˜š๐˜›๐˜œ๐˜๐˜ž๐˜Ÿ๐˜ ๐˜ก"
2419+
translation_table = str.maketrans(italic, normal)
2420+
self.state = text.translate(translation_table)
2421+
return self

โ€Žchepy/modules/dataformat.pyiโ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,6 @@ class DataFormat(ChepyCore):
123123
def increment_bytes(self: DataFormatT, n: int) -> DataFormatT: ...
124124
def decrement_bytes(self: DataFormatT, n: int) -> DataFormatT: ...
125125
def parse_csv(self: DataFormatT) -> DataFormatT: ...
126-
def parse_sqlite(self, query: str) -> DataFormatT: ...
126+
def parse_sqlite(self: DataFormatT, query: str) -> DataFormatT: ...
127+
def to_italics(self: DataFormatT) -> DataFormatT: ...
128+
def from_italics(self: DataFormatT) -> DataFormatT: ...

โ€Žtests/test_dataformat.pyโ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,14 @@ def test_parse_sqlite():
841841
.o
842842
== b"bar"
843843
)
844+
845+
846+
def test_italics():
847+
assert (
848+
Chepy("hello 123 !@$@# world").to_italics().out_as_any
849+
== "๐˜ฉ๐˜ฆ๐˜ญ๐˜ญ๐˜ฐ 123 !@$@# ๐˜ธ๐˜ฐ๐˜ณ๐˜ญ๐˜ฅ"
850+
)
851+
assert (
852+
Chepy("๐˜ฉ๐˜ฆ๐˜ญ๐˜ญ๐˜ฐ 123 !@$@# ๐˜ธ๐˜ฐ๐˜ณ๐˜ญ๐˜ฅ").from_italics().out_as_any
853+
== "hello 123 !@$@# world"
854+
)

0 commit comments

Comments
ย (0)