org.kefirsf.bb.util.ArrayCharSequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kefirbb Show documentation
Show all versions of kefirbb Show documentation
KefirBB is a Java-library for text processing. Initially it was developed for BB2HTML translation.
But flexible configuration allows to use it in different cases. For example for parsing Markdown, Textile,
and for HTML filtration.
The newest version!
package org.kefirsf.bb.util;
import java.util.Arrays;
/**
* The char sequence based on existing char array.
*/
public final class ArrayCharSequence implements CharSequence {
private final char[] text;
private final int offset;
private final int length;
public ArrayCharSequence(char[] text, int offset, int length) {
Exceptions.nullArgument("text", text);
Exceptions.negativeArgument("offset", offset);
Exceptions.negativeArgument("length", length);
if ((offset + length) > text.length) {
throw new ArrayIndexOutOfBoundsException("The breaks are wrong.");
}
this.text = text;
this.offset = offset;
this.length = length;
}
public int length() {
return length;
}
public char charAt(int index) {
return text[index + offset];
}
public CharSequence subSequence(int start, int end) {
return new ArrayCharSequence(text, start + offset, end - start);
}
@SuppressWarnings("NullableProblems")
@Override
public String toString() {
return String.valueOf(text, offset, length);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CharSequence)) return false;
CharSequence that = (CharSequence) o;
if(length != that.length()){
return false;
}
for(int i =0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy