Search in sources :

Example 11 with Pattern

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);
    }
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) Match(org.rstudio.core.client.regex.Match)

Example 12 with Pattern

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)));
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) JsArrayString(com.google.gwt.core.client.JsArrayString) Point(org.rstudio.core.client.Point) Match(org.rstudio.core.client.regex.Match)

Example 13 with Pattern

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;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) Match(org.rstudio.core.client.regex.Match)

Example 14 with Pattern

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);
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) ArrayList(java.util.ArrayList) Match(org.rstudio.core.client.regex.Match)

Example 15 with Pattern

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);
        }
    });
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) OpenFileInBrowserEvent(org.rstudio.studio.client.common.filetypes.events.OpenFileInBrowserEvent) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType) FileType(org.rstudio.studio.client.common.filetypes.FileType) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) ServerError(org.rstudio.studio.client.server.ServerError) EditableFileType(org.rstudio.studio.client.common.filetypes.EditableFileType)

Aggregations

Pattern (org.rstudio.core.client.regex.Pattern)28 Match (org.rstudio.core.client.regex.Match)22 JsArrayString (com.google.gwt.core.client.JsArrayString)8 ArrayList (java.util.ArrayList)3 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)3 Point (org.rstudio.core.client.Point)2 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)2 Iterator (java.util.Iterator)1 TextCursor (org.rstudio.core.client.TextCursor)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 EditableFileType (org.rstudio.studio.client.common.filetypes.EditableFileType)1 FileType (org.rstudio.studio.client.common.filetypes.FileType)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 OpenFileInBrowserEvent (org.rstudio.studio.client.common.filetypes.events.OpenFileInBrowserEvent)1 ServerError (org.rstudio.studio.client.server.ServerError)1 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)1 AceFold (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceFold)1 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)1