Esempio n. 1
0
 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
     throws IOException {
   if (m != null) m.reset(root.relativize(dir).toString());
   return m == null || m.matches() || m.hitEnd()
       ? FileVisitResult.CONTINUE
       : FileVisitResult.SKIP_SUBTREE;
 }
Esempio n. 2
0
  /**
   * Leave only the value for RCS keywords.
   *
   * <p>For example, <code>$Revision: 1.1 $</code> becomes <code>1.0</code>.
   */
  public String replaceRcsKeywords(String text) {
    if (matcher == null) {
      matcher =
          Pattern.compile(
                  "\\$(Author|Date|Header|Id|Locker|Log|Name|RCSFile|Revision|Source|State): (.+?) \\$")
              .matcher(text);
    } else {
      matcher.reset(text);
    }

    StringBuffer buffer = new StringBuffer();
    while (matcher.find()) {
      String string = matcher.group(2);

      // For the Date: keyword, have a shot at reformatting string
      if ("Date".equals(matcher.group(1))) {
        try {
          DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
          Date date = dateFormat.parse(string);
          string = date.toString();
        } catch (ParseException e) {
        } // if we can't parse, return unchanged
      }

      matcher.appendReplacement(buffer, string);
    }
    matcher.appendTail(buffer);
    return buffer.toString();
  }
Esempio n. 3
0
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   if (attrs.isRegularFile()) {
     if (m != null) m.reset(root.relativize(file).toString());
     if (m == null || m.matches())
       futures.add(exec.submit(new FileLoader(root, file, blocSize)));
   }
   return FileVisitResult.CONTINUE;
 }
Esempio n. 4
0
 public static void main(String[] args) {
   String[] msgs = {
     "Java has regular expressions in 1.4",
     "regular expressions now expressing in Java",
     "Java represses oracular expressions"
   };
   Pattern p = Pattern.compile("re\\w*");
   Matcher matcher = null;
   for (int i = 0; i < msgs.length; i++) {
     if (matcher == null) {
       matcher = p.matcher(msgs[i]);
     } else {
       matcher.reset(msgs[i]);
     }
     System.out.println(matcher.replaceAll("¹þ¹þ\2"));
   }
 }
Esempio n. 5
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    Matcher m =
        Pattern.compile(
                "(?<countryCode>\\d{1,3})"
                    + "([ -])"
                    + "(?<localAreaCode>\\d{1,3})"
                    + "\\2"
                    + "(?<number>\\d{4,10})")
            .matcher("");

    int N = Integer.parseInt(in.nextLine());
    while (N-- > 0) {
      String line = in.nextLine();
      if (m.reset(line).matches()) {
        String countryCode = m.group("countryCode");
        String localAreaCode = m.group("localAreaCode");
        String number = m.group("number");
        String output =
            "CountryCode=" + countryCode + ",LocalAreaCode=" + localAreaCode + ",Number=" + number;
        System.out.println(output);
      }
    }
  }