Java Code Examples for org.commonmark.parser.delimiter.DelimiterProcessor#getMinLength()
The following examples show how to use
org.commonmark.parser.delimiter.DelimiterProcessor#getMinLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaggeredDelimiterProcessor.java From 1Rramp-Android with MIT License | 6 votes |
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; } }
Example 2
Source File: StaggeredDelimiterProcessor.java From Markwon with Apache License 2.0 | 6 votes |
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; } }
Example 3
Source File: StaggeredDelimiterProcessor.java From commonmark-java with BSD 2-Clause "Simplified" License | 6 votes |
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; } }
Example 4
Source File: StaggeredDelimiterProcessor.java From 1Rramp-Android with MIT License | 5 votes |
private DelimiterProcessor findProcessor(int len) { for (DelimiterProcessor p : processors) { if (p.getMinLength() <= len) { return p; } } return processors.getFirst(); }
Example 5
Source File: StaggeredDelimiterProcessor.java From Markwon with Apache License 2.0 | 5 votes |
private DelimiterProcessor findProcessor(int len) { for (DelimiterProcessor p : processors) { if (p.getMinLength() <= len) { return p; } } return processors.getFirst(); }
Example 6
Source File: StaggeredDelimiterProcessor.java From commonmark-java with BSD 2-Clause "Simplified" License | 5 votes |
private DelimiterProcessor findProcessor(int len) { for (DelimiterProcessor p : processors) { if (p.getMinLength() <= len) { return p; } } return processors.getFirst(); }
Example 7
Source File: InlineParserImpl.java From 1Rramp-Android with MIT License | 4 votes |
/** * 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); }
Example 8
Source File: MarkwonInlineParser.java From Markwon with Apache License 2.0 | 4 votes |
/** * 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); }
Example 9
Source File: InlineParserImpl.java From commonmark-java with BSD 2-Clause "Simplified" License | 4 votes |
/** * 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); }