use of com.google.gwt.regexp.shared.RegExp 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;
}
use of com.google.gwt.regexp.shared.RegExp 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;
}
}
use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.
the class FindActionPresenter method nameChanged.
@Override
public void nameChanged(String name, boolean checkBoxState) {
if (name.isEmpty()) {
view.hideActions();
return;
}
String pattern = convertPattern(name.trim());
RegExp regExp = RegExp.compile(pattern);
Map<Action, String> actions = new TreeMap<>(actionComparator);
if (checkBoxState) {
Set<String> ids = ((ActionManagerImpl) actionManager).getActionIds();
for (Action action : actionsMap.keySet()) {
ids.remove(actionManager.getId(action));
}
for (String id : ids) {
Action action = actionManager.getAction(id);
Presentation presentation = action.getTemplatePresentation();
String text = presentation.getText();
if (text != null && regExp.test(text)) {
actions.put(action, null);
}
}
}
List<String> excludedActionIds = getExcludedActionIds(actionManager);
for (Entry<Action, String> entry : actionsMap.entrySet()) {
final Action action = entry.getKey();
final String groupName = entry.getValue();
if (excludedActionIds.contains(actionManager.getId(action))) {
continue;
}
Presentation presentation = action.getTemplatePresentation();
String text = presentation.getText();
if (text != null && regExp.test(text)) {
actions.put(action, groupName);
}
}
if (!actions.isEmpty()) {
view.showActions(actions);
} else {
view.hideActions();
}
}
use of com.google.gwt.regexp.shared.RegExp in project rstudio by rstudio.
the class YamlFrontMatter method getFrontMatterRange.
public static Range getFrontMatterRange(DocDisplay display) {
// front matter can end with ... rather than ---; see spec:
// http://www.yaml.org/spec/1.2/spec.html#id2760395
RegExp frontMatterBegin = RegExp.compile("^---\\s*$", "gm");
RegExp frontMatterEnd = RegExp.compile("^(---|\\.\\.\\.)\\s*$", "gm");
Position begin = null;
Position end = null;
for (int i = 0; i < display.getRowCount(); i++) {
String code = display.getLine(i);
if (begin == null) {
// haven't found front matter begin yet; test this line
MatchResult beginMatch = frontMatterBegin.exec(code);
if (beginMatch == null) {
// Markdown package)
if (!code.matches("\\s*"))
break;
} else {
begin = Position.create(i + 1, 0);
continue;
}
} else if (end == null) {
// haven't found front matter end yet; test this line
MatchResult endMatch = frontMatterEnd.exec(code);
if (endMatch != null) {
end = Position.create(i, 0);
break;
}
}
}
if (begin == null || end == null)
return null;
return Range.fromPoints(begin, end);
}
use of com.google.gwt.regexp.shared.RegExp in project rstudio by rstudio.
the class AppNameTextbox method validateAppName.
public void validateAppName() {
if (!host_.supportsTitle()) {
String app = appTitle_.getText();
RegExp validReg = RegExp.compile("^[A-Za-z0-9_-]{4,63}$");
validTitle_ = validReg.test(app);
setAppNameValid(validTitle_);
if (validTitle_)
name_ = app;
else
error_.setText("The title must contain 3 - 64 alphanumeric " + "characters.");
return;
}
// if we don't have enough characters, bail out early
final String title = appTitle_.getText().trim();
if (title.length() < 3) {
validTitle_ = false;
// if we also don't have focus in the box, show an error
if (DomUtils.getActiveElement() != appTitle_.getElement()) {
setAppNameValid(false);
error_.setText("The title must contain at least 3 characters.");
}
return;
}
host_.generateAppName(title, new CommandWithArg<RSConnectAppName>() {
@Override
public void execute(RSConnectAppName arg) {
name_ = arg.name();
validTitle_ = arg.valid();
error_.setText(arg.error());
setAppNameValid(arg.valid());
}
});
}
Aggregations