Java Code Examples for org.commonmark.internal.util.Parsing#skipSpaceTab()

The following examples show how to use org.commonmark.internal.util.Parsing#skipSpaceTab() . 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: LinkReferenceDefinitionParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int startDefinition(CharSequence line, int i) {
    i = Parsing.skipSpaceTab(line, i, line.length());
    if (i >= line.length() || line.charAt(i) != '[') {
        return -1;
    }

    state = State.LABEL;
    label = new StringBuilder();

    int labelStart = i + 1;
    if (labelStart >= line.length()) {
        label.append('\n');
    }

    return labelStart;
}
 
Example 2
Source File: LinkReferenceDefinitionParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int destination(CharSequence line, int i) {
    i = Parsing.skipSpaceTab(line, i, line.length());
    int afterDestination = LinkScanner.scanLinkDestination(line, i);
    if (afterDestination == -1) {
        return -1;
    }

    destination = (line.charAt(i) == '<')
            ? line.subSequence(i + 1, afterDestination - 1).toString()
            : line.subSequence(i, afterDestination).toString();

    int afterSpace = Parsing.skipSpaceTab(line, afterDestination, line.length());
    if (afterSpace >= line.length()) {
        // Destination was at end of line, so this is a valid reference for sure (and maybe a title).
        // If not at end of line, wait for title to be valid first.
        referenceValid = true;
        paragraph.setLength(0);
    } else if (afterSpace == afterDestination) {
        // spec: The title must be separated from the link destination by whitespace
        return -1;
    }

    state = State.START_TITLE;
    return afterSpace;
}
 
Example 3
Source File: FencedCodeBlockParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean isClosing(CharSequence line, int index) {
    char fenceChar = block.getFenceChar();
    int fenceLength = block.getFenceLength();
    int fences = Parsing.skip(fenceChar, line, index, line.length()) - index;
    if (fences < fenceLength) {
        return false;
    }
    // spec: The closing code fence [...] may be followed only by spaces, which are ignored.
    int after = Parsing.skipSpaceTab(line, index + fences, line.length());
    return after == line.length();
}
 
Example 4
Source File: LinkReferenceDefinitionParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int label(CharSequence line, int i) {
    int afterLabel = LinkScanner.scanLinkLabelContent(line, i);
    if (afterLabel == -1) {
        return -1;
    }

    label.append(line, i, afterLabel);

    if (afterLabel >= line.length()) {
        // label might continue on next line
        label.append('\n');
        return afterLabel;
    } else if (line.charAt(afterLabel) == ']') {
        int colon = afterLabel + 1;
        // end of label
        if (colon >= line.length() || line.charAt(colon) != ':') {
            return -1;
        }

        // spec: A link label can have at most 999 characters inside the square brackets.
        if (label.length() > 999) {
            return -1;
        }

        String normalizedLabel = Escaping.normalizeLabelContent(label.toString());
        if (normalizedLabel.isEmpty()) {
            return -1;
        }

        this.normalizedLabel = normalizedLabel;
        state = State.DESTINATION;

        return Parsing.skipSpaceTab(line, colon + 1, line.length());
    } else {
        return -1;
    }
}
 
Example 5
Source File: LinkReferenceDefinitionParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int startTitle(CharSequence line, int i) {
    i = Parsing.skipSpaceTab(line, i, line.length());
    if (i >= line.length()) {
        state = State.START_DEFINITION;
        return i;
    }

    titleDelimiter = '\0';
    char c = line.charAt(i);
    switch (c) {
        case '"':
        case '\'':
            titleDelimiter = c;
            break;
        case '(':
            titleDelimiter = ')';
            break;
    }

    if (titleDelimiter != '\0') {
        state = State.TITLE;
        title = new StringBuilder();
        i++;
        if (i == line.length()) {
            title.append('\n');
        }
    } else {
        finishReference();
        // There might be another reference instead, try that for the same character.
        state = State.START_DEFINITION;
    }
    return i;
}
 
Example 6
Source File: LinkReferenceDefinitionParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int title(CharSequence line, int i) {
    int afterTitle = LinkScanner.scanLinkTitleContent(line, i, titleDelimiter);
    if (afterTitle == -1) {
        // Invalid title, stop
        return -1;
    }

    title.append(line.subSequence(i, afterTitle));

    if (afterTitle >= line.length()) {
        // Title still going, continue on next line
        title.append('\n');
        return afterTitle;
    }

    int afterTitleDelimiter = afterTitle + 1;
    int afterSpace = Parsing.skipSpaceTab(line, afterTitleDelimiter, line.length());
    if (afterSpace != line.length()) {
        // spec: No further non-whitespace characters may occur on the line.
        return -1;
    }
    referenceValid = true;
    finishReference();
    paragraph.setLength(0);

    // See if there's another definition.
    state = State.START_DEFINITION;
    return afterSpace;
}
 
Example 7
Source File: HeadingParser.java    From commonmark-java with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static boolean isSetextHeadingRest(CharSequence line, int index, char marker) {
    int afterMarker = Parsing.skip(marker, line, index, line.length());
    int afterSpace = Parsing.skipSpaceTab(line, afterMarker, line.length());
    return afterSpace >= line.length();
}