mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 20:34:44 +00:00
Add inc!
, dec!
to Int
This commit is contained in:
parent
6cb3231845
commit
b0fe1103f3
13 changed files with 303 additions and 29 deletions
|
@ -13,27 +13,47 @@ class Str(str):
|
|||
return Str(self[i])
|
||||
else:
|
||||
return None
|
||||
def mutate(self):
|
||||
return StrMut(self)
|
||||
|
||||
class StrMut(Str):
|
||||
class StrMut(): # Inherits Str
|
||||
value: Str
|
||||
|
||||
def __init__(self, s: str):
|
||||
self.value = s
|
||||
def __repr__(self):
|
||||
return self.value.__repr__()
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Str):
|
||||
return self.value == other
|
||||
else:
|
||||
return self.value == other.value
|
||||
def __ne__(self, other):
|
||||
if isinstance(other, Str):
|
||||
return self.value != other
|
||||
else:
|
||||
return self.value != other.value
|
||||
def try_new(s: str):
|
||||
if isinstance(s, str):
|
||||
return StrMut(s)
|
||||
self = StrMut()
|
||||
self.value = s
|
||||
return self
|
||||
else:
|
||||
return Error("Str! can't be other than str")
|
||||
def clear(self):
|
||||
self = ""
|
||||
self.value = ""
|
||||
def pop(self):
|
||||
if len(self) > 0:
|
||||
last = self[-1]
|
||||
self = self[:-1]
|
||||
if len(self.value) > 0:
|
||||
last = self.value[-1]
|
||||
self.value = self.value[:-1]
|
||||
return last
|
||||
else:
|
||||
return Error("Can't pop from empty `Str!`")
|
||||
def push(self, c: str):
|
||||
self += c
|
||||
self.value += c
|
||||
def remove(self, idx: int):
|
||||
char = self[idx]
|
||||
self = self[:idx] + self[idx+1:]
|
||||
char = self.value[idx]
|
||||
self.value = self.value[:idx] + self.value[idx+1:]
|
||||
return char
|
||||
def insert(self, idx: int, c: str):
|
||||
self = self[:idx] + c + self[idx:]
|
||||
self.value = self.value[:idx] + c + self.value[idx:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue