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);
}
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();
}
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);
}
}
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();
}
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);
}
Aggregations