Method `[..]()
- Method
`[..]
mixed`[..](objectarg,mixedstart,intstart_type,mixedend,intend_type)
string`[..](stringarg,intstart,intstart_type,intend,intend_type)
array`[..](arrayarg,intstart,intstart_type,intend,intend_type)- Description
Extracts a subrange.
This is the function form of expressions with the
[..]operator.argis the thing from which the subrange is to be extracted.startis the lower bound of the subrange andendthe upper bound.start_typeandend_typespecifies how thestartandendindices, respectively, are to be interpreted. The types are either Pike.INDEX_FROM_BEG, Pike.INDEX_FROM_END or Pike.OPEN_BOUND. In the last case, the index value is insignificant.The relation between
[..]expressions and this function is therefore as follows:a[i..j] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_BEG) a[i..<j] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_END) a[i..] <=> `[..] (a, i, Pike.INDEX_FROM_BEG, 0, Pike.OPEN_BOUND) a[<i..j] <=> `[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_BEG) a[<i..<j] <=> `[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_END) a[<i..] <=> `[..] (a, i, Pike.INDEX_FROM_END, 0, Pike.OPEN_BOUND) a[..j] <=> `[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_BEG) a[..<j] <=> `[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_END) a[..] <=> `[..] (a, 0, Pike.OPEN_BOUND, 0, Pike.OPEN_BOUND)The subrange is specified as follows by the two bounds:
If the lower bound refers to an index before the lowest allowable (typically zero) then it's taken as an open bound which starts at the first index (without any error).
Correspondingly, if the upper bound refers to an index past the last allowable then it's taken as an open bound which ends at the last index (without any error).
If the lower bound is less than or equal to the upper bound, then the subrange is the inclusive range between them, i.e. from and including the element at the lower bound and up to and including the element at the upper bound.
If the lower bound is greater than the upper bound then the result is an empty subrange (without any error).
- Returns
The returned value depends on the type of
arg:argcan have any of the following types:stringA string with the characters in the range is returned.
arrayAn array with the elements in the range is returned.
objectIf the object implements lfun::`[..], that function is called with the four remaining arguments.
As a compatibility measure, if the object does not implement lfun::`[..] but lfun::`[] then the latter is called with the bounds transformed to normal from-the-beginning indices in array-like fashion:
`[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_BEG)Calls
a->`[] (i, j)`[..] (a, i, Pike.INDEX_FROM_BEG, j, Pike.INDEX_FROM_END)Calls
a->`[] (i, a->_sizeof()-1-j)`[..] (a, i, Pike.INDEX_FROM_BEG, 0, Pike.OPEN_BOUND)Calls
a->`[] (i, Int.NATIVE_MAX)`[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_BEG)Calls
a->`[] (a->_sizeof()-1-i, j)`[..] (a, i, Pike.INDEX_FROM_END, j, Pike.INDEX_FROM_END)Calls
a->`[] (a->_sizeof()-1-i, a->_sizeof()-1-j), except thata->_sizeof()is called only once.`[..] (a, i, Pike.INDEX_FROM_END, 0, Pike.OPEN_BOUND)Calls
a->`[] (a->_sizeof()-1-i, Int.NATIVE_MAX)`[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_BEG)Calls
a->`[] (0, j)`[..] (a, 0, Pike.OPEN_BOUND, j, Pike.INDEX_FROM_END)Calls
a->`[] (0, a->_sizeof()-1-j)`[..] (a, 0, Pike.OPEN_BOUND, 0, Pike.OPEN_BOUND)Calls
a->`[] (0, Int.NATIVE_MAX)
Note that Int.NATIVE_MAX might be replaced with an even larger integer in the future.
- See also