Package org.rstudio.core.client.regex

Examples of org.rstudio.core.client.regex.Pattern


    *    /help/base/ls
    */
   private String removeHost(String url)
   {
      String pageUrl = Document.get().getURL();
      Pattern p = Pattern.create("^http(s?)://[^/]+");
      Match m = p.match(pageUrl, 0);
      if (m == null)
      {
         assert false : "Couldn't parse page URL: " + url;
         return url;
      }
View Full Code Here


      public String data;
   }

   public SVNDiffParser(String data)
   {
      Pattern sectionHeaderPattern = Pattern.create(
            "^((Index: ([^\\r\\n]+)\\r?\\n=+)|(\\r?\\nProperty changes on: ([^\\r\\n]+)\\r?\\n_+))$");

      ArrayList<String> sectionData = new ArrayList<String>();
      ArrayList<Match> sectionMatches = new ArrayList<Match>();

      int pos = 0;
      int lastHeaderStart = -1;
      Match m;
      while (null != (m = sectionHeaderPattern.match(data, pos)))
      {
         sectionMatches.add(m);

         if (lastHeaderStart >= 0)
            sectionData.add(data.substring(lastHeaderStart, m.getIndex()));
View Full Code Here

            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);
View Full Code Here

      // create regex pattern used to find leading space
      // NOTE: the 4 spaces comes from the implementation of printtab2buff
      // in deparse.c -- it is hard-coded to use 4 spaces for the first 4
      // levels of indentation and then 2 spaces for subsequent levels.
      final String replaceWith = replaceText;
      Pattern pattern = Pattern.create("^(    ){1,4}");
      code = pattern.replaceAll(code, new ReplaceOperation()
      {
         @Override
         public String replace(Match m)
         {
            return m.getValue().replace("    ", replaceWith);
         }
      });
      Pattern pattern2 = Pattern.create("^\t{4}(  )+");
      code = pattern2.replaceAll(code, new ReplaceOperation()
      {
         @Override
         public String replace(Match m)
         {
            return m.getValue().replace("  ",  replaceWith);
View Full Code Here

   {
      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);
View Full Code Here

     
      if (prefs_.stripTrailingWhitespace().getValue() &&
          !fileType_.isMarkdown())
      {
         String code = docDisplay_.getCode();
         Pattern pattern = Pattern.create("[ \t]+$");
         String strippedCode = pattern.replaceAll(code, "");
         if (!strippedCode.equals(code))
            docDisplay_.setCode(strippedCode, true);
      }
     
      if (prefs_.autoAppendNewline().getValue() || fileType_.isPython())
View Full Code Here

      return false;
   }

   private String extractIndentation(String code)
   {
      Pattern leadingWhitespace = Pattern.create("^(\\s*)");
      Match match = leadingWhitespace.match(code, 0);
      return match == null ? "" : match.getGroup(1);
   }
View Full Code Here

                               final InputEditorPosition cursorPos)
   {
      String code = docDisplay_.getCode(selection);
      String[] lines = code.split("\n");
      String prefix = StringUtil.getCommonPrefix(lines, true);
      Pattern pattern = Pattern.create("^\\s*" + commentPrefix + "+('?)\\s*");
      Match match = pattern.match(prefix, 0);
      // Selection includes non-comments? Abort.
      if (match == null)
         return;
      prefix = match.getValue();
      final boolean roxygen = match.hasGroup(1);
View Full Code Here

   {
      String searchString = display_.getFindValue().getValue();
      if (searchString.length() == 0)
         return;

      Pattern pattern = createPattern();
      String line = editor_.getCurrentLine();
      Match m = pattern.match(line,
                              editor_.getSelectionStart().getColumn());
      if (m != null
          && m.getIndex() == editor_.getSelectionStart().getColumn()
          && m.getValue().length() == editor_.getSelectionValue().length())
      {
View Full Code Here

      String repl = display_.getReplaceValue().getValue();

      int occurrences = 0;
      if (find.length() > 0)
      {
         Pattern pattern = createPattern();
         StringBuilder result = new StringBuilder();

         int pos = 0; // pointer into original string
         for (Match m = pattern.match(code, 0);
              m != null;
              m = m.nextMatch())
         {
            occurrences++;
View Full Code Here

TOP

Related Classes of org.rstudio.core.client.regex.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.