Search in sources :

Example 26 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project che by eclipse.

the class StringCharacterScanner method getColumn.

private int getColumn(int offset) {
    // Bad and slow implementation
    if (offset < 0 || offset > this.content.length()) {
        return -1;
    }
    if (this.delimiters == null || this.delimiters.isEmpty()) {
        return offset;
    }
    final StringBuilder sb = new StringBuilder("[");
    for (final String delimiter : this.delimiters) {
        sb.append("(?:").append(delimiter).append(")");
    }
    sb.append("]");
    final RegExp regexp = RegExp.compile(sb.toString());
    final String split = this.content;
    int currentIndex = 0;
    while (currentIndex < offset) {
        final MatchResult matchResult = regexp.exec(split);
        final int found = matchResult.getIndex();
        if (found < 0) {
            throw new RuntimeException("Invalid index for regexp match");
        }
        if (currentIndex + found > offset) {
            // we're on the same line as offset
            return offset - currentIndex;
        }
        currentIndex = currentIndex + found + 1;
    }
    return -1;
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 27 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project che by eclipse.

the class CloseCStyleCommentChangeInterceptor method processChange.

@Override
public TextChange processChange(final TextChange change, ReadOnlyDocument document) {
    final RegExp regex = RegExp.compile("^\n(\\s*)\\*\\s*$");
    final MatchResult matchResult = regex.exec(change.getNewText());
    // either must be on the first line or be just after a line break (regexp)
    if (matchResult != null) {
        final String line = document.getLineContent(change.getFrom().getLine());
        // matches a line containing only whitespaces followed by either /** or /* and then optionally whitespaces again
        if (!line.matches("^\\s*\\/\\*\\*?\\s*$")) {
            return null;
        }
        final String whitespaces = matchResult.getGroup(1);
        final String modifiedInsert = "\n" + whitespaces + "* \n" + whitespaces + "*/";
        return new TextChange.Builder().from(change.getFrom()).to(change.getFrom()).insert(modifiedInsert).build();
    } else {
        return null;
    }
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 28 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project che by eclipse.

the class FirstLineFileTypeIdentifier method getShebang.

private String getShebang(final String content) {
    final MatchResult matchResult = SHEBANG_PATTERN.exec(content);
    if (matchResult == null || matchResult.getGroup(1) == null || matchResult.getGroup(1).isEmpty()) {
        return null;
    }
    Log.debug(FirstLineFileTypeIdentifier.class, "File may be a script with a shebang.");
    String loader = matchResult.getGroup(1);
    // special case for /usr/bin/env
    if ("/usr/bin/env".equals(loader)) {
        Log.debug(FirstLineFileTypeIdentifier.class, "Shebang points to /usr/bin/env. Looking at the parameter.");
        // we must use the first option as hint
        if (matchResult.getGroup(2) == null || matchResult.getGroup(2).isEmpty()) {
            return null;
        }
        loader = matchResult.getGroup(2);
        Log.debug(FirstLineFileTypeIdentifier.class, "Shebang parameter kept: " + loader);
    } else {
        Log.debug(FirstLineFileTypeIdentifier.class, "Shebang loader kept: " + loader);
    }
    return loader;
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 29 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project che by eclipse.

the class Elements method markupParagraph.

/** Creates a paragraph tag and fills it with spans and anchor tags internally. */
private static void markupParagraph(Element parent, String text, String linkCssClass) {
    if (StringUtils.isNullOrWhitespace(text)) {
        // don't add any dom here
        return;
    }
    ParagraphElement myParagraph = createParagraphElement();
    int index = 0;
    REGEXP_MARKUP.setLastIndex(0);
    SpanElement current = createSpanElement();
    for (MatchResult match = REGEXP_MARKUP.exec(text); match != null; match = REGEXP_MARKUP.exec(text)) {
        current.setTextContent(text.substring(index, match.getIndex()));
        myParagraph.appendChild(current);
        current = createSpanElement();
        /*
       * If our match is a \n we need to create a <br/> element to force a line break, otherwise we
       * matched an http/www link so let's make an anchor tag out of it.
       */
        if (match.getGroup(0).equals("\n")) {
            myParagraph.appendChild(createBRElement());
        } else {
            AnchorElement anchor = createAnchorElement(linkCssClass);
            anchor.setHref(match.getGroup(0));
            anchor.setTarget("_blank");
            anchor.setTextContent(match.getGroup(0));
            myParagraph.appendChild(anchor);
        }
        index = match.getIndex() + match.getGroup(0).length();
    }
    current.setTextContent(text.substring(index));
    myParagraph.appendChild(current);
    parent.appendChild(myParagraph);
}
Also used : SpanElement(elemental.html.SpanElement) ParagraphElement(elemental.html.ParagraphElement) AnchorElement(elemental.html.AnchorElement) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 30 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project che by eclipse.

the class TextUtils method directionalRegexp.

/**
     * Depending on the supplied direction, it will call either
     * findMatchAfterIndex or findMatchBeforeIndex. Once the result is obtained it
     * will return either the match index or the appropriate bound column
     * (text.length() or -1).
     */
private static int directionalRegexp(boolean forward, RegExp regexp, String text, int column) {
    MatchResult result = forward ? RegExpUtils.findMatchAfterIndex(regexp, text, column) : RegExpUtils.findMatchBeforeIndex(regexp, text, column);
    int fallback = forward ? text.length() : -1;
    return result == null ? fallback : result.getIndex();
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Aggregations

MatchResult (com.google.gwt.regexp.shared.MatchResult)47 RegExp (com.google.gwt.regexp.shared.RegExp)23 ArrayList (java.util.ArrayList)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)3 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Node (com.google.gwt.dom.client.Node)1 PreElement (com.google.gwt.dom.client.PreElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)1 ItemTexts (cz.metacentrum.perun.webgui.model.ItemTexts)1 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 CollectionId (edu.stanford.bmir.protege.web.shared.collection.CollectionId)1 CollectionItem (edu.stanford.bmir.protege.web.shared.collection.CollectionItem)1 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1