本文整理匯總了Java中org.commonmark.parser.delimiter.DelimiterProcessor類的典型用法代碼示例。如果您正苦於以下問題:Java DelimiterProcessor類的具體用法?Java DelimiterProcessor怎麽用?Java DelimiterProcessor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DelimiterProcessor類屬於org.commonmark.parser.delimiter包,在下文中一共展示了DelimiterProcessor類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: add
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
void add(DelimiterProcessor dp) {
final int len = dp.getMinLength();
ListIterator<DelimiterProcessor> it = processors.listIterator();
boolean added = false;
while (it.hasNext()) {
DelimiterProcessor p = it.next();
int pLen = p.getMinLength();
if (len > pLen) {
it.previous();
it.add(dp);
added = true;
break;
} else if (len == pLen) {
throw new IllegalArgumentException("Cannot add two delimiter processors for char '" + delim + "' and minimum length " + len);
}
}
if (!added) {
processors.add(dp);
this.minLength = len;
}
}
示例2: addDelimiterProcessors
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
private static void addDelimiterProcessors(Iterable<DelimiterProcessor> delimiterProcessors, Map<Character, DelimiterProcessor> map) {
for (DelimiterProcessor delimiterProcessor : delimiterProcessors) {
char opening = delimiterProcessor.getOpeningCharacter();
char closing = delimiterProcessor.getClosingCharacter();
if (opening == closing) {
DelimiterProcessor old = map.get(opening);
if (old != null && old.getOpeningCharacter() == old.getClosingCharacter()) {
StaggeredDelimiterProcessor s;
if (old instanceof StaggeredDelimiterProcessor) {
s = (StaggeredDelimiterProcessor) old;
} else {
s = new StaggeredDelimiterProcessor(opening);
s.add(old);
}
s.add(delimiterProcessor);
map.put(opening, s);
} else {
addDelimiterProcessorForChar(opening, delimiterProcessor, map);
}
} else {
addDelimiterProcessorForChar(opening, delimiterProcessor, map);
addDelimiterProcessorForChar(closing, delimiterProcessor, map);
}
}
}
示例3: parseDelimiters
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
/**
* Attempt to parse delimiters like emphasis, strong emphasis or custom delimiters.
*/
private boolean parseDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) {
DelimiterData res = scanDelimiters(delimiterProcessor, delimiterChar);
if (res == null) {
return false;
}
int length = res.count;
int startIndex = index;
index += length;
Text node = appendText(input, startIndex, index);
// Add entry to stack for this opener
lastDelimiter = new Delimiter(node, delimiterChar, res.canOpen, res.canClose, lastDelimiter);
lastDelimiter.length = length;
lastDelimiter.originalLength = length;
if (lastDelimiter.previous != null) {
lastDelimiter.previous.next = lastDelimiter;
}
return true;
}
示例4: findProcessor
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
private DelimiterProcessor findProcessor(int len) {
for (DelimiterProcessor p : processors) {
if (p.getMinLength() <= len) {
return p;
}
}
return processors.getFirst();
}
示例5: CustomInlineParserContext
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
CustomInlineParserContext(List<DelimiterProcessor> delimiterProcessors) {
this.delimiterProcessors = delimiterProcessors;
}
示例6: getCustomDelimiterProcessors
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
@Override
public List<DelimiterProcessor> getCustomDelimiterProcessors() {
return delimiterProcessors;
}
示例7: InlineParserImpl
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
public InlineParserImpl(List<DelimiterProcessor> delimiterProcessors) {
this.delimiterProcessors = calculateDelimiterProcessors(delimiterProcessors);
this.delimiterCharacters = calculateDelimiterCharacters(this.delimiterProcessors.keySet());
this.specialCharacters = calculateSpecialCharacters(delimiterCharacters);
}
示例8: calculateDelimiterProcessors
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
public static Map<Character, DelimiterProcessor> calculateDelimiterProcessors(List<DelimiterProcessor> delimiterProcessors) {
Map<Character, DelimiterProcessor> map = new HashMap<>();
addDelimiterProcessors(Arrays.<DelimiterProcessor>asList(new AsteriskDelimiterProcessor(), new UnderscoreDelimiterProcessor()), map);
addDelimiterProcessors(delimiterProcessors, map);
return map;
}
示例9: addDelimiterProcessorForChar
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
private static void addDelimiterProcessorForChar(char delimiterChar, DelimiterProcessor toAdd, Map<Character, DelimiterProcessor> delimiterProcessors) {
DelimiterProcessor existing = delimiterProcessors.put(delimiterChar, toAdd);
if (existing != null) {
throw new IllegalArgumentException("Delimiter processor conflict with delimiter char '" + delimiterChar + "'");
}
}
示例10: parseInline
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
/**
* Parse the next inline element in subject, advancing input index.
* On success, add the result to block's children and return true.
* On failure, return false.
*/
private boolean parseInline() {
boolean res;
char c = peek();
if (c == '\0') {
return false;
}
switch (c) {
case '\n':
res = parseNewline();
break;
case '\\':
res = parseBackslash();
break;
case '`':
res = parseBackticks();
break;
case '[':
res = parseOpenBracket();
break;
case '!':
res = parseBang();
break;
case ']':
res = parseCloseBracket();
break;
case '<':
res = parseAutolink() || parseHtmlInline();
break;
case '&':
res = parseEntity();
break;
default:
boolean isDelimiter = delimiterCharacters.get(c);
if (isDelimiter) {
DelimiterProcessor delimiterProcessor = delimiterProcessors.get(c);
res = parseDelimiters(delimiterProcessor, c);
} else {
res = parseString();
}
break;
}
if (!res) {
index++;
// When we get here, it's only for a single special character that turned out to not have a special meaning.
// So we shouldn't have a single surrogate here, hence it should be ok to turn it into a String.
String literal = String.valueOf(c);
appendText(literal);
}
return true;
}
示例11: scanDelimiters
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
/**
* Scan a sequence of characters with code delimiterChar, and return information about the number of delimiters
* and whether they are positioned such that they can open and/or close emphasis or strong emphasis.
*
* @return information about delimiter run, or {@code null}
*/
private DelimiterData scanDelimiters(DelimiterProcessor delimiterProcessor, char delimiterChar) {
int startIndex = index;
int delimiterCount = 0;
while (peek() == delimiterChar) {
delimiterCount++;
index++;
}
if (delimiterCount < delimiterProcessor.getMinLength()) {
index = startIndex;
return null;
}
String before = startIndex == 0 ? "\n" :
input.substring(startIndex - 1, startIndex);
char charAfter = peek();
String after = charAfter == '\0' ? "\n" :
String.valueOf(charAfter);
// We could be more lazy here, in most cases we don't need to do every match case.
boolean beforeIsPunctuation = PUNCTUATION.matcher(before).matches();
boolean beforeIsWhitespace = UNICODE_WHITESPACE_CHAR.matcher(before).matches();
boolean afterIsPunctuation = PUNCTUATION.matcher(after).matches();
boolean afterIsWhitespace = UNICODE_WHITESPACE_CHAR.matcher(after).matches();
boolean leftFlanking = !afterIsWhitespace &&
(!afterIsPunctuation || beforeIsWhitespace || beforeIsPunctuation);
boolean rightFlanking = !beforeIsWhitespace &&
(!beforeIsPunctuation || afterIsWhitespace || afterIsPunctuation);
boolean canOpen;
boolean canClose;
if (delimiterChar == '_') {
canOpen = leftFlanking && (!rightFlanking || beforeIsPunctuation);
canClose = rightFlanking && (!leftFlanking || afterIsPunctuation);
} else {
canOpen = leftFlanking && delimiterChar == delimiterProcessor.getOpeningCharacter();
canClose = rightFlanking && delimiterChar == delimiterProcessor.getClosingCharacter();
}
index = startIndex;
return new DelimiterData(delimiterCount, canOpen, canClose);
}
示例12: customDelimiterProcessor
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
/**
* Adds a custom delimiter processor.
* <p>
* Note that multiple delimiter processors with the same characters can be added, as long as they have a
* different minimum length. In that case, the processor with the shortest matching length is used. Adding more
* than one delimiter processor with the same character and minimum length is invalid.
*
* @param delimiterProcessor a delimiter processor implementation
* @return {@code this}
*/
public Builder customDelimiterProcessor(DelimiterProcessor delimiterProcessor) {
delimiterProcessors.add(delimiterProcessor);
return this;
}
示例13: getCustomDelimiterProcessors
import org.commonmark.parser.delimiter.DelimiterProcessor; //導入依賴的package包/類
List<DelimiterProcessor> getCustomDelimiterProcessors();