cl-interpret: [NOT FINAL] Add unicode-aware O(n) string indexing
This commit is contained in:
parent
53cf71608a
commit
3f5c5480ae
@ -90,12 +90,18 @@ pub mod convalue {
|
|||||||
let Self::Int(index) = index else {
|
let Self::Int(index) = index else {
|
||||||
Err(Error::TypeError)?
|
Err(Error::TypeError)?
|
||||||
};
|
};
|
||||||
let Self::Array(arr) = self else {
|
match self {
|
||||||
Err(Error::TypeError)?
|
ConValue::String(string) => string
|
||||||
};
|
.chars()
|
||||||
arr.get(*index as usize)
|
.nth(*index as _)
|
||||||
|
.map(ConValue::Char)
|
||||||
|
.ok_or(Error::OobIndex(*index as usize, string.chars().count())),
|
||||||
|
ConValue::Array(arr) => arr
|
||||||
|
.get(*index as usize)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(Error::OobIndex(*index as usize, arr.len()))
|
.ok_or(Error::OobIndex(*index as usize, arr.len())),
|
||||||
|
_ => Err(Error::TypeError),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cmp! {
|
cmp! {
|
||||||
lt: false, <;
|
lt: false, <;
|
||||||
|
Loading…
Reference in New Issue
Block a user