Java Code Examples for com.google.re2j.Matcher#matches()
The following examples show how to use
com.google.re2j.Matcher#matches() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestGhcnm.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
static private int parseLine(String line) { int balony = 0; Matcher matcher = dataPattern.matcher(line); if (matcher.matches()) { for (int i = 1; i <= matcher.groupCount(); i++) { String r = matcher.group(i); if (r == null) continue; int value = (int) Long.parseLong(r.trim()); balony += value; } } else { System.out.printf("Fail on %s%n", line); } return balony; }
Example 2
Source File: IgraPor.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public StructureData next() throws IOException { Matcher matcher; while (true) { String line = vinfo.rafile.readLine(); if (line == null) return null; if (line.startsWith("#")) continue; if (line.trim().isEmpty()) continue; matcher = vinfo.p.matcher(line); if (matcher.matches()) { String stnid = matcher.group(stn_fldno).trim(); if (stnid.equals(stationId)) break; } } recno++; return new StationData(vinfo.sm, matcher); }
Example 3
Source File: IgraPor.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public StructureData next() throws IOException { Matcher matcher; String line; while (true) { line = timeSeriesRaf.readLine(); if (line == null) return null; // only on EOF if (line.trim().isEmpty()) continue; matcher = seriesVinfo.p.matcher(line); if (matcher.matches()) break; logger.error("FAIL TimeSeriesIter at line {}", line); } countRead++; return new TimeSeriesData(matcher); }
Example 4
Source File: IgraPor.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
TimeSeriesData(Matcher matcher) throws IOException { super(seriesVinfo.sm, matcher); String line; long pos; while (true) { pos = timeSeriesRaf.getFilePointer(); line = timeSeriesRaf.readLine(); if (line == null) break; if (line.trim().isEmpty()) continue; matcher = profileVinfo.p.matcher(line); if (matcher.matches()) lines.add(line); else { timeSeriesRaf.seek(pos); // put the line back break; } } }
Example 5
Source File: GerritDestination.java From copybara with Apache License 2.0 | 6 votes |
@Nullable private Matcher tryFindGerritUrl(List<String> lines) { boolean successFound = false; for (String line : lines) { if ((line.contains("SUCCESS"))) { successFound = true; } if (successFound) { // Usually next line is empty, but let's try best effort to find the URL after "SUCCESS" Matcher urlMatcher = GERRIT_URL_LINE.matcher(line); if (urlMatcher.matches()) { return urlMatcher; } } } return null; }
Example 6
Source File: Ghcnm2.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public StructureData next() throws IOException { Matcher matcher; String line; while (true) { line = dataRaf.readLine(); if (line == null) return null; if (line.startsWith("#")) continue; if (line.trim().isEmpty()) continue; matcher = dataPattern.matcher(line); if (matcher.matches()) break; } countRead++; return new StructureDataRegexp(sm, matcher); }
Example 7
Source File: GitHubPRIntegrateLabel.java From copybara with Apache License 2.0 | 5 votes |
@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; }
Example 8
Source File: Message.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public String extractWMO() { Matcher matcher = wmoPattern.matcher(header); if (!matcher.matches()) { return ""; } return matcher.group(1); }
Example 9
Source File: Scanner.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
static void extractAllWithHeader(String filein, Pattern p, WritableByteChannel wbc) throws IOException { System.out.println("extract " + filein); try (RandomAccessFile raf = new RandomAccessFile(filein, "r")) { MessageScanner scan = new MessageScanner(raf); while (scan.hasNext()) { Message m = scan.next(); Matcher matcher = p.matcher(m.getHeader()); if (matcher.matches()) { scan.writeCurrentMessage(wbc); System.out.println(" found match " + m.getHeader()); } } } }
Example 10
Source File: CalendarDateUnit.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private CalendarDateUnit(Calendar calt, String dateUnitString) { dateUnitString = dateUnitString.trim(); // dateUnitString = dateUnitString.replaceAll("\\s+", " "); LOOK think about should we allow this ?? dateUnitString = dateUnitString.toLowerCase(); isCalendarField = dateUnitString.startsWith(byCalendarString); if (isCalendarField) { dateUnitString = dateUnitString.substring(byCalendarString.length()).trim(); } Matcher m = udunitPattern.matcher(dateUnitString); if (!m.matches()) { throw new IllegalArgumentException(dateUnitString + " does not match " + udunitPatternString); } String unitString = m.group(1); period = CalendarPeriod.of(unitString); periodField = CalendarPeriod.fromUnitString(unitString); int pos = dateUnitString.indexOf("since"); String iso = dateUnitString.substring(pos + 5); baseDate = CalendarDateFormatter.isoStringToCalendarDate(calt, iso); // calendar might change !! calt = baseDate.getCalendar(); this.cal = calt; }
Example 11
Source File: StreamFilter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean accept(Path entry) { String matchOn = nameOnly ? entry.getName(entry.getNameCount() - 1).toString() : StringUtil2.replace(entry.toString(), "\\", "/"); Matcher matcher = this.pattern.matcher(matchOn); return matcher.matches(); }
Example 12
Source File: UnitTestCommon.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public String modify(String text) { String[] lines = text.split("[\n]"); StringBuilder result = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i]; Matcher m = this.pattern.matcher(line); if (m.matches()) { result.append(line); result.append("\n"); } } return result.toString(); }
Example 13
Source File: GerritIntegrateLabel.java From copybara with Apache License 2.0 | 5 votes |
@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; }
Example 14
Source File: UnitTestCommon.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public String modify(String text) { StringBuilder result = new StringBuilder(text); for (Pattern p : patterns) { for (;;) { Matcher m = p.matcher(result.toString()); if (!m.matches()) break; int pos0 = m.start(); int pos1 = m.end(); result.delete(pos0, pos1); } } return result.toString(); }
Example 15
Source File: GitRepository.java From copybara with Apache License 2.0 | 5 votes |
ImmutableList<TreeElement> lsTree(GitRevision reference, @Nullable String treeish, boolean recursive, boolean fullName) throws RepoException { ImmutableList.Builder<TreeElement> result = ImmutableList.builder(); List<String> args = Lists.newArrayList("ls-tree", reference.getSha1()); if (recursive) { args.add("-r"); } if (fullName) { args.add("--full-name"); } if (treeish != null) { args.add("--"); args.add(treeish); } String stdout = simpleCommand(args).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(); }
Example 16
Source File: TestServletLogParser.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void show(String s, Pattern p) { System.out.println("=============================="); Matcher m = p.matcher(s); System.out.printf(" match against %s = %s %n", m, m.matches()); if (!m.matches()) return; for (int i = 1; i <= m.groupCount(); i++) System.out.println(" " + i + " " + m.group(i)); }
Example 17
Source File: LatestVersionSelector.java From copybara with Apache License 2.0 | 4 votes |
@Override public String selectVersion( @Nullable String requestedRef, GitRepository repo, String url, Console console) throws RepoException, ValidationException { if (!Strings.isNullOrEmpty(requestedRef)) { if (requestedRef.startsWith("force:")) { return requestedRef.substring("force:".length()); } console.warnFmt("Ignoring '%s' as git.version_selector is being used.", requestedRef); } Set<String> refs = repo.lsRemote(url, ImmutableList.of(asGitRefspec())).keySet(); ImmutableListMultimap<String, Integer> groupIndexes = template.getGroupIndexes(); List<Object> latest = new ArrayList<>(); String latestRef = null; for (String ref : refs) { Matcher matcher = template.getBefore().matcher(ref); if (!matcher.matches()) { continue; } List<Object> objs = new ArrayList<>(); for (Entry<Integer, VersionElementType> groups : groupTypes .entrySet()) { String var = groups.getValue().varName(groups.getKey()); String val = matcher.group(Iterables.getLast(groupIndexes.get(var))); objs.add(groups.getValue().convert(val)); } if (isAfter(latest, objs)) { latest = objs; latestRef = ref; } } checkCondition(latestRef != null, "version_selector didn't match any version for '%s'", template.getBefore().pattern()); // It is rare that a branch and a tag has the same name. The reason for this is that // destinations expect that the context_reference is a non-full reference. Also it is // more readable when we use it in transformations. if (latestRef.startsWith("refs/heads/")) { return latestRef.substring("refs/heads/".length()); } if (latestRef.startsWith("refs/tags/")) { return latestRef.substring("refs/tags/".length()); } return latestRef; }
Example 18
Source File: GerritChange.java From copybara with Apache License 2.0 | 4 votes |
/** * Given a local repository, a repo url and a reference, it tries to do its best to resolve the * reference to a Gerrit Change. * * <p>Note that if the PatchSet is not found in the ref, it will go to Gerrit to get the latest * PatchSet number. * * @return a Gerrit change if it can be resolved. Null otherwise. */ @Nullable public static GerritChange resolve( GitRepository repository, String repoUrl, String ref, GeneralOptions options) throws RepoException, ValidationException { if (Strings.isNullOrEmpty(ref)) { return null; } Matcher refMatcher = WHOLE_GERRIT_REF.matcher(ref); if (refMatcher.matches()) { return new GerritChange( repository, options, repoUrl, Ints.tryParse(refMatcher.group(1)), Ints.tryParse(refMatcher.group(2)), ref); } // A change number like '23423' if (CharMatcher.javaDigit().matchesAllOf(ref)) { return resolveLatestPatchSet(repository, options, repoUrl, Ints.tryParse(ref)); } Matcher urlMatcher = URL_PATTERN.matcher(ref); if (!urlMatcher.matches()) { return null; } if (!ref.startsWith(repoUrl)) { // Assume it is our url. We can make this more strict later options .console() .warn( String.format( "Assuming repository '%s' for looking for review '%s'", repoUrl, ref)); } int change = Ints.tryParse(urlMatcher.group(1)); Integer patchSet = urlMatcher.group(2) == null ? null : Ints.tryParse(urlMatcher.group(2)); if (patchSet == null) { return resolveLatestPatchSet(repository, options, repoUrl, change); } Map<Integer, GitRevision> patchSets = getGerritPatchSets(repository, repoUrl, change); if (!patchSets.containsKey(patchSet)) { throw new CannotResolveRevisionException( String.format( "Cannot find patch set %d for change %d in %s. Available Patch sets: %s", patchSet, change, repoUrl, patchSets.keySet())); } return new GerritChange( repository, options, repoUrl, change, patchSet, patchSets.get(patchSet).contextReference()); }
Example 19
Source File: CompareTableB.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
String norm(String s) { Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return s; return matcher.group(1); }
Example 20
Source File: N3iosp.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Determine if the given name can be used for a Dimension, Attribute, or Variable name. * Should match makeValidNetcdf3ObjectName. * * @param name test this. * @return true if valid name. * @deprecated use isValidNetcdfObjectName */ public static boolean isValidNetcdf3ObjectName(String name) { Matcher m = objectNamePatternOld.matcher(name); return m.matches(); }