mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
feat: support Array
, Str
, Bytes
slice
This commit is contained in:
parent
579615d76e
commit
0152e368ab
14 changed files with 170 additions and 19 deletions
|
@ -2,7 +2,6 @@ from _erg_result import Error
|
|||
from _erg_int import Int
|
||||
from _erg_control import then__
|
||||
|
||||
|
||||
class Str(str):
|
||||
def __instancecheck__(cls, obj):
|
||||
return isinstance(obj, str)
|
||||
|
@ -40,6 +39,15 @@ class Str(str):
|
|||
def __mod__(self, other):
|
||||
return then__(str.__mod__(other, self), Str)
|
||||
|
||||
def __getitem__(self, index_or_slice):
|
||||
from _erg_range import Range
|
||||
if isinstance(index_or_slice, slice):
|
||||
return Str(str.__getitem__(self, index_or_slice))
|
||||
elif isinstance(index_or_slice, Range):
|
||||
return Str(str.__getitem__(self, index_or_slice.into_slice()))
|
||||
else:
|
||||
return str.__getitem__(self, index_or_slice)
|
||||
|
||||
|
||||
class StrMut: # Inherits Str
|
||||
value: Str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue