當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。