slice method
Accesses a subset of this LogicValue from startIndex
to endIndex
,
both inclusive.
If endIndex
is less than startIndex
, the returned value will be
reversed relative to the original value.
LogicValue.ofString('xz01').slice(2, 1); // LogicValue.ofString('z0')
LogicValue.ofString('xz01').slice(-2, -3); // LogicValue.ofString('z0')
LogicValue.ofString('xz01').slice(1, 3); // LogicValue.ofString('0zx')
LogicValue.ofString('xz01').slice(-3, -1); // LogicValue.ofString('0zx')
LogicValue.ofString('xz01').slice(-2, -2); // LogicValue.ofString('z')
Implementation
LogicValue slice(int endIndex, int startIndex) {
final modifiedStartIndex = IndexUtilities.wrapIndex(startIndex, width);
final modifiedEndIndex = IndexUtilities.wrapIndex(endIndex, width);
if (modifiedStartIndex <= modifiedEndIndex) {
return getRange(modifiedStartIndex, modifiedEndIndex + 1);
} else {
return getRange(modifiedEndIndex, modifiedStartIndex + 1).reversed;
}
}