mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-25 12:11:39 +02:00
Switch to one-based indexing
This commit is contained in:
parent
4defe15611
commit
4d00974f2c
@ -593,7 +593,11 @@ fn eval_indexer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let index_value = eval_expr(context, &indexes[0], unit)?.to_f64() as usize;
|
let index_value = eval_expr(context, &indexes[0], unit)?.to_f64() as usize;
|
||||||
if let Some(value) = values.get(index_value) {
|
if index_value == 0 {
|
||||||
|
return Err(CalcError::ItemOfIndexDoesNotExist(vec![index_value]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(value) = values.get(index_value - 1) {
|
||||||
Ok(value.clone())
|
Ok(value.clone())
|
||||||
} else {
|
} else {
|
||||||
Err(CalcError::ItemOfIndexDoesNotExist(vec![index_value]))
|
Err(CalcError::ItemOfIndexDoesNotExist(vec![index_value]))
|
||||||
@ -606,8 +610,15 @@ fn eval_indexer(
|
|||||||
|
|
||||||
let row_index = eval_expr(context, &indexes[0], unit)?.to_f64() as usize;
|
let row_index = eval_expr(context, &indexes[0], unit)?.to_f64() as usize;
|
||||||
let column_index = eval_expr(context, &indexes[1], unit)?.to_f64() as usize;
|
let column_index = eval_expr(context, &indexes[1], unit)?.to_f64() as usize;
|
||||||
if let Some(row) = rows.get(row_index) {
|
if row_index == 0 || column_index == 0 {
|
||||||
if let Some(value) = row.get(column_index) {
|
return Err(CalcError::ItemOfIndexDoesNotExist(vec![
|
||||||
|
row_index,
|
||||||
|
column_index,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(row) = rows.get(row_index - 1) {
|
||||||
|
if let Some(value) = row.get(column_index - 1) {
|
||||||
return Ok(value.clone());
|
return Ok(value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user