String Collection¶
[1]:
from rich.console import Console
from rich.table import Table
from byteclasses.print import byteclass_info, byteclass_inspect
from byteclasses.types.collections import String
[2]:
string = String(32, value="my string collection")
byteclass_info(string)
byteclass_inspect(string)
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ String │ │ is_byteclass() │ True │ │ is_collection_instance() │ True │ │ is_primitive_instance() │ False │ │ mro │ String -> ByteArray -> object │ │ len() │ 32 │ │ str() │ my string collection │ │ repr() │ String(32, value='my string collection') │ │ .data │ b'my string collection\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' │ └──────────────────────────┴─────────────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ──────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ----------------------------------------------------- │ │ 0x0 |6d|79|20|73|74|72|69|6e|67|20|63|6f|6c|6c|65|63 │ │ 0x10 |74|69|6f|6e|00|00|00|00|00|00|00|00|00|00|00|00 │ │ 0x20 │ ╰───────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━┳━━━━━━━┓ ┃ Member ┃ Value ┃ ┡━━━━━━━━╇━━━━━━━┩ │ 0 │ m │ │ 1 │ y │ │ 2 │ │ │ 3 │ s │ │ 4 │ t │ │ 5 │ r │ │ 6 │ i │ │ 7 │ n │ │ 8 │ g │ │ 9 │ │ │ 10 │ c │ │ 11 │ o │ │ 12 │ l │ │ 13 │ l │ │ 14 │ e │ │ 15 │ c │ │ 16 │ t │ │ 17 │ i │ │ 18 │ o │ │ 19 │ n │ │ 20 │ │ │ 21 │ │ │ 22 │ │ │ 23 │ │ │ 24 │ │ │ 25 │ │ │ 26 │ │ │ 27 │ │ │ 28 │ │ │ 29 │ │ │ 30 │ │ │ 31 │ │ └────────┴───────┘
[3]:
table = Table(title="Generic String Collection")
table.add_column("Name")
table.add_column("Value")
table.add_row("string[:]", str(string[:]))
table.add_row("string[::2]", str(string[::2]))
table.add_row("string[0]", str(string[0]))
table.add_row("string[0].value", str(string[0].value))
table.add_row("string[0].data", str(string[0].data))
console = Console()
console.print(table)
Generic String Collection ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Name ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ string[:] │ (UChar('m'), UChar('y'), UChar(' '), UChar('s'), UChar('t'), UChar('r'), UChar('i'), │ │ │ UChar('n'), UChar('g'), UChar(' '), UChar('c'), UChar('o'), UChar('l'), UChar('l'), │ │ │ UChar('e'), UChar('c'), UChar('t'), UChar('i'), UChar('o'), UChar('n'), UChar('\x00'), │ │ │ UChar('\x00'), UChar('\x00'), UChar('\x00'), UChar('\x00'), UChar('\x00'), UChar('\x00'), │ │ │ UChar('\x00'), UChar('\x00'), UChar('\x00'), UChar('\x00'), UChar('\x00')) │ │ string[::2] │ (UChar('m'), UChar(' '), UChar('t'), UChar('i'), UChar('g'), UChar('c'), UChar('l'), │ │ │ UChar('e'), UChar('t'), UChar('o'), UChar('\x00'), UChar('\x00'), UChar('\x00'), │ │ │ UChar('\x00'), UChar('\x00'), UChar('\x00')) │ │ string[0] │ m │ │ string[0].value │ m │ │ string[0].data │ b'm' │ └─────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────┘