Refine search
/** * Say whether this regular expression can be found at the beginning of * this String. This method provides one of the two "missing" * convenience methods for regular expressions in the String class * in JDK1.4. * * @param str String to search for match at start of * @param regex String to compile as the regular expression * @return Whether the regex can be found at the start of str */ public static boolean lookingAt(String str, String regex) { return Pattern.compile(regex).matcher(str).lookingAt(); }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
mig = ignoreRegexp.matcher(word); if (mig != null && mig.lookingAt()) { word = word.substring(mig.end()); } else { Matcher m = tokenizerRegexp.matcher(word); if (m.lookingAt()) { al.add(word.substring(0, m.end())); word = word.substring(m.end()); } else { logger.info("Warning: regexpTokenize pattern " + tokenizerRegexp + " didn't match on |" +
/** * Extracts the long literal corresponding to a given {@link LiteralTree} node from the source * code as a string. Returns null if the source code is not available. */ private static String getLongLiteral(LiteralTree literalTree, VisitorState state) { JCLiteral longLiteral = (JCLiteral) literalTree; CharSequence sourceFile = state.getSourceCode(); if (sourceFile == null) { return null; } int start = longLiteral.getStartPosition(); java.util.regex.Matcher matcher = LONG_LITERAL_PATTERN.matcher(sourceFile.subSequence(start, sourceFile.length())); if (matcher.lookingAt()) { return matcher.group(); } return null; }
Matcher typeSubtype = TYPE_SUBTYPE.matcher(string); if (!typeSubtype.lookingAt()) { throw new IllegalArgumentException("No subtype found for: \"" + string + '"'); String type = typeSubtype.group(1).toLowerCase(Locale.US); String subtype = typeSubtype.group(2).toLowerCase(Locale.US); Matcher parameter = PARAMETER.matcher(string); for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) { parameter.region(s, string.length()); if (!parameter.lookingAt()) { throw new IllegalArgumentException("Parameter is not formatted correctly: \"" + string.substring(s) String name = parameter.group(1); if (name == null || !name.equalsIgnoreCase("charset")) continue; String charsetParameter;
checkArgument(LOWERCASE.matcher(argument).matches(), "argument '%s' must start with a lowercase character", argument); if (colon != -1) { int endIndex = Math.min(colon + 2, format.length()); matcher = NAMED_ARGUMENT.matcher(format.substring(p, endIndex)); if (matcher != null && matcher.lookingAt()) { String argumentName = matcher.group("argumentName"); checkArgument(arguments.containsKey(argumentName), "Missing named argument for $%s", argumentName); char formatChar = matcher.group("typeChar").charAt(0); addArgument(format, formatChar, arguments.get(argumentName)); formatParts.add("$" + formatChar);
boolean tagFound = false; for (DocTag tag : DocTag.docTags) { Matcher matcher = tag.pattern.matcher(ss); if (matcher.lookingAt()) { StringBuffer sbuf = new StringBuffer(); matcher.appendReplacement(sbuf, tag.replacement); !Character.isWhitespace(sb.charAt(index + matcher.end() + 1))) { sbuf.append(' '); index + 1 + matcher.end(), sbuf.toString()); index += sbuf.length() - 1; tagFound = true;
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
final Matcher numberMatcher = numberPattern.matcher(expression.substring(position)); if (numberMatcher.lookingAt()) { String numberPart = numberMatcher.group(1); if (!numberPart.isEmpty()) { try { final Matcher identifierMatcher = identifierPattern.matcher(expression.substring(position)); if (identifierMatcher.lookingAt()) { String identifierPart = identifierMatcher.group(1); if (!identifierPart.isEmpty()) { if (keywords.contains(identifierPart)) {
public boolean setOptions(Properties opts) { for(String opt : opts.stringPropertyNames()) { String value = opts.getProperty(opt); if(value == null) { System.err.printf("%s: Read parameter with null value (%s)\n", this.getClass().getName(),opt); continue; } configuredOptions.add(opt); Matcher pathMatcher = ConfigParser.matchPath.matcher(opt); if(pathMatcher.lookingAt()) { pathsToData.add(new File(value)); configuredOptions.add(ConfigParser.paramPath); } else if(opt.equals(ConfigParser.paramName)) { Matcher inThisFilename = fileNameNormalizer.matcher(value.trim()); outFileName = inThisFilename.replaceAll("-"); toStringBuffer.append(String.format("Dataset Name: %s\n",value.trim())); } } if(!configuredOptions.containsAll(requiredOptions)) return false; //Finalize the output file names outFileName += ".txt"; //Used for codifying lexical hacks lexMapper = new DefaultLexicalMapper(); return true; }
protected void parseText() { while(true) { if (matcher.lookingAt()) { offset = matcher.start(); if (matcher.group(2) != null) { processPar(); else if (matcher.group(3) != null) { processPattern(); else if (matcher.group(4) != null) { processOp(TokenType.COMMA, 3); if (matcher.end() == text.length()) { break; matcher.region(matcher.end(), text.length());
private static List<KerberosRule> parseRules(String defaultRealm, List<String> rules) { List<KerberosRule> result = new ArrayList<>(); for (String rule : rules) { Matcher matcher = RULE_PARSER.matcher(rule); if (!matcher.lookingAt()) { throw new IllegalArgumentException("Invalid rule: " + rule); } if (rule.length() != matcher.end()) throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`"); if (matcher.group(2) != null) { result.add(new KerberosRule(defaultRealm)); } else { result.add(new KerberosRule(defaultRealm, Integer.parseInt(matcher.group(5)), matcher.group(6), matcher.group(8), matcher.group(10), matcher.group(11), "g".equals(matcher.group(12)), "L".equals(matcher.group(13)))); } } return result; }