Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.eclipse.xtext.ui.editor.model;
  
  
  import  org.eclipse.core.runtime.Assert;
  import  org.eclipse.jface.text.BadLocationException;
  import  org.eclipse.jface.text.IDocument;

Copied from org.eclipse.jdt.internal.ui.text.DocumentCharacterIterator.
 
 /*
  * @see org.eclipse.jdt.internal.ui.text.DocumentCharacterIterator
  */
 
 	private int fIndex = -1;
 	private final IDocument fDocument;
 	private final int fFirst;
 	private final int fLast;
 
 	private void invariant() {
 		Assert.isTrue( >= );
 		Assert.isTrue( <= );
 	}

Creates an iterator for the entire document.

Parameters:
document the document backing this iterator
Throws:
BadLocationException if the indices are out of bounds
 
 	public DocumentCharacterIterator(IDocument documentthrows BadLocationException {
 		this(document, 0);
 	}

Creates an iterator, starting at offset first.

Parameters:
document the document backing this iterator
first the first character to consider
Throws:
BadLocationException if the indices are out of bounds
 
 	public DocumentCharacterIterator(IDocument documentint firstthrows BadLocationException {
 		this(documentfirstdocument.getLength());
 	}

Creates an iterator for the document contents from first (inclusive) to last (exclusive).

Parameters:
document the document backing this iterator
first the first character to consider
last the last character index to consider
Throws:
BadLocationException if the indices are out of bounds
 
 	public DocumentCharacterIterator(IDocument documentint firstint lastthrows BadLocationException {
 		if (document == null)
 			throw new NullPointerException();
 		if (first < 0 || first > last)
 			throw new BadLocationException();
 		if (last > document.getLength()) {
 			throw new BadLocationException();
 		}
 		 = document;
 		 = first;
 		 = last;
 		 = first;
 	}
 
 	/*
 	 * @see java.text.CharacterIterator#first()
 	 */
 	public char first() {
 		return setIndex(getBeginIndex());
 	}
 
 	/*
 	 * @see java.text.CharacterIterator#last()
 	 */
 	public char last() {
 		if ( == )
 			return setIndex(getEndIndex());
 		else
 			return setIndex(getEndIndex() - 1);
 	}
 
	/*
	 * @see java.text.CharacterIterator#current()
	 */
	public char current() {
		if ( >=  &&  < )
			try {
				return .getChar();
catch (BadLocationException e) {
				// ignore
			}
		return ;
	}
	/*
	 * @see java.text.CharacterIterator#next()
	 */
	public char next() {
		return setIndex(Math.min( + 1, getEndIndex()));
	}
	/*
	 * @see java.text.CharacterIterator#previous()
	 */
	public char previous() {
		if ( > getBeginIndex()) {
			return setIndex( - 1);
else {
			return ;
		}
	}
	/*
	 * @see java.text.CharacterIterator#setIndex(int)
	 */
	public char setIndex(int position) {
		if (position >= getBeginIndex() && position <= getEndIndex())
			 = position;
		else
		return current();
	}
	/*
	 * @see java.text.CharacterIterator#getBeginIndex()
	 */
	public int getBeginIndex() {
		return ;
	}
	/*
	 * @see java.text.CharacterIterator#getEndIndex()
	 */
	public int getEndIndex() {
		return ;
	}
	/*
	 * @see java.text.CharacterIterator#getIndex()
	 */
	public int getIndex() {
		return ;
	}
	/*
	 * @see java.text.CharacterIterator#clone()
	 */
	public Object clone() {
		try {
			return super.clone();
			throw new InternalError();
		}
	}
	/*
	 * @see java.lang.CharSequence#length()
	 */
	public int length() {
		return getEndIndex() - getBeginIndex();
	}

Note that, if the document is modified concurrently, this method may return CharacterIterator.DONE if a BadLocationException was thrown when accessing the backing document.

Parameters:
index
Returns:
	public char charAt(int index) {
		if (index >= 0 && index < length())
			try {
				return .getChar(getBeginIndex() + index);
catch (BadLocationException e) {
				// ignore and return DONE
				return ;
			}
		else
	}
	/*
	 * @see java.lang.CharSequence#subSequence(int, int)
	 */
	public CharSequence subSequence(int startint end) {
		if (start < 0)
		if (end < start)
		if (end > length())
		try {
			return new DocumentCharacterIterator(getBeginIndex() + startgetBeginIndex() + end);
catch (BadLocationException ex) {
		}
	}
New to GrepCode? Check out our FAQ X