Search in sources :

Example 1 with Match

use of org.rstudio.core.client.regex.Match 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 2 with Match

use of org.rstudio.core.client.regex.Match 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)

Example 3 with Match

use of org.rstudio.core.client.regex.Match 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 4 with Match

use of org.rstudio.core.client.regex.Match 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 5 with Match

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

the class StringUtil method pathToTitle.

public static String pathToTitle(String path) {
    String val = FileSystemItem.createFile(path).getStem();
    val = Pattern.create("\\b[a-z]").replaceAll(val, new ReplaceOperation() {

        @Override
        public String replace(Match m) {
            return m.getValue().toUpperCase();
        }
    });
    val = Pattern.create("[-_]").replaceAll(val, " ");
    return val;
}
Also used : ReplaceOperation(org.rstudio.core.client.regex.Pattern.ReplaceOperation) JsArrayString(com.google.gwt.core.client.JsArrayString) Match(org.rstudio.core.client.regex.Match)

Aggregations

Match (org.rstudio.core.client.regex.Match)33 Pattern (org.rstudio.core.client.regex.Pattern)22 JsArrayString (com.google.gwt.core.client.JsArrayString)10 ArrayList (java.util.ArrayList)5 Point (org.rstudio.core.client.Point)3 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)1 Iterator (java.util.Iterator)1 Pair (org.rstudio.core.client.Pair)1 TextCursor (org.rstudio.core.client.TextCursor)1 ReplaceOperation (org.rstudio.core.client.regex.Pattern.ReplaceOperation)1 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)1 InputEditorPosition (org.rstudio.studio.client.workbench.views.console.shell.editor.InputEditorPosition)1 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)1