mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-27 19:59:07 +00:00
Add some Str!
methods
This commit is contained in:
parent
4184c5d1f2
commit
e44ba71aa5
2 changed files with 32 additions and 4 deletions
|
@ -984,6 +984,34 @@ impl Context {
|
||||||
);
|
);
|
||||||
str_mut_mutable.register_builtin_erg_impl(PROC_UPDATE, t, Immutable, Public);
|
str_mut_mutable.register_builtin_erg_impl(PROC_UPDATE, t, Immutable, Public);
|
||||||
str_mut.register_trait(mono(MUT_STR), str_mut_mutable);
|
str_mut.register_trait(mono(MUT_STR), str_mut_mutable);
|
||||||
|
let t = pr_met(
|
||||||
|
ref_mut(mono(MUT_STR), None),
|
||||||
|
vec![kw("s", Str)],
|
||||||
|
None,
|
||||||
|
vec![],
|
||||||
|
NoneType,
|
||||||
|
);
|
||||||
|
str_mut.register_builtin_py_impl(PROC_PUSH, t, Immutable, Public, Some(FUNC_PUSH));
|
||||||
|
let t = pr0_met(ref_mut(mono(MUT_STR), None), Str);
|
||||||
|
str_mut.register_builtin_py_impl(PROC_POP, t, Immutable, Public, Some(FUNC_POP));
|
||||||
|
let t = pr0_met(ref_mut(mono(MUT_STR), None), NoneType);
|
||||||
|
str_mut.register_builtin_py_impl(PROC_CLEAR, t, Immutable, Public, Some(FUNC_CLEAR));
|
||||||
|
let t = pr_met(
|
||||||
|
ref_mut(mono(MUT_STR), None),
|
||||||
|
vec![kw("idx", Nat), kw("s", Str)],
|
||||||
|
None,
|
||||||
|
vec![],
|
||||||
|
NoneType,
|
||||||
|
);
|
||||||
|
str_mut.register_builtin_py_impl(PROC_INSERT, t, Immutable, Public, Some(FUNC_INSERT));
|
||||||
|
let t = pr_met(
|
||||||
|
ref_mut(mono(MUT_STR), None),
|
||||||
|
vec![kw("idx", Nat)],
|
||||||
|
None,
|
||||||
|
vec![],
|
||||||
|
Str,
|
||||||
|
);
|
||||||
|
str_mut.register_builtin_py_impl(PROC_REMOVE, t, Immutable, Public, Some(FUNC_REMOVE));
|
||||||
/* File! */
|
/* File! */
|
||||||
let mut file_mut = Self::builtin_mono_class(MUT_FILE, 2);
|
let mut file_mut = Self::builtin_mono_class(MUT_FILE, 2);
|
||||||
let mut file_mut_readable = Self::builtin_methods(Some(mono(MUT_READABLE)), 1);
|
let mut file_mut_readable = Self::builtin_methods(Some(mono(MUT_READABLE)), 1);
|
||||||
|
|
|
@ -52,11 +52,11 @@ class StrMut(): # Inherits Str
|
||||||
return last
|
return last
|
||||||
else:
|
else:
|
||||||
return Error("Can't pop from empty `Str!`")
|
return Error("Can't pop from empty `Str!`")
|
||||||
def push(self, c: str):
|
def push(self, s: str):
|
||||||
self.value += c
|
self.value += s
|
||||||
def remove(self, idx: int):
|
def remove(self, idx: int):
|
||||||
char = self.value[idx]
|
char = self.value[idx]
|
||||||
self.value = self.value[:idx] + self.value[idx+1:]
|
self.value = self.value[:idx] + self.value[idx+1:]
|
||||||
return char
|
return char
|
||||||
def insert(self, idx: int, c: str):
|
def insert(self, idx: int, s: str):
|
||||||
self.value = self.value[:idx] + c + self.value[idx:]
|
self.value = self.value[:idx] + s + self.value[idx:]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue