use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class FileSystemDialog method extractFilterExtension.
// NOTE: web mode only supports a single one-extension filter (whereas
// desktop mode supports full multi-filetype, multi-extension filtering).
// to support more sophisticated filtering we'd need to both add the
// UI as well as update this function to extract a list of filters
private String extractFilterExtension(String filter) {
if (StringUtil.isNullOrEmpty(filter)) {
return null;
} else {
Pattern p = Pattern.create("\\(\\*(\\.[^)]*)\\)$");
Match m = p.match(filter, 0);
if (m == null)
return null;
else
return m.getGroup(1);
}
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class DomUtils method setInnerText.
public static void setInnerText(Element el, String plainText) {
el.setInnerText("");
if (plainText == null || plainText.length() == 0)
return;
Document doc = el.getOwnerDocument();
Pattern pattern = Pattern.create("\\n");
int tail = 0;
Match match = pattern.match(plainText, 0);
while (match != null) {
if (tail != match.getIndex()) {
String line = plainText.substring(tail, match.getIndex());
el.appendChild(doc.createTextNode(line));
}
el.appendChild(doc.createBRElement());
tail = match.getIndex() + 1;
match = match.nextMatch();
}
if (tail < plainText.length())
el.appendChild(doc.createTextNode(plainText.substring(tail)));
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class TextCursor method consumeUntilRegex.
public boolean consumeUntilRegex(String regex) {
Pattern pattern = Pattern.create(regex);
Match match = pattern.match(data_, index_);
if (match == null)
return false;
index_ = match.getIndex();
return true;
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class CodeSearchOracle method requestSuggestions.
@Override
public void requestSuggestions(final Request request, final Callback callback) {
// invalidate any outstanding search
searchInvalidation_.invalidate();
// first see if we can serve the request from the cache
for (int i = resultCache_.size() - 1; i >= 0; i--) {
// get the previous result
SearchResult res = resultCache_.get(i);
// exact match of previous query
if (request.getQuery().equals(res.getQuery())) {
callback.onSuggestionsReady(request, new Response(res.getSuggestions()));
return;
}
// previous query then satisfy it by filtering the previous results
if (!res.getMoreAvailable() && request.getQuery().startsWith(res.getQuery())) {
Pattern pattern = null;
String query = request.getQuery();
String queryLower = query.toLowerCase();
if (queryLower.indexOf('*') != -1)
pattern = patternForTerm(queryLower);
ArrayList<CodeSearchSuggestion> suggestions = new ArrayList<CodeSearchSuggestion>();
for (int s = 0; s < res.getSuggestions().size(); s++) {
CodeSearchSuggestion sugg = res.getSuggestions().get(s);
String name = sugg.getMatchedString().toLowerCase();
if (pattern != null) {
Match match = pattern.match(name, 0);
if (match != null && match.getIndex() == 0)
suggestions.add(sugg);
} else {
int colonIndex = query.indexOf(":");
if (colonIndex == -1)
colonIndex = query.length();
if (StringUtil.isSubsequence(name, query.substring(0, colonIndex), true))
suggestions.add(sugg);
}
}
// process and cache suggestions. note that this adds an item to
// the end of the resultCache_ (which we are currently iterating
// over) no biggie because we are about to return from the loop
suggestions = processSuggestions(request, suggestions, false);
// sort suggestions
sortSuggestions(suggestions, query);
// return suggestions
callback.onSuggestionsReady(request, new Response(suggestions));
return;
}
}
// failed to short-circuit via the cache, hit the server
codeSearch_.enqueRequest(request, callback);
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method navigateToUrl.
private void navigateToUrl(String url) {
// allow web links starting with 'www'
if (url.startsWith("www."))
url = "http://" + url;
// attempt to open web links in a new window
Pattern reWebLink = Pattern.create("^https?://");
if (reWebLink.test(url)) {
globalDisplay_.openWindow(url);
return;
}
// handle testthat links
Pattern reSrcRef = Pattern.create("@[^#]+#\\d+");
if (reSrcRef.test(url))
return;
// treat other URLs as paths to files on the server
final String finalUrl = url;
server_.stat(finalUrl, new ServerRequestCallback<FileSystemItem>() {
@Override
public void onResponseReceived(FileSystemItem file) {
// inform user when no file found
if (file == null || !file.exists()) {
String message = "No file at path '" + finalUrl + "'.";
String caption = "Error navigating to file";
globalDisplay_.showErrorMessage(caption, message);
return;
}
// if we have a registered filetype for this file, try
// to open it in the IDE; otherwise open in browser
FileType fileType = fileTypeRegistry_.getTypeForFile(file);
if (fileType != null && fileType instanceof EditableFileType) {
fileType.openFile(file, null, NavigationMethods.DEFAULT, events_);
} else {
events_.fireEvent(new OpenFileInBrowserEvent(file));
}
}
@Override
public void onError(ServerError error) {
Debug.logError(error);
}
});
}
Aggregations