use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class ApplicationUtils method getHostPageBaseURLWithoutContext.
public static String getHostPageBaseURLWithoutContext(boolean includeSlash) {
String replaceWith = includeSlash ? "/" : "";
String url = GWT.getHostPageBaseURL();
Pattern pattern = Pattern.create("/s/[A-Fa-f0-9]{5}[A-Fa-f0-9]{8}[A-Fa-f0-9]{8}/");
return pattern.replaceAll(url, replaceWith);
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class RMarkdownChunkHeaderParser method consumeUntilRegex.
private static final boolean consumeUntilRegex(TextCursor cursor, String regex, Consumer consumer) {
Pattern pattern = Pattern.create(regex);
Match match = pattern.match(cursor.getData(), cursor.getIndex());
if (match == null)
return false;
int startIdx = cursor.getIndex();
int endIdx = match.getIndex();
if (consumer != null) {
String value = cursor.getData().substring(startIdx, endIdx);
consumer.consume(value);
}
cursor.setIndex(endIdx);
return true;
}
use of org.rstudio.core.client.regex.Pattern in project rstudio by rstudio.
the class SVNDiffParser method nextFilePair.
@Override
public DiffFileHeader nextFilePair() {
pendingDiffChunks_.clear();
if (sections_.size() == 0)
return null;
ArrayList<Section> sectionsToUse = new ArrayList<Section>();
sectionsToUse.add(sections_.remove(0));
String filename = sectionsToUse.get(0).filename;
while (sections_.size() > 0 && sections_.get(0).filename.equals(filename)) {
sectionsToUse.add(sections_.remove(0));
}
// Put the properties above the item diffs.
Collections.sort(sectionsToUse, new Comparator<Section>() {
@Override
public int compare(Section a, Section b) {
return a.isProperty == b.isProperty ? 0 : a.isProperty ? -1 : 1;
}
});
Section lastSection = null;
for (Section section : sectionsToUse) {
if (section.isProperty) {
String trimmed = StringUtil.trimBlankLines(section.data);
pendingDiffChunks_.add(createInfoChunk(StringUtil.getLineIterator(trimmed)));
} else {
UnifiedParser parser = new UnifiedParser(section.data, diffIndex_);
DiffFileHeader filePair = parser.nextFilePair();
if (filePair == null) {
// Although "Index: <filename>" appeared, no diff was actually
// generated (e.g. binary file)
Pattern hrule = Pattern.create("^=+$");
Match m = hrule.match(section.data, 0);
int startAt = (m != null) ? m.getIndex() + m.getValue().length() : 0;
Iterable<String> lines = StringUtil.getLineIterator(StringUtil.trimBlankLines(section.data.substring(startAt)));
DiffChunk chunk = createInfoChunk(lines);
if (lastSection != null && lastSection.isProperty) {
// This is to work around special case where a binary file is
// initially checked in. If we do nothing, in the history it
// will appear as the property changes, then without a break,
// the message that this file can't be displayed. That's the
// correct content, but we want it in the order of the message
// that the file can't be displayed, then a blank line, then
// the property changes.
pendingDiffChunks_.add(0, chunk);
pendingDiffChunks_.add(1, createInfoChunk(StringUtil.getLineIterator("\n")));
} else {
pendingDiffChunks_.add(chunk);
}
}
DiffChunk chunk;
while (null != (chunk = parser.nextChunk())) {
pendingDiffChunks_.add(chunk);
}
diffIndex_ = parser.getDiffIndex();
}
lastSection = section;
}
return new DiffFileHeader(new ArrayList<String>(), filename, filename);
}
Aggregations