Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » IMP » LexStream
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
Previous Topic:Problems with LPG parser
Next Topic:LexStream
Goto Forum:
  


Current Time: Wed Oct 22 00:09:09 GMT 2014

Powered by FUDForum. Page generated in 0.01624 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software