Search in sources :

Example 21 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project perun by CESNET.

the class JsonUtils method isStringWithIds.

/**
 * Whether string contains IDs separated by a comma
 *
 * @param text
 * @return
 */
public static boolean isStringWithIds(String text) {
    final String IDS_PATTERN = "^[0-9, ]+$";
    RegExp regExp = RegExp.compile(IDS_PATTERN);
    MatchResult matcher = regExp.exec(text);
    return (matcher != null);
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) JsArrayString(com.google.gwt.core.client.JsArrayString) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 22 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project perun by CESNET.

the class TestJSONParserTabItem method draw.

public Widget draw() {
    Button sendMessageButton = new Button("Parse response");
    final FlexTable ft = new FlexTable();
    ft.setCellSpacing(15);
    int row = 0;
    ft.setText(row, 0, "Server response:");
    ft.setWidget(row, 1, returnedValue);
    row++;
    ft.setText(row, 0, "Callback name:");
    ft.setHTML(row, 1, "callbackPost");
    row++;
    ft.setWidget(row, 0, sendMessageButton);
    row++;
    sendMessageButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            String resp = returnedValue.getText();
            // trims the whitespace
            resp = resp.trim();
            // short comparing
            if (("callbackPost(null);").equalsIgnoreCase(resp)) {
                UiElements.generateInfo("Parser result", "Parsed value is: NULL");
            }
            // if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
            RegExp re = RegExp.compile("^" + "callbackPost" + "\\((.*)\\)|\\);$");
            MatchResult result = re.exec(resp);
            if (result != null) {
                resp = result.getGroup(1);
            }
            UiElements.generateInfo("Unwrapped value", "Non-null unwrapped value is: " + resp);
            // if response = null - return null
            if (resp.equals("null")) {
                UiElements.generateInfo("Parser result", "Parsed value is: NULL");
            }
            // normal object
            JavaScriptObject jso = JsonUtils.parseJson(resp);
            BasicOverlayType basic = jso.cast();
            UiElements.generateInfo("Parser result", "Parsed result is: " + basic.getString());
        }
    });
    this.contentWidget.setWidget(ft);
    return getWidget();
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegExp(com.google.gwt.regexp.shared.RegExp) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 23 with MatchResult

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

the class FuzzyMatches method fuzzyMatch.

public List<Match> fuzzyMatch(String word, String wordToMatch, boolean substringMatch) {
    RegExp regExp = regExpCache.get(word);
    if (regExp == null) {
        regExp = convertWordToRegExp(word);
        regExpCache.put(word, regExp);
    }
    MatchResult matchResult = regExp.exec(wordToMatch);
    if (matchResult != null) {
        return Collections.singletonList(new Match(matchResult.getIndex(), matchResult.getIndex() + matchResult.getGroup(0).length()));
    }
    if (substringMatch) {
        return FUZZY_SEPARATE.match(word, wordToMatch);
    } else {
        return FUZZY_CONTIGUOUS.match(word, wordToMatch);
    }
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 24 with MatchResult

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

the class OutputConsoleViewImpl method print.

@Override
public void print(final String text, boolean carriageReturn, String color) {
    if (this.carriageReturn) {
        Node lastChild = consoleLines.getElement().getLastChild();
        if (lastChild != null) {
            lastChild.removeFromParent();
        }
    }
    this.carriageReturn = carriageReturn;
    final SafeHtml colorOutput = new SafeHtml() {

        @Override
        public String asString() {
            if (Strings.isNullOrEmpty(text)) {
                return " ";
            }
            for (final Pair<RegExp, String> pair : output2Color) {
                final MatchResult matcher = pair.first.exec(text);
                if (matcher != null) {
                    return text.replaceAll(matcher.getGroup(1), "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
                }
            }
            return text;
        }
    };
    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerSafeHtml(colorOutput);
    if (color != null) {
        pre.getStyle().setColor(color);
    }
    consoleLines.getElement().appendChild(pre);
    followOutput();
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) PreElement(com.google.gwt.dom.client.PreElement) Node(com.google.gwt.dom.client.Node) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 25 with MatchResult

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

the class TestServiceClient method getOrCreateTestCompileCommand.

public Promise<CommandImpl> getOrCreateTestCompileCommand() {
    List<CommandImpl> commands = commandManager.getCommands();
    for (CommandImpl command : commands) {
        if (command.getName() != null && command.getName().startsWith("test-compile") && "mvn".equals(command.getType())) {
            return promiseProvider.resolve(command);
        }
    }
    for (CommandImpl command : commands) {
        if ("build".equals(command.getName()) && "mvn".equals(command.getType())) {
            String commandLine = command.getCommandLine();
            MatchResult result = mavenCleanBuildPattern.exec(commandLine);
            if (result != null) {
                String testCompileCommandLine = mavenCleanBuildPattern.replace(commandLine, "$1mvn test-compile $2");
                return commandManager.create("test-compile", testCompileCommandLine, "mvn", new HashMap<String, String>());
            }
        }
    }
    return promiseProvider.resolve(null);
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) 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