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]);
}
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();
}
};
}
};
}
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);
}
}
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)));
}
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;
}
Aggregations