org.pkl.thirdparty.commonmark.internal.Delimiter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkl-tools Show documentation
Show all versions of pkl-tools Show documentation
Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.
package org.pkl.thirdparty.commonmark.internal;
import org.pkl.thirdparty.commonmark.node.Text;
import org.pkl.thirdparty.commonmark.parser.delimiter.DelimiterRun;
import java.util.List;
/**
* Delimiter (emphasis, strong emphasis or custom emphasis).
*/
public class Delimiter implements DelimiterRun {
public final List characters;
public final char delimiterChar;
private final int originalLength;
// Can open emphasis, see spec.
private final boolean canOpen;
// Can close emphasis, see spec.
private final boolean canClose;
public Delimiter previous;
public Delimiter next;
public Delimiter(List characters, char delimiterChar, boolean canOpen, boolean canClose, Delimiter previous) {
this.characters = characters;
this.delimiterChar = delimiterChar;
this.canOpen = canOpen;
this.canClose = canClose;
this.previous = previous;
this.originalLength = characters.size();
}
@Override
public boolean canOpen() {
return canOpen;
}
@Override
public boolean canClose() {
return canClose;
}
@Override
public int length() {
return characters.size();
}
@Override
public int originalLength() {
return originalLength;
}
@Override
public Text getOpener() {
return characters.get(characters.size() - 1);
}
@Override
public Text getCloser() {
return characters.get(0);
}
@Override
public Iterable getOpeners(int length) {
if (!(length >= 1 && length <= length())) {
throw new IllegalArgumentException("length must be between 1 and " + length() + ", was " + length);
}
return characters.subList(characters.size() - length, characters.size());
}
@Override
public Iterable getClosers(int length) {
if (!(length >= 1 && length <= length())) {
throw new IllegalArgumentException("length must be between 1 and " + length() + ", was " + length);
}
return characters.subList(0, length);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy