Search in sources :

Example 6 with Pattern

use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.

the class TextEditingTarget method isExecutableChunk.

private boolean isExecutableChunk(final Scope chunk) {
    if (!chunk.isChunk())
        return false;
    String headerText = docDisplay_.getLine(chunk.getPreamble().getRow());
    Pattern reEvalFalse = Pattern.create("eval\\s*=\\s*F(?:ALSE)?");
    if (reEvalFalse.test(headerText))
        return false;
    return true;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 7 with Pattern

use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.

the class ImagePreviewer method imgSrcPathFromHref.

private static String imgSrcPathFromHref(DocUpdateSentinel sentinel, String href) {
    // return paths that have a custom / external protocol as-is
    Pattern reProtocol = Pattern.create("^\\w+://");
    if (reProtocol.test(href))
        return href;
    // make relative paths absolute
    String absPath = href;
    if (FilePathUtils.pathIsRelative(href)) {
        String docPath = sentinel.getPath();
        absPath = FilePathUtils.dirFromFile(docPath) + "/" + absPath;
    }
    return "file_show?path=" + StringUtil.encodeURIComponent(absPath) + "&id=" + IMAGE_ID++;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern)

Example 8 with Pattern

use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.

the class AceEditor method moveSelectionToNextLine.

public boolean moveSelectionToNextLine(boolean skipBlankLines) {
    int curRow = getSession().getSelection().getCursor().getRow();
    while (++curRow < getSession().getLength()) {
        String line = getSession().getLine(curRow);
        Pattern pattern = Pattern.create("[^\\s]");
        Match match = pattern.match(line, 0);
        if (skipBlankLines && match == null)
            continue;
        int col = (match != null) ? match.getIndex() : 0;
        getSession().getSelection().moveCursorTo(curRow, col, false);
        getSession().unfold(curRow, true);
        scrollCursorIntoViewIfNecessary();
        return true;
    }
    return false;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) JsArrayString(com.google.gwt.core.client.JsArrayString) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) Match(org.rstudio.core.client.regex.Match)

Example 9 with Pattern

use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.

the class PosixFileSystemContext method parseDir.

public FileSystemItem[] parseDir(String dirPath) {
    ArrayList<FileSystemItem> results = new ArrayList<FileSystemItem>();
    if (dirPath.startsWith("/"))
        results.add(FileSystemItem.createDir("/"));
    Pattern pattern = Pattern.create("[^/]+");
    Match m = pattern.match(dirPath, 0);
    while (m != null) {
        results.add(FileSystemItem.createDir(dirPath.substring(0, m.getIndex() + m.getValue().length())));
        m = m.nextMatch();
    }
    return results.toArray(new FileSystemItem[0]);
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) ArrayList(java.util.ArrayList) Match(org.rstudio.core.client.regex.Match)

Example 10 with Pattern

use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.

the class StringUtil method getLineIterator.

public static Iterable<String> getLineIterator(final String text) {
    return new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            return new Iterator<String>() {

                private int pos = 0;

                private Pattern newline = Pattern.create("\\r?\\n");

                @Override
                public boolean hasNext() {
                    return pos < text.length();
                }

                @Override
                public String next() {
                    if (pos >= text.length())
                        return null;
                    Match match = newline.match(text, pos);
                    String result;
                    if (match == null) {
                        result = text.substring(pos);
                        pos = text.length();
                    } else {
                        result = text.substring(pos, match.getIndex());
                        pos = match.getIndex() + match.getValue().length();
                    }
                    return result;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) Iterator(java.util.Iterator) JsArrayString(com.google.gwt.core.client.JsArrayString) Match(org.rstudio.core.client.regex.Match)

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