Refine search
public void setTitleChars(BasedSequence titleChars) { if (titleChars != null && titleChars != BasedSequence.NULL) { int titleCharsLength = titleChars.length(); titleOpeningMarker = titleChars.subSequence(0, 1); title = titleChars.subSequence(1, titleCharsLength - 1); titleClosingMarker = titleChars.subSequence(titleCharsLength - 1, titleCharsLength); } else { titleOpeningMarker = BasedSequence.NULL; title = BasedSequence.NULL; titleClosingMarker = BasedSequence.NULL; } }
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); }
public void setTitleChars(BasedSequence titleChars) { if (titleChars != null && titleChars != BasedSequence.NULL) { int titleCharsLength = titleChars.length(); titleOpeningMarker = titleChars.subSequence(0, 1); title = titleChars.subSequence(1, titleCharsLength - 1); titleClosingMarker = titleChars.subSequence(titleCharsLength - 1, titleCharsLength); } else { titleOpeningMarker = BasedSequence.NULL; title = BasedSequence.NULL; titleClosingMarker = BasedSequence.NULL; } } }
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)); }
@Override public BasedSequence ifNullEmptyAfter(BasedSequence other) { return isNull() ? other.subSequence(other.length(), other.length()) : this; }
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 Reference(BasedSequence label, BasedSequence url, BasedSequence title) { super(BasedSequence.NULL); this.openingMarker = label.subSequence(0, 1); this.reference = label.subSequence(1, label.length() - 2).trim(); this.closingMarker = label.subSequence(label.length() - 2, label.length()); setUrlChars(url); if (title != null) { this.titleOpeningMarker = title.subSequence(0, 1); this.title = title.subSequence(1, title.length() - 1); this.titleClosingMarker = title.subSequence(title.length() - 1, title.length()); } setCharsFromContent(); }
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 void setTextChars(BasedSequence textChars) { int textCharsLength = textChars.length(); this.textOpeningMarker = textChars.subSequence(0, 1); this.text = textChars.subSequence(1, textCharsLength - 1).trim(); this.textClosingMarker = textChars.subSequence(textCharsLength - 1, textCharsLength); }
private static List<BasedSequence> split(BasedSequence input, boolean columnSpans, boolean wantPipes) { BasedSequence line = input.trim(); int lineLength = line.length(); List<BasedSequence> segments = new ArrayList<BasedSequence>(); if (wantPipes) segments.add(line.subSequence(0, 1)); line = line.subSequence(1, lineLength); lineLength--; int cellChars = 0; for (int i = 0; i < lineLength; i++) { char c = line.charAt(i); if (escape) { escape = false; break; case '|': if (!columnSpans || lastPos < i) segments.add(line.subSequence(lastPos, i)); if (wantPipes) segments.add(line.subSequence(i, i + 1)); lastPos = i + 1;
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 void setTextChars(BasedSequence textChars) { int textCharsLength = textChars.length(); this.textOpeningMarker = textChars.subSequence(0, 2); this.text = textChars.subSequence(2, textCharsLength - 1).trim(); this.textClosingMarker = textChars.subSequence(textCharsLength - 1, textCharsLength); } }
static List<BasedSequence> split(BasedSequence input) { BasedSequence line = input.trim(); int lineLength = line.length(); List<BasedSequence> segments = new ArrayList<BasedSequence>(); line = line.subSequence(1, lineLength); lineLength--; int cellChars = 0; for (int i = 0; i < lineLength; i++) { char c = line.charAt(i); if (escape) { escape = false; break; case '|': segments.add(line.subSequence(lastPos, i)); segments.add(line.subSequence(lastPos, lineLength));
@Override public void setTextChars(BasedSequence textChars) { int textCharsLength = textChars.length(); this.textOpeningMarker = textChars.subSequence(0, 2); this.text = textChars.subSequence(2, textCharsLength - 1).trim(); this.textClosingMarker = textChars.subSequence(textCharsLength - 1, textCharsLength); }
@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); }