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