Java Code Examples for org.commonmark.parser.delimiter.DelimiterProcessor#getClosingCharacter()
The following examples show how to use
org.commonmark.parser.delimiter.DelimiterProcessor#getClosingCharacter() .
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: InlineParserImpl.java From 1Rramp-Android with MIT License | 6 votes |
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); } } }
Example 2
Source File: MarkwonInlineParser.java From Markwon with Apache License 2.0 | 6 votes |
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); } } }
Example 3
Source File: InlineParserImpl.java From commonmark-java with BSD 2-Clause "Simplified" License | 6 votes |
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); } } }
Example 4
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 5
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 6
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); }