当前位置: 首页>>代码示例>>Java>>正文


Java Matcher.find方法代码示例

本文整理汇总了Java中com.google.re2j.Matcher.find方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.find方法的具体用法?Java Matcher.find怎么用?Java Matcher.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.re2j.Matcher的用法示例。


在下文中一共展示了Matcher.find方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private Set<FileState> run(Iterable<FileState> files, Console console) throws IOException, ValidationException {
  Set<FileState> modifiedFiles = new HashSet<>();
  // TODO(malcon): Remove reconstructing pattern once RE2J doesn't synchronize on matching.
  Pattern batchPattern = Pattern.compile(pattern.pattern(), pattern.flags());
  for (FileState file : files) {
    if (Files.isSymbolicLink(file.getPath())) {
      continue;
    }
    String content = new String(Files.readAllBytes(file.getPath()), UTF_8);
    Matcher matcher = batchPattern.matcher(content);
    StringBuffer sb = new StringBuffer();
    boolean modified = false;
    while (matcher.find()) {
      List<String> users = Splitter.on(",").splitToList(matcher.group(2));
      List<String> mappedUsers = mapUsers(users, matcher.group(0), file.getPath(), console);
      modified |= !users.equals(mappedUsers);
      String result = matcher.group(1);
      if (!mappedUsers.isEmpty()) {
        result += "(" + Joiner.on(",").join(mappedUsers) + ")";
      }
      matcher.appendReplacement(sb, result);
    }
    matcher.appendTail(sb);

    if (modified) {
      modifiedFiles.add(file);
      Files.write(file.getPath(), sb.toString().getBytes(UTF_8));
    }
  }
  return modifiedFiles;
}
 
开发者ID:google,项目名称:copybara,代码行数:32,代码来源:TodoReplace.java

示例2: peekWatermark

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Look at some bytes from {@code xmlInput} to ensure it appears to be a FULL XML deposit and
 * then use a regular expression to extract the watermark timestamp which is returned.
 *
 * @throws IOException
 * @throws XmlException
 */
public static DateTime peekWatermark(BufferedInputStream xmlInput)
    throws IOException, XmlException {
  xmlInput.mark(PEEK_SIZE);
  byte[] peek = new byte[PEEK_SIZE];
  if (xmlInput.read(peek) != PEEK_SIZE) {
    throw new IOException(String.format("Failed to peek %,d bytes on input file", PEEK_SIZE));
  }
  xmlInput.reset();
  String peekStr = new String(peek, UTF_8);
  if (!peekStr.contains("urn:ietf:params:xml:ns:rde-1.0")) {
    throw new XmlException(String.format(
        "Does not appear to be an XML RDE deposit\n%s", dumpHex(peek)));
  }
  if (!peekStr.contains("type=\"FULL\"")) {
    throw new XmlException("Only FULL XML RDE deposits suppported at this time");
  }
  Matcher watermarkMatcher = WATERMARK_PATTERN.matcher(peekStr);
  if (!watermarkMatcher.find()) {
    throw new XmlException("Could not find RDE watermark in XML");
  }
  return DATETIME_FORMATTER.parseDateTime(watermarkMatcher.group(1));
}
 
开发者ID:google,项目名称:nomulus,代码行数:30,代码来源:RdeUtil.java

示例3: build

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Returns the freshly substituted SQL code.
 *
 * @throws IllegalArgumentException if any substitution variable is not found in the template,
 *         or if there are any variable-like strings (%something%) left after substitution.
 */
public String build() {
  StringBuffer result = new StringBuffer(template.length());
  Set<String> found = new HashSet<>();
  Matcher matcher = SEARCH_PATTERN.matcher(template);
  while (matcher.find()) {
    String wholeMatch = matcher.group(0);
    String leftQuote = matcher.group(1);
    String key = matcher.group(2);
    String rightQuote = matcher.group(3);
    String value = substitutions.get(key);
    checkArgumentNotNull(value, "%%s% found in template but no substitution specified", key);
    checkArgument(leftQuote.equals(rightQuote), "Quote mismatch: %s", wholeMatch);
    matcher.appendReplacement(result, String.format("%s%s%s", leftQuote, value, rightQuote));
    found.add(key);
  }
  matcher.appendTail(result);
  Set<String> remaining = difference(substitutions.keySet(), found);
  checkArgument(remaining.isEmpty(),
      "Not found in template: %s", Joiner.on(", ").join(remaining));
  return result.toString();
}
 
开发者ID:google,项目名称:nomulus,代码行数:28,代码来源:SqlTemplate.java

示例4: extractIDString

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Extract Date + ID + No
 * Ex: " 15/02/14(六)07:14:32 ID:F.OqpZFA No.6135732"
 * @return Post
 */
private Post extractIDString(Post post, TextNode node) {
    Pattern r = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{2}).+?(\\d{2}):(\\d{2}):(\\d{2}) ID:([\\./0-9A-Za-z]+?) No\\.(\\d+)");
    Matcher m = r.matcher(node.text());
    if (m.find()) {
        Integer Y = Integer.parseInt(m.group(1)) + 2000, //year
                M = Integer.parseInt(m.group(2)) - 1, //month
                D = Integer.parseInt(m.group(3)), //day
                H = Integer.parseInt(m.group(4)), //hours
                I = Integer.parseInt(m.group(5)), //minutes
                S = Integer.parseInt(m.group(6)); //seconds
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Taipei"));
        cal.set(Y, M, D, H, I, S);
        post.date = cal;

        post.tripId = m.group(7);
        post.no = m.group(8);
    }

    return post;
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:26,代码来源:KomicaScraper.java

示例5: TemplateMessage

import com.google.re2j.Matcher; //导入方法依赖的package包/类
TemplateMessage(String header, boolean ignoreIfLabelNotFound, boolean newLine,
    boolean replaceMessage) {
  this.header = Preconditions.checkNotNull(header);
  this.ignoreIfLabelNotFound = ignoreIfLabelNotFound;
  this.newLine = newLine;
  this.replaceMessage = replaceMessage;
  Matcher matcher = VAR_PATTERN.matcher(header);
  while (matcher.find()) {
    labels.add(matcher.group(1));
  }
}
 
开发者ID:google,项目名称:copybara,代码行数:12,代码来源:TemplateMessage.java

示例6: checkChapterTitle

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private static boolean checkChapterTitle(List<TextChapter> chapterList, int lineCount, String line) {
    if (line != null) {
        if (line.length() > 75) return false; // 超过75字的一般就不是标题了
        /*if(!line.contains("章") &&
                !line.contains("回") &&
                !line.contains("节") &&
                !line.contains("卷") &&
                !line.contains("集") &&
                !line.contains("幕") &&
                !line.contains("计") &&
                !line.contains("部")) { // 不包含这些关键字的话也一般不是章节标题
            return false;
        }*/
        String trimLine = line.trim().replace("\u3000", "");
        if (trimLine != null && trimLine.length() <= 75) {
            Matcher matchResult = chapterNumberPattern.matcher(trimLine);
            int symbolCount = countSymbolsCount(line);
            if (matchResult.find() && matchResult.start() < 5 && symbolCount < 3) {
                Matcher excludeMatcher = chapterNumberExcludePattern.matcher(line);
                if (excludeMatcher.find()) {
                    return false;
                }
                if (matchResult.find(0) && matchResult.start() > 0 && countSymbolsCount(line) > 1) {
                    return false;
                }
                return addToChapterList(chapterList, lineCount, line);
            } else if (trimLine.length() >= 3 && !line.startsWith(" ") && !line.startsWith("\u3000") && line.length() < 30 && countSymbolsCount(line) < 3) {
                String removeSymbol = replaceSymbols(trimLine);
                if (removeSymbol != null && removeSymbol.length() >= 2) {
                    return addToChapterList(chapterList, lineCount, line);
                }
            }
        }
    }
    return false;
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:37,代码来源:LocalTextReader.java

示例7: countSymbolsCount

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private static int countSymbolsCount(String input) {
    Matcher matcher = symbol2Pattern.matcher(input);
    int count = 0;
    while (matcher.find())
        count++;
    return count;
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:8,代码来源:LocalTextReader.java

示例8: parseBookName

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private void parseBookName() {
    String fileName = this.mFile.getName();
    Matcher matcher = bookNamePattern.matcher(fileName);
    while (matcher.find()) {
        mBookName = matcher.group();
        mBookName = mBookName.substring(1, mBookName.length() - 1);
    }
    if (mBookName == null) {
        int lastIndexOfDot = fileName.lastIndexOf(".");
        if (lastIndexOfDot > 0 && lastIndexOfDot < fileName.length())
            mBookName = fileName.substring(0, lastIndexOfDot);
        else
            mBookName = fileName;
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:16,代码来源:LocalTextReader.java

示例9: testAllClassesPrintedExactlyOnce

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Test
public void testAllClassesPrintedExactlyOnce() throws Exception {
  runCommand();
  String stdout = getStdoutAsString();
  for (Class<?> clazz : EntityClasses.ALL_CLASSES) {
    String printableName = GetSchemaTreeCommand.getPrintableName(clazz);
    int count = 0;
    Matcher matcher = Pattern.compile("(^|\\s)" + printableName + "\\s").matcher(stdout);
    while (matcher.find()) {
      count++;
    }
    assertThat(count).named(printableName + " occurences").isEqualTo(1);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:15,代码来源:GetSchemaTreeCommandTest.java

示例10: getNextPageNumber

import com.google.re2j.Matcher; //导入方法依赖的package包/类
public Integer getNextPageNumber() {
    if(nextPageLink == null) {
        return 0;
    } else {
        Pattern p = Pattern.compile("(\\d+).*");
        Matcher m = p.matcher(nextPageLink);
        if(m.find()) {
            return Integer.parseInt(m.group(1));
        } else {
            return 0;
        }
    }
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:14,代码来源:Scraper.java

示例11: replaceLine

import com.google.re2j.Matcher; //导入方法依赖的package包/类
private String replaceLine(String line) {
  if (patternsToIgnore != null) {
    for (Pattern patternToIgnore : patternsToIgnore) {
      if (patternToIgnore.matches(line)) {
        return line;
      }
    }
  }

  Matcher matcher = before.matcher(line);
  StringBuffer sb = new StringBuffer();
  while (matcher.find()) {
    for (Collection<Integer> groupIndexes : repeatedGroups.asMap().values()) {
      // Check that all the references of the repeated group match the same string
      Iterator<Integer> iterator = groupIndexes.iterator();
      String value = matcher.group(iterator.next());
      while (iterator.hasNext()) {
        if (!value.equals(matcher.group(iterator.next()))) {
          return line;
        }
      }
    }
    String replaceTemplate;
    if (callback != null) {
      ImmutableMap.Builder<Integer, String> groupValues =
          ImmutableMap.builder();
      for (int i = 0; i <= matcher.groupCount(); i++) {
        groupValues.put(i, matcher.group(i));
      }
      replaceTemplate = callback.alter(groupValues.build(), afterReplaceTemplate);
    } else {
      replaceTemplate = afterReplaceTemplate;
    }

    matcher.appendReplacement(sb, replaceTemplate);
    if (firstOnly) {
      break;
    }
  }
  matcher.appendTail(sb);
  return sb.toString();
}
 
开发者ID:google,项目名称:copybara,代码行数:43,代码来源:TemplateTokens.java

示例12: extractHtmlTitle

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/** Returns the contents of the title tag in the given HTML, or null if not found. */
private static String extractHtmlTitle(String html) {
  Matcher matcher = HTML_TITLE_TAG_PATTERN.matcher(html);
  return (matcher.find() ? matcher.group(1) : null);
}
 
开发者ID:google,项目名称:nomulus,代码行数:6,代码来源:AppEngineConnection.java

示例13: testDomainTransferPollMessage_serverApproved

import com.google.re2j.Matcher; //导入方法依赖的package包/类
@Test
public void testDomainTransferPollMessage_serverApproved() throws Exception {
  // As the losing registrar, create the domain.
  assertCommandAndResponse("login_valid.xml", "login_response.xml");
  createFakesite();
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // As the winning registrar, request a transfer. Capture the server trid; we'll need it later.
  assertCommandAndResponse("login2_valid.xml", "login_response.xml");
  String response =
      assertCommandAndResponse(
          "domain_transfer_request_1_year.xml",
          "domain_transfer_response_1_year.xml",
          DateTime.parse("2001-01-01T00:00:00Z"));
  Matcher matcher = Pattern.compile("<svTRID>(.*)</svTRID>").matcher(response);
  matcher.find();
  String transferRequestTrid = matcher.group(1);
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // As the losing registrar, read the request poll message, and then ack it.
  assertCommandAndResponse("login_valid.xml", "login_response.xml");
  assertCommandAndResponse(
      "poll.xml",
      "poll_response_domain_transfer_request.xml",
      DateTime.parse("2001-01-01T00:01:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-23-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-01T00:01:00Z"));

  // Five days in the future, expect a server approval poll message to the loser, and ack it.
  assertCommandAndResponse(
      "poll.xml",
      "poll_response_domain_transfer_server_approve_loser.xml",
      DateTime.parse("2001-01-06T00:01:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-22-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-06T00:01:00Z"));
  assertCommandAndResponse("logout.xml", "logout_response.xml");

  // Also expect a server approval poll message to the winner, with the transfer request trid.
  assertCommandAndResponse("login2_valid.xml", "login_response.xml");
  assertCommandAndResponse(
      "poll.xml",
      null,
      "poll_response_domain_transfer_server_approve_winner.xml",
      ImmutableMap.of("SERVER_TRID", transferRequestTrid),
      DateTime.parse("2001-01-06T00:02:00Z"));
  assertCommandAndResponse(
      "poll_ack.xml",
      ImmutableMap.of("ID", "1-C-EXAMPLE-17-21-2001"),
      "poll_ack_response_empty.xml",
      null,
      DateTime.parse("2001-01-06T00:02:00Z"));
  assertCommandAndResponse("logout.xml", "logout_response.xml");
}
 
开发者ID:google,项目名称:nomulus,代码行数:62,代码来源:EppLifecycleDomainTest.java

示例14: extractCssRenames

import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
 * Extract class name rewrites from a {@code .css.js} mapping file.
 *
 * <p>This is the file created when you pass {@code --css_renaming_output_file} to the Closure
 * Stylesheets compiler. In order for this to work, {@code --output_renaming_map_format} should
 * be {@code CLOSURE_COMPILED} or {@code CLOSURE_UNCOMPILED}.
 *
 * <p>Here's an example of what the {@code .css.js} file looks like:<pre>
 *
 *   goog.setCssNameMapping({
 *     "nonLatin": "a",
 *     "secondary": "b",
 *     "mobile": "c"
 *   });</pre>
 *
 * <p>This is a burden that's only necessary for tofu, since the closure compiler is smart enough
 * to substitute CSS class names when soy is compiled to JavaScript.
 */
private static ImmutableMap<String, String> extractCssRenames(String json) {
  ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
  Matcher matcher = KEY_VALUE_PATTERN.matcher(json);
  while (matcher.find()) {
    builder.put(matcher.group(1), matcher.group(2));
  }
  return builder.build();
}
 
开发者ID:google,项目名称:nomulus,代码行数:27,代码来源:SoyTemplateUtils.java


注:本文中的com.google.re2j.Matcher.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。