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


Java Matcher.lookingAt方法代码示例

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


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

示例1: parseRules

import java.util.regex.Matcher; //导入方法依赖的package包/类
static List<Rule> parseRules(String rules) {
  List<Rule> result = new ArrayList<Rule>();
  String remaining = rules.trim();
  while (remaining.length() > 0) {
    Matcher matcher = ruleParser.matcher(remaining);
    if (!matcher.lookingAt()) {
      throw new IllegalArgumentException("Invalid rule: " + remaining);
    }
    if (matcher.group(2) != null) {
      result.add(new Rule());
    } else {
      result.add(new Rule(Integer.parseInt(matcher.group(4)),
                          matcher.group(5),
                          matcher.group(7),
                          matcher.group(9),
                          matcher.group(10),
                          "g".equals(matcher.group(11))));
    }
    remaining = remaining.substring(matcher.end());
  }
  return result;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:KerberosName.java

示例2: parseRules

import java.util.regex.Matcher; //导入方法依赖的package包/类
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(4)),
                    matcher.group(5),
                    matcher.group(7),
                    matcher.group(9),
                    matcher.group(10),
                    "g".equals(matcher.group(11))));

        }
    }
    return result;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:25,代码来源:KerberosShortNamer.java

示例3: lexComment

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Tokenizes between comment delimiters.
 * <p>
 * Simply find the closing delimiter for the comment and move the cursor to
 * that point.
 *
 * @throws ParserException
 */
private void lexComment() throws ParserException {

    // all we need to do is find the end of the comment.
    Matcher matcher = this.syntax.getRegexCommentClose().matcher(source);

    boolean match = matcher.find(0);
    if (!match) {
        throw new ParserException(null, "Unclosed comment.", source.getLineNumber(), source.getFilename());
    }

    /*
     * check if the commented ended with the whitespace trim character by
     * reversing the comment and performing a regular forward regex search.
     */
    String comment = source.substring(matcher.start());
    String reversedComment = new StringBuilder(comment).reverse().toString();
    Matcher whitespaceTrimMatcher = this.syntax.getRegexLeadingWhitespaceTrim().matcher(reversedComment);
    if (whitespaceTrimMatcher.lookingAt()) {
        this.trimLeadingWhitespaceFromNextData = true;
    }

    // move cursor to end of comment (and closing delimiter)
    source.advance(matcher.end());
    popState();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:34,代码来源:LexerImpl.java

示例4: RuleParser

import java.util.regex.Matcher; //导入方法依赖的package包/类
RuleParser(String rule) {
    Matcher m = tokenizer.matcher(rule);
    List<String> list = new ArrayList<>();
    int end = 0;
    while (m.lookingAt()) {
        list.add(m.group(1));
        end = m.end();
        m.region(m.end(), m.regionEnd());
    }
    if (end != m.regionEnd()) {
        throw new RuleParseError("Unexpected tokens :" + rule.substring(m.end(), m.regionEnd()));
    }
    tokens = list.toArray(new String[0]);

    matchDescriptor = parseExpression();
    if (!done()) {
        throw new RuleParseError("didn't consume all tokens");
    }
    capturedNames.add(0, "root");
    capturedTypes.add(0, matchDescriptor.nodeType);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:MatchProcessor.java

示例5: getKeyPropertyList

import java.util.regex.Matcher; //导入方法依赖的package包/类
static LinkedHashMap<String, String> getKeyPropertyList(ObjectName mbeanName) {
    // Implement a version of ObjectName.getKeyPropertyList that returns the
    // properties in the ordered they were added (the ObjectName stores them
    // in the order they were added).
    LinkedHashMap<String, String> output = new LinkedHashMap<String, String>();
    String properties = mbeanName.getKeyPropertyListString();
    Matcher match = PROPERTY_PATTERN.matcher(properties);
    while (match.lookingAt()) {
        output.put(match.group(1), match.group(2));
        properties = properties.substring(match.end());
        if (properties.startsWith(",")) {
            properties = properties.substring(1);
        }
        match.reset(properties);
    }
    return output;
}
 
开发者ID:flokkr,项目名称:jmxpromo,代码行数:18,代码来源:JmxScraper.java

示例6: rateStrToInt

import java.util.regex.Matcher; //导入方法依赖的package包/类
static int rateStrToInt(String str) {
    int rate = -1;
    Pattern p = Pattern.compile("(\\d+)\\s*([kKmMgG])");
    Matcher m = p.matcher(str);

    if (m.lookingAt()) {
        try {
            rate = Integer.parseInt(m.group(1));
        } catch (Exception e) {
            return -1;
        }

        String unitStr = m.group(2);
        if (unitStr.equalsIgnoreCase("K")) {
            return rate;
        } else if (unitStr.equalsIgnoreCase("M")) {
            return rate * 1000;
        } else if (unitStr.equalsIgnoreCase("G")) {
            return rate * 1000000;
        }
    }

    return -1;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:25,代码来源:EXAtraxInterface.java

示例7: executeCommand

import java.util.regex.Matcher; //导入方法依赖的package包/类
void executeCommand(String cmdStr) {
	try {
		Matcher m = COMMAND.matcher(cmdStr);
		if (m.lookingAt()) {
			String cmd = m.group(1);
			if (commands.containsKey(cmd))
				commands.get(cmd).execute(this, cmdStr.substring(m.end()).trim());
			else
				throw new Exception("unknown command " + cmd + ", type '@help' to get a list of commands");
		}
		else
			ShellCommand.QUERY.execute(this, cmdStr);
	}
	catch (ParseException pe) {
		System.err.println(pe.getMessage());
	}
	catch (TokenMgrError tme) {
		System.err.println(tme.getMessage());
	}
	catch (Exception e) {
		//System.err.println(e.getMessage());
		e.printStackTrace(System.err);
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:25,代码来源:ShellEnvironment.java

示例8: parseRules

import java.util.regex.Matcher; //导入方法依赖的package包/类
static List<Rule> parseRules(String rules) {
  List<Rule> result = new ArrayList<Rule>();
  String remaining = rules.trim();
  while (remaining.length() > 0) {
    Matcher matcher = ruleParser.matcher(remaining);
    if (!matcher.lookingAt()) {
      throw new IllegalArgumentException("Invalid rule: " + remaining);
    }
    if (matcher.group(2) != null) {
      result.add(new Rule());
    } else {
      result.add(new Rule(Integer.parseInt(matcher.group(4)),
                          matcher.group(5),
                          matcher.group(7),
                          matcher.group(9),
                          matcher.group(10),
                          "g".equals(matcher.group(11)),
                          "L".equals(matcher.group(12))));
    }
    remaining = remaining.substring(matcher.end());
  }
  return result;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:KerberosName.java

示例9: checkForLeadingWhitespaceTrim

import java.util.regex.Matcher; //导入方法依赖的package包/类
private void checkForLeadingWhitespaceTrim(Token leadingToken) {

        Matcher whitespaceTrimMatcher = this.syntax.getRegexLeadingWhitespaceTrim().matcher(source);

        if (whitespaceTrimMatcher.lookingAt()) {
            if (leadingToken != null) {
                leadingToken.setValue(StringUtils.rtrim(leadingToken.getValue()));
            }
            source.advance(whitespaceTrimMatcher.end());
        }

    }
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:LexerImpl.java

示例10: lexStringInterpolation

import java.util.regex.Matcher; //导入方法依赖的package包/类
private void lexStringInterpolation() throws ParserException {
    String lastBracket = brackets.peek().getLeft();
    Matcher matcher = syntax.getRegexInterpolationClose().matcher(source);
    if (syntax.getInterpolationOpenDelimiter().equals(lastBracket) && matcher.lookingAt()) {
        brackets.pop();
        pushToken(Token.Type.STRING_INTERPOLATION_END);
        source.advance(matcher.end());
        popState();
    } else {
        lexExpression();
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:LexerImpl.java

示例11: parseExplainCall

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Parse EXPLAIN <query>
 * @param statement  statement to parse
 * @return           query parameter string or NULL if statement wasn't recognized
 */
public static String parseExplainCall(String statement)
{
    Matcher matcher = ExplainCallPreamble.matcher(statement);
    if ( ! matcher.lookingAt()) {
        return null;
    }
    return statement.substring(matcher.end());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:14,代码来源:SQLParser.java

示例12: show_ip_all

import java.util.regex.Matcher; //导入方法依赖的package包/类
boolean show_ip_all() throws IOException, ConsoleException,
        AbortedException {
    execute(EXAtraxDiscovery.show_ip_all);

    String str = skipto("^\\s*IP\\s*\"default\"");
    if (str == null) {
        return false;
    }

    str = search("^\\s*IP\\s*address\\s*\\(1\\)");
    if (str == null) {
        return false;
    }

    Pattern p = Pattern
            .compile("^\\s*IP\\s*address\\s*\\(1\\)\\s*([^\\(]+)\\s*\\(2\\)\\s*(.*)");
    {
        Matcher m = p.matcher(str);

        if (m.lookingAt()) {
            Pattern pAddr = Pattern
                    .compile("(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s*/\\s*(\\d+\\.\\d+\\.\\d+\\.\\d+)");
            for (int i = 1; i <= 2; i++) {
                Matcher mAddr = pAddr.matcher(m.group(i));

                if (mAddr.lookingAt()) {
                    defaultAddresses.add(new IpAddress(mAddr.group(1),
                            mAddr.group(2)));
                }
            }
        }
    }
    return true;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:35,代码来源:ShowIpAll.java

示例13: next

import java.util.regex.Matcher; //导入方法依赖的package包/类
public String next(String regexp) throws ParseException {
    trim();
    Pattern p = Pattern.compile(regexp);
    Matcher m = p.matcher(s);
    if(m.lookingAt()) {
        String r = m.group();
        s = s.substring(r.length());
        trim();
        return r;
    } else
        throw error();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:StringCutter.java

示例14: init

import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
 * Initialize derived fields from defining fields.
 * This is called from constructor and from readObject (de-serialization)
 *
 * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser
 */
private void init(Calendar definingCalendar) {

    final StringBuilder regex = new StringBuilder();
    final List<Strategy> collector = new ArrayList<Strategy>();

    final Matcher patternMatcher = formatPattern.matcher(pattern);
    if (!patternMatcher.lookingAt()) {
        throw new IllegalArgumentException(
                "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'");
    }

    currentFormatField = patternMatcher.group();
    Strategy currentStrategy = getStrategy(currentFormatField, definingCalendar);
    for (; ; ) {
        patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd());
        if (!patternMatcher.lookingAt()) {
            nextStrategy = null;
            break;
        }
        final String nextFormatField = patternMatcher.group();
        nextStrategy = getStrategy(nextFormatField, definingCalendar);
        if (currentStrategy.addRegex(this, regex)) {
            collector.add(currentStrategy);
        }
        currentFormatField = nextFormatField;
        currentStrategy = nextStrategy;
    }
    if (patternMatcher.regionStart() != patternMatcher.regionEnd()) {
        throw new IllegalArgumentException("Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
    }
    if (currentStrategy.addRegex(this, regex)) {
        collector.add(currentStrategy);
    }
    currentFormatField = null;
    strategies = collector.toArray(new Strategy[collector.size()]);
    parsePattern = Pattern.compile(regex.toString());
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:44,代码来源:FastDateParser.java

示例15: next

import java.util.regex.Matcher; //导入方法依赖的package包/类
/** {@inheritDoc} */
public int next() throws VersionFormatException {
  if (!hasNext()) throw new NoSuchElementException();

  int n;

  while (true) {
    switch (state) {
    case NUM:   // read a version number
      final Matcher m = Pattern.compile("^\\d+").matcher(v);
      if (!m.lookingAt()) throw new VersionFormatException();
      try {
        n = Integer.parseInt(m.group());
        if (n < 0) throw new VersionFormatException();
      }
      catch (NumberFormatException e) {
        throw new VersionFormatException(e);
      }
      v = v.substring(m.end());
      state = v.length() == 0 ? State.EOS : State.DELIM;
      return n;
    case DELIM: // eat delimiters
      switch (v.charAt(0)) {
      case '.':
        state = State.NUM;
        v = v.substring(1);
        break;
      default:
        throw new VersionFormatException();
      }
      break;
    case EOS: // mark the end of the string
      state = State.END;
      return -1;
    case END: // this case is terminal
      throw new IllegalStateException();
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:40,代码来源:SimpleVersionTokenizer.java


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