LexStream [message #566515] |
Thu, 20 September 2007 20:04 |
Eclipse User |
|
|
|
Originally posted by: olegm.gmail.com
Hello,
Class LexStream provides the following methods
-----------------------
class LexStream {
public int getLineOffset(int i) { return lineOffsets.get(i); }
public int getLineNumberOfCharAt(int i)
{
int index = lineOffsets.binarySearch(i);
return index < 0 ? -index : index == 0 ? 1 : index;
}
}
-----------------------
It seems that the former works with 0-based line indexes, while the
latter works with 1-based, or to put it another way:
getLineOffset(getLineNumberOfCharAt(0)) > 0
This is because of the way the binary search is defined:
-------------
public class IntSegmentedTuple
{
// If array is sorted, this function will find the index location
// of a given element if it is contained in the array. Otherwise, it
// will return the negation of the index of the element prior to
// which the new element would be inserted in the array.
//
public int binarySearch(int element) {
...
}
}
-------------
Is this behavior intentional?
Best,
OM
|
|
|
Powered by
FUDForum. Page generated in 0.01495 seconds