Search in sources :

Example 26 with Pattern

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);
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern)

Example 27 with Pattern

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;
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) Match(org.rstudio.core.client.regex.Match)

Example 28 with Pattern

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);
}
Also used : Pattern(org.rstudio.core.client.regex.Pattern) ArrayList(java.util.ArrayList) 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