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


Java Matcher类代码示例

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


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

示例1: deserialize

import com.google.re2j.Matcher; //导入依赖的package包/类
@Override
public DeserializedEvent deserialize(String raw) {
  Matcher m = this.pattern.matcher(raw);

  if (!m.matches()) {
    throw new DeserializationException("raw event does not match string");
  }

  int groups = m.groupCount();
  Map<String, Object> mapping = new HashMap<>(groups);
  for (int i = 0; i < groups && i < fields.size(); i++) {
    String str = m.group(i + 1);

    ReFieldConfig field = this.fields.get(i);
    mapping.put(field.getName(), RegexDeserializer.parse(str, field.getType()));
  }

  return new RegexEvent(mapping);
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:20,代码来源:Re2jRegexDeserializer.java

示例2: 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

示例3: lsTree

import com.google.re2j.Matcher; //导入依赖的package包/类
ImmutableList<TreeElement> lsTree(GitRevision reference, String treeish) throws RepoException {
  ImmutableList.Builder<TreeElement> result = ImmutableList.builder();
  String stdout = simpleCommand("ls-tree", reference.getSha1(), "--", treeish).getStdout();
  for (String line : Splitter.on('\n').split(stdout)) {
    if (line.isEmpty()) {
      continue;
    }
    Matcher matcher = LS_TREE_ELEMENT.matcher(line);
    if (!matcher.matches()) {
      throw new RepoException("Unexpected format for ls-tree output: " + line);
    }
    // We ignore the mode for now
    GitObjectType objectType = GitObjectType.valueOf(matcher.group(2).toUpperCase());
    String sha1 = matcher.group(3);
    String path = matcher.group(4)
        // Per ls-tree documentation. Replace those escaped characters.
        .replace("\\\\", "\\").replace("\\t", "\t").replace("\\n", "\n");

    result.add(new TreeElement(objectType, sha1, path));
  }
  return result.build();
}
 
开发者ID:google,项目名称:copybara,代码行数:23,代码来源:GitRepository.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: parse

import com.google.re2j.Matcher; //导入依赖的package包/类
@Nullable
static GerritIntegrateLabel parse(String str, GitRepository repository,
    GeneralOptions generalOptions) {
  Matcher matcher = LABEL_PATTERN.matcher(str);
  return matcher.matches()
         ? new GerritIntegrateLabel(repository, generalOptions,
                                    matcher.group(1),
                                    Integer.parseInt(matcher.group(2)),
                                    (matcher.group(3) == null
                                     ? null
                                     : Integer.parseInt(matcher.group(3))),
                                    matcher.group(4))
         : null;
}
 
开发者ID:google,项目名称:copybara,代码行数:15,代码来源:GerritIntegrateLabel.java

示例9: parse

import com.google.re2j.Matcher; //导入依赖的package包/类
@Nullable
static GithubPRIntegrateLabel parse(String str, GitRepository repository,
    GeneralOptions generalOptions) {
  Matcher matcher = LABEL_PATTERN.matcher(str);
  return matcher.matches()
         ? new GithubPRIntegrateLabel(repository, generalOptions,
                                      matcher.group(1),
                                      Long.parseLong(matcher.group(2)),
                                      matcher.group(3),
                                      matcher.group(4))
         : null;
}
 
开发者ID:google,项目名称:copybara,代码行数:13,代码来源:GithubPRIntegrateLabel.java

示例10: maybeParseGithubPrFromHeadRef

import com.google.re2j.Matcher; //导入依赖的package包/类
/**
 * Given a ref like 'refs/pull/12345/head' returns 12345 or null it not a GitHub PR ref
 */
static Optional<Integer> maybeParseGithubPrFromHeadRef(String ref) {
  Matcher matcher = GITHUB_PULL_REQUEST_REF.matcher(ref);
  return (matcher.matches() && "head".equals(matcher.group(2)))
         ? Optional.of(Integer.parseInt(matcher.group(1)))
         : Optional.empty();
}
 
开发者ID:google,项目名称:copybara,代码行数:10,代码来源:GithubUtil.java

示例11: parse

import com.google.re2j.Matcher; //导入依赖的package包/类
/**
 * Parses a Git author {@code string} into an {@link Author}.
 */
public static Author parse(String author) throws InvalidAuthorException {
  Preconditions.checkNotNull(author);
  Matcher matcher = AUTHOR_PATTERN.matcher(author);
  if (!matcher.matches()) {
    throw new InvalidAuthorException(
        String.format("Invalid author '%s'. Must be in the form of 'Name <email>'", author));
  }
  return new Author(matcher.group(1).trim(), matcher.group(2).trim());
}
 
开发者ID:google,项目名称:copybara,代码行数:13,代码来源:AuthorParser.java

示例12: 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

示例13: 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

示例14: 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

示例15: readCodepoint

import com.google.re2j.Matcher; //导入依赖的package包/类
/**
 * Read the codepoint from a single line. The expected format of each line is:
 * {@code U+XXXX}
 * Where {@code XXXX} holds the hex value of the codepoint.
 */
private static int readCodepoint(String line) {
  Matcher matcher = LINE_PATTERN.matcher(line);
  checkArgument(matcher.lookingAt(), "Can't parse line: %s", line);

  String hexString = matcher.group(1);
  return Integer.valueOf(hexString, 16);
}
 
开发者ID:google,项目名称:nomulus,代码行数:13,代码来源:IdnTable.java


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