Package org.commonmark.internal
Class StaggeredDelimiterProcessor
- java.lang.Object
-
- org.commonmark.internal.StaggeredDelimiterProcessor
-
- All Implemented Interfaces:
DelimiterProcessor
class StaggeredDelimiterProcessor extends java.lang.Object implements DelimiterProcessor
An implementation of DelimiterProcessor that dispatches all calls to two or more other DelimiterProcessors depending on the length of the delimiter run. All child DelimiterProcessors must have different minimum lengths. A given delimiter run is dispatched to the child with the largest acceptable minimum length. If no child is applicable, the one with the largest minimum length is chosen.
-
-
Field Summary
Fields Modifier and Type Field Description private char
delim
private int
minLength
private java.util.LinkedList<DelimiterProcessor>
processors
-
Constructor Summary
Constructors Constructor Description StaggeredDelimiterProcessor(char delim)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
add(DelimiterProcessor dp)
private DelimiterProcessor
findProcessor(int len)
char
getClosingCharacter()
int
getMinLength()
Minimum number of delimiter characters that are needed to activate this.char
getOpeningCharacter()
int
process(DelimiterRun openingRun, DelimiterRun closingRun)
Process the delimiter runs.
-
-
-
Field Detail
-
delim
private final char delim
-
minLength
private int minLength
-
processors
private java.util.LinkedList<DelimiterProcessor> processors
-
-
Method Detail
-
getOpeningCharacter
public char getOpeningCharacter()
- Specified by:
getOpeningCharacter
in interfaceDelimiterProcessor
- Returns:
- the character that marks the beginning of a delimited node, must not clash with any built-in special characters
-
getClosingCharacter
public char getClosingCharacter()
- Specified by:
getClosingCharacter
in interfaceDelimiterProcessor
- Returns:
- the character that marks the the ending of a delimited node, must not clash with any built-in special characters. Note that for a symmetric delimiter such as "*", this is the same as the opening.
-
getMinLength
public int getMinLength()
Description copied from interface:DelimiterProcessor
Minimum number of delimiter characters that are needed to activate this. Must be at least 1.- Specified by:
getMinLength
in interfaceDelimiterProcessor
-
add
void add(DelimiterProcessor dp)
-
findProcessor
private DelimiterProcessor findProcessor(int len)
-
process
public int process(DelimiterRun openingRun, DelimiterRun closingRun)
Description copied from interface:DelimiterProcessor
Process the delimiter runs.The processor can examine the runs and the nodes and decide if it wants to process or not. If not, it should not change any nodes and return 0. If yes, it should do the processing (wrapping nodes, etc) and then return how many delimiters were used.
Note that removal (unlinking) of the used delimiter
Text
nodes is done by the caller.- Specified by:
process
in interfaceDelimiterProcessor
- Parameters:
openingRun
- the opening delimiter runclosingRun
- the closing delimiter run- Returns:
- how many delimiters were used; must not be greater than length of either opener or closer
-
-