Refine search
private void findNextNonSpace() { int i = index; int cols = column; blank = true; while (i < line.length()) { char c = line.charAt(i); switch (c) { case ' ': i++; cols++; continue; case '\t': i++; cols += (4 - (cols % 4)); continue; } blank = false; break; } nextNonSpace = i; nextNonSpaceColumn = cols; indent = nextNonSpaceColumn - column; }
@Override public boolean isMatch(BasedSequence nodeChars) { final int length = nodeChars.length(); if (options.imageLinks) { if (length >= 5 && nodeChars.charAt(0) == '!') { return nodeChars.charAt(1) == '[' && nodeChars.charAt(2) == '[' && nodeChars.endCharAt(1) == ']' && nodeChars.endCharAt(2) == ']'; } else if (length >= 4) { return nodeChars.charAt(0) == '[' && nodeChars.charAt(1) == '[' && nodeChars.endCharAt(1) == ']' && nodeChars.endCharAt(2) == ']'; } } else if (length >= 4) { return nodeChars.charAt(0) == '[' && nodeChars.charAt(1) == '[' && nodeChars.endCharAt(1) == ']' && nodeChars.endCharAt(2) == ']'; } return false; }
public int length() { int total = 0; BasedSequence last = null; for (BasedSequence s : segments) { if (s.isEmpty()) continue; if (last != null && last.getEndOffset() < s.getStartOffset() && (BasedSequence.WHITESPACE_CHARS.indexOf(last.charAt(last.length() - 1)) == -1) && BasedSequence.WHITESPACE_CHARS.indexOf(s.charAt(0)) == -1) { total++; } total++; last = s; } return total; }
/** * Parse a run of ordinary characters, or a single character with a special meaning in markdown, as a plain string. * * @return true if processed characters false otherwise */ protected boolean parseString() { int begin = index; int length = input.length(); while (index != length) { if (specialCharacters.get(input.charAt(index))) { break; } index++; } if (begin != index) { appendText(input, begin, index); return true; } else { return false; } }
@SuppressWarnings("WeakerAccess") public HtmlWriter srcPosWithTrailingEOL(BasedSequence sourceText) { if (sourceText.isNotNull()) { int endOffset = sourceText.getEndOffset(); BasedSequence base = sourceText.getBaseSequence(); while (endOffset < base.length()) { char c = base.charAt(endOffset); if (c != ' ' && c != '\t') break; endOffset++; } if (endOffset < base.length() && base.charAt(endOffset) == '\r') { endOffset++; } if (endOffset < base.length() && base.charAt(endOffset) == '\n') { endOffset++; } return srcPos(sourceText.getStartOffset(), endOffset); } return this; }
public static BasedSequence stripIndent(BasedSequence input, CharSequence sourceIndent) { BasedSequence result = input; if (sourceIndent.length() != 0) { // strip out indent to test how segmented input parses ArrayList<BasedSequence> segments = new ArrayList<>(); int lastPos = 0; int length = input.length(); while (lastPos < length) { int pos = input.indexOf(sourceIndent, lastPos); int end = pos == -1 ? length : pos; if (lastPos < end && (pos <= 0 || input.charAt(pos - 1) == '\n')) { segments.add(input.subSequence(lastPos, end)); } lastPos = end + sourceIndent.length(); } result = SegmentedSequence.of(segments); } return result; }
public TocBlockBase(BasedSequence chars, BasedSequence styleChars, boolean closingSimToc) { super(chars); openingMarker = chars.subSequence(0, 1); tocKeyword = chars.subSequence(1, 4); if (styleChars != null) { style = styleChars; } int closingPos = chars.indexOf(']', 4); if (closingSimToc && !(closingPos != -1 && closingPos + 1 < chars.length() && chars.charAt(closingPos + 1) == ':')) { throw new IllegalStateException("Invalid TOC block sequence"); } closingMarker = chars.subSequence(closingPos, closingPos + (closingSimToc ? 2 : 1)); }
public TocBlock(BasedSequence chars, BasedSequence styleChars, boolean closingSimToc) { super(chars); openingMarker = chars.subSequence(0, 1); tocKeyword = chars.subSequence(1, 4); if (styleChars != null) { style = styleChars; } int closingPos = chars.indexOf(']', 4); if (closingSimToc && !(closingPos != -1 && closingPos + 1 < chars.length() && chars.charAt(closingPos + 1) == ':')) { throw new IllegalStateException("Invalid TOC block sequence"); } closingMarker = chars.subSequence(closingPos, closingPos + (closingSimToc ? 2 : 1)); }
public void setReferenceChars(BasedSequence referenceChars) { int referenceCharsLength = referenceChars.length(); int openingOffset = referenceChars.charAt(0) == '!' ? 2 : 1; this.referenceOpeningMarker = referenceChars.subSequence(0, openingOffset); this.reference = referenceChars.subSequence(openingOffset, referenceCharsLength - 1).trim(); this.referenceClosingMarker = referenceChars.subSequence(referenceCharsLength - 1, referenceCharsLength); }
@Override public String toString() { int total = 0; StringBuilder sb = new StringBuilder(); BasedSequence last = null; for (BasedSequence s : segments) { if (s.isEmpty()) continue; if (last != null && last.getEndOffset() < s.getStartOffset() && (BasedSequence.WHITESPACE_CHARS.indexOf(last.charAt(last.length() - 1)) == -1) && BasedSequence.WHITESPACE_CHARS.indexOf(s.charAt(0)) == -1 && s.baseSubSequence(last.getEndOffset(), s.getStartOffset()).endsWith(" ") ) { sb.append(' '); } s.appendTo(sb); last = s; } return sb.toString(); } }
@Override public BlockContinue tryContinue(ParserState state) { int nextNonSpace = state.getNextNonSpaceIndex(); int newIndex = state.getIndex(); BasedSequence line = state.getLine(); Matcher matcher; boolean matches = (state.getIndent() <= 3 && nextNonSpace < line.length() && (!matchingCloser || line.charAt(nextNonSpace) == fenceChar)); if (matches) { BasedSequence trySequence = line.subSequence(nextNonSpace, line.length()); matcher = CLOSING_FENCE.matcher(trySequence); if (matcher.find()) { int foundFenceLength = matcher.group(0).length(); if (foundFenceLength >= fenceLength) { // closing fence - we're at end of line, so we can finalize now block.setClosingMarker(trySequence.subSequence(0, foundFenceLength)); return BlockContinue.finished(); } } } // skip optional spaces of fence indent int i = fenceIndent; while (i > 0 && newIndex < line.length() && line.charAt(newIndex) == ' ') { newIndex++; i--; } return BlockContinue.atIndex(newIndex); }
@Override public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { BasedSequence line = state.getLine(); if (state.getIndex() == 0) { int breakLength = myOptions.exampleBreak.length(); if (line.length() >= breakLength + 1 + EXAMPLE_KEYWORD.length() && line.startsWith(myOptions.exampleBreak) && line.matchChars(EXAMPLE_KEYWORD, breakLength + 1) && " \t\u00A0".contains(String.valueOf(line.charAt(breakLength)))) { SpecExampleBlockParser blockParser = new SpecExampleBlockParser(state.getProperties()); blockParser.block.setOpeningMarker(line.subSequence(0, breakLength)); //blockParser.addLine(state, state.getLineWithEOL()); return BlockStart.of(blockParser).atIndex(-1); } } return BlockStart.none(); } }