/**
* Copyright 2011 Oliver Buchtala
*
* This file is part of ndogen.
*
* ndogen is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ndogen is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ndogen. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ndogen.markdown;
import org.antlr.runtime.CharStream;
public class CharSequenceAdapter implements CharSequence {
CharStream stream;
int startIndex;
int length;
public CharSequenceAdapter(CharStream stream, int startIndex) {
super();
this.stream = stream;
this.startIndex = startIndex;
this.length = stream.size() - startIndex;
}
public CharSequenceAdapter(CharStream stream, int startIndex, int length) {
super();
this.stream = stream;
this.startIndex = startIndex;
this.length = stream.size() - startIndex;
}
@Override
public int length() {
return this.length;
}
@Override
public char charAt(int index) {
return (char) stream.LA(index);
}
@Override
public CharSequence subSequence(int start, int end) {
return new CharSequenceAdapter(stream, start, end-start);
}
}