當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.region方法代碼示例

本文整理匯總了Java中java.util.regex.Matcher.region方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.region方法的具體用法?Java Matcher.region怎麽用?Java Matcher.region使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Matcher的用法示例。


在下文中一共展示了Matcher.region方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: params

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Map<String, String> params() throws IOException {
    final Matcher match = this.matcher();
    final Matcher param = MimeTypeOf.PTN_PARAM.matcher(this.src);
    final Map<String, String> map = new HashMap<>(1);
    for (int id = match.end(); id < this.src.length(); id = param.end()) {
        param.region(id, this.src.length());
        if (!param.lookingAt()) {
            throw new IOException("Invalid mime-type params format");
        }
        final String name = param.group(1);
        if (map.containsKey(name)) {
            throw new IOException(
                String.format("Parameter %s may only exist once.", name)
            );
        }
        map.put(name, MimeTypeOf.paramValue(param));
    }
    return map;
}
 
開發者ID:g4s8,項目名稱:mime,代碼行數:22,代碼來源:MimeTypeOf.java

示例2: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns a media type for {@code string}, or null if {@code string} is not a
 * well-formed media type.
 */
public static MediaType parse(String string) {
  Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
  if (!typeSubtype.lookingAt()) return null;
  String type = typeSubtype.group(1).toLowerCase(Locale.US);
  String subtype = typeSubtype.group(2).toLowerCase(Locale.US);

  String charset = null;
  Matcher parameter = PARAMETER.matcher(string);
  for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
    parameter.region(s, string.length());
    if (!parameter.lookingAt()) return null; // This is not a well-formed media type.

    String name = parameter.group(1);
    if (name == null || !name.equalsIgnoreCase("charset")) continue;
    if (charset != null) throw new IllegalArgumentException("Multiple charsets: " + string);
    charset = parameter.group(2) != null
        ? parameter.group(2)  // Value is a token.
        : parameter.group(3); // Value is a quoted string.
  }

  return new MediaType(string, type, subtype, charset);
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:27,代碼來源:MediaType.java

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

示例4: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns a media type for {@code string}, or null if {@code string} is not a well-formed media
 * type.
 */
public static MediaType parse(String string) {
  Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
  if (!typeSubtype.lookingAt()) return null;
  String type = typeSubtype.group(1).toLowerCase(Locale.US);
  String subtype = typeSubtype.group(2).toLowerCase(Locale.US);

  String charset = null;
  Matcher parameter = PARAMETER.matcher(string);
  for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
    parameter.region(s, string.length());
    if (!parameter.lookingAt()) return null; // This is not a well-formed media type.

    String name = parameter.group(1);
    if (name == null || !name.equalsIgnoreCase("charset")) continue;
    String charsetParameter;
    String token = parameter.group(2);
    if (token != null) {
      // If the token is 'single-quoted' it's invalid! But we're lenient and strip the quotes.
      charsetParameter = (token.startsWith("'") && token.endsWith("'") && token.length() > 2)
          ? token.substring(1, token.length() - 1)
          : token;
    } else {
      // Value is "double-quoted". That's valid and our regex group already strips the quotes.
      charsetParameter = parameter.group(3);
    }
    if (charset != null && !charsetParameter.equalsIgnoreCase(charset)) {
      return null; // Multiple different charsets!
    }
    charset = charsetParameter;
  }

  return new MediaType(string, type, subtype, charset);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:MediaType.java

示例5: parseExpires

import java.util.regex.Matcher; //導入方法依賴的package包/類
/** Parse a date as specified in RFC 6265, section 5.1.1. */
private static long parseExpires(String s, int pos, int limit) {
  pos = dateCharacterOffset(s, pos, limit, false);

  int hour = -1;
  int minute = -1;
  int second = -1;
  int dayOfMonth = -1;
  int month = -1;
  int year = -1;
  Matcher matcher = TIME_PATTERN.matcher(s);

  while (pos < limit) {
    int end = dateCharacterOffset(s, pos + 1, limit, true);
    matcher.region(pos, end);

    if (hour == -1 && matcher.usePattern(TIME_PATTERN).matches()) {
      hour = Integer.parseInt(matcher.group(1));
      minute = Integer.parseInt(matcher.group(2));
      second = Integer.parseInt(matcher.group(3));
    } else if (dayOfMonth == -1 && matcher.usePattern(DAY_OF_MONTH_PATTERN).matches()) {
      dayOfMonth = Integer.parseInt(matcher.group(1));
    } else if (month == -1 && matcher.usePattern(MONTH_PATTERN).matches()) {
      String monthString = matcher.group(1).toLowerCase(Locale.US);
      month = MONTH_PATTERN.pattern().indexOf(monthString) / 4; // Sneaky! jan=1, dec=12.
    } else if (year == -1 && matcher.usePattern(YEAR_PATTERN).matches()) {
      year = Integer.parseInt(matcher.group(1));
    }

    pos = dateCharacterOffset(s, end + 1, limit, false);
  }

  // Convert two-digit years into four-digit years. 99 becomes 1999, 15 becomes 2015.
  if (year >= 70 && year <= 99) year += 1900;
  if (year >= 0 && year <= 69) year += 2000;

  // If any partial is omitted or out of range, return -1. The date is impossible. Note that leap
  // seconds are not supported by this syntax.
  if (year < 1601) throw new IllegalArgumentException();
  if (month == -1) throw new IllegalArgumentException();
  if (dayOfMonth < 1 || dayOfMonth > 31) throw new IllegalArgumentException();
  if (hour < 0 || hour > 23) throw new IllegalArgumentException();
  if (minute < 0 || minute > 59) throw new IllegalArgumentException();
  if (second < 0 || second > 59) throw new IllegalArgumentException();

  Calendar calendar = new GregorianCalendar(UTC);
  calendar.setLenient(false);
  calendar.set(Calendar.YEAR, year);
  calendar.set(Calendar.MONTH, month - 1);
  calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  calendar.set(Calendar.HOUR_OF_DAY, hour);
  calendar.set(Calendar.MINUTE, minute);
  calendar.set(Calendar.SECOND, second);
  calendar.set(Calendar.MILLISECOND, 0);
  return calendar.getTimeInMillis();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:57,代碼來源:Cookie.java

示例6: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns a media type for {@code string}, or null if {@code string} is not a well-formed media
 * type.
 */
public static @Nullable MediaType parse(String string) {
  Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
  if (!typeSubtype.lookingAt()) return null;
  String type = typeSubtype.group(1).toLowerCase(Locale.US);
  String subtype = typeSubtype.group(2).toLowerCase(Locale.US);

  String charset = null;
  Matcher parameter = PARAMETER.matcher(string);
  for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
    parameter.region(s, string.length());
    if (!parameter.lookingAt()) return null; // This is not a well-formed media type.

    String name = parameter.group(1);
    if (name == null || !name.equalsIgnoreCase("charset")) continue;
    String charsetParameter;
    String token = parameter.group(2);
    if (token != null) {
      // If the token is 'single-quoted' it's invalid! But we're lenient and strip the quotes.
      charsetParameter = (token.startsWith("'") && token.endsWith("'") && token.length() > 2)
          ? token.substring(1, token.length() - 1)
          : token;
    } else {
      // Value is "double-quoted". That's valid and our regex group already strips the quotes.
      charsetParameter = parameter.group(3);
    }
    if (charset != null && !charsetParameter.equalsIgnoreCase(charset)) {
      return null; // Multiple different charsets!
    }
    charset = charsetParameter;
  }

  return new MediaType(string, type, subtype, charset);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:MediaType.java

示例7: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns a media type for {@code string}, or null if {@code string} is not a well-formed media
 * type.
 */
public static MediaType parse(String string) {
    Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
    if (!typeSubtype.lookingAt()) return null;
    String type = typeSubtype.group(1).toLowerCase(Locale.US);
    String subtype = typeSubtype.group(2).toLowerCase(Locale.US);

    String charset = null;
    Matcher parameter = PARAMETER.matcher(string);
    for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
        parameter.region(s, string.length());
        if (!parameter.lookingAt()) return null; // This is not a well-formed media type.

        String name = parameter.group(1);
        if (name == null || !name.equalsIgnoreCase("charset")) continue;
        String charsetParameter;
        String token = parameter.group(2);
        if (token != null) {
            // If the token is 'single-quoted' it's invalid! But we're lenient and strip the quotes.
            charsetParameter = (token.startsWith("'") && token.endsWith("'") && token.length() > 2)
                    ? token.substring(1, token.length() - 1)
                    : token;
        } else {
            // Value is "double-quoted". That's valid and our regex group already strips the quotes.
            charsetParameter = parameter.group(3);
        }
        if (charset != null && !charsetParameter.equalsIgnoreCase(charset)) {
            return null; // Multiple different charsets!
        }
        charset = charsetParameter;
    }

    return new MediaType(string, type, subtype, charset);
}
 
開發者ID:TFdream,項目名稱:okurl,代碼行數:38,代碼來源:MediaType.java

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

示例9: shallowIndexOfPattern

import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
 * Returns index of the first case-insensitive match of search pattern that
 * is not enclosed in parenthesis.
 *
 * @param sb
 *            String to search.
 * @param pattern
 *            Compiled search pattern.
 * @param fromIndex
 *            The index from which to start the search.
 *
 * @return Position of the first match, or {@literal -1} if not found.
 */
private static int shallowIndexOfPattern(final StringBuilder sb, final Pattern pattern, int fromIndex) {
	int index = -1;
	final String matchString = sb.toString();

	// quick exit, save performance and avoid exceptions
	if (matchString.length() < fromIndex || fromIndex < 0) {
		return -1;
	}

	List<IgnoreRange> ignoreRangeList = generateIgnoreRanges(matchString);

	Matcher matcher = pattern.matcher(matchString);
	matcher.region(fromIndex, matchString.length());

	if (ignoreRangeList.isEmpty()) {
		// old behavior where the first match is used if no ignorable ranges
		// were deduced from the matchString.
		if (matcher.find() && matcher.groupCount() > 0) {
			index = matcher.start();
		}
	} else {
		// rather than taking the first match, we now iterate all matches
		// until we determine a match that isn't considered "ignorable'.
		while (matcher.find() && matcher.groupCount() > 0) {
			final int position = matcher.start();
			if (!isPositionIgnorable(ignoreRangeList, position)) {
				index = position;
				break;
			}
		}
	}
	return index;
}
 
開發者ID:drinkjava2,項目名稱:jDialects,代碼行數:47,代碼來源:SQLServer2005LimitHandler.java

示例10: 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 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:pooyafaroka,項目名稱:PlusGram,代碼行數:44,代碼來源:FastDateParser.java

示例11: HivePath

import java.util.regex.Matcher; //導入方法依賴的package包/類
public HivePath(final ObjectInspector oi, final String path) {
	this.oi = oi;
	this.accessors = new ArrayList<>();

	final Matcher m = STRUCT_ACCESS_PATTERN.matcher(path);

	while (m.usePattern(STRUCT_ACCESS_PATTERN).find()) {
		accessors.add(new StructAccessor(m.group("field")));
		m.region(m.end(), m.regionEnd());

		boolean match;
		do {
			match = false;
			if (m.usePattern(ARRAY_ACCESS_PATTERN).find()) {
				accessors.add(new ArrayAccessor(Integer.parseInt(m.group("index"))));
				m.region(m.end(), m.regionEnd());
				match = true;
			}
			if (m.usePattern(MAP_ACCESS_PATTERN).find()) {
				final String key;
				try {
					key = MAPPER.readValue(m.group("keyjson"), String.class);
				} catch (IOException e) {
					throw new IllegalArgumentException(e);
				}
				accessors.add(new MapAccessor(key));
				m.region(m.end(), m.regionEnd());
				match = true;
			}
		} while (match);
	}

	if (!m.hitEnd())
		throw new IllegalArgumentException("error at " + m.regionStart());
}
 
開發者ID:CyberAgent,項目名稱:hive-jq-udtf,代碼行數:36,代碼來源:HivePath.java

示例12: parse

import java.util.regex.Matcher; //導入方法依賴的package包/類
public static MediaType parse(String string) {
    Matcher typeSubtype = TYPE_SUBTYPE.matcher(string);
    if (!typeSubtype.lookingAt()) {
        return null;
    }
    String type = typeSubtype.group(1).toLowerCase(Locale.US);
    String subtype = typeSubtype.group(2).toLowerCase(Locale.US);
    String charset = null;
    Matcher parameter = PARAMETER.matcher(string);
    for (int s = typeSubtype.end(); s < string.length(); s = parameter.end()) {
        parameter.region(s, string.length());
        if (!parameter.lookingAt()) {
            return null;
        }
        String name = parameter.group(1);
        if (name != null && name.equalsIgnoreCase("charset")) {
            String charsetParameter;
            if (parameter.group(2) != null) {
                charsetParameter = parameter.group(2);
            } else {
                charsetParameter = parameter.group(3);
            }
            if (charset == null || charsetParameter.equalsIgnoreCase(charset)) {
                charset = charsetParameter;
            } else {
                throw new IllegalArgumentException("Multiple different charsets: " + string);
            }
        }
    }
    return new MediaType(string, type, subtype, charset);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:MediaType.java

示例13: match

import java.util.regex.Matcher; //導入方法依賴的package包/類
public String match(int index, Pattern pattern) {
    Matcher m = pattern.matcher(text);
    m = m.region(index, length);
    if (m.lookingAt()) {
        return m.group();
    } else {
        return null;
    }
}
 
開發者ID:i49,項目名稱:cascade,代碼行數:10,代碼來源:TextInput.java

示例14: matcher

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Nullable
private static Matcher matcher(String string) {
    if (string == null) {
        return null;
    }
    Matcher bytesMatcher = BYTES_PATTERN.matcher(string);
    if (bytesMatcher.find()) {
        Matcher rangeMatcher = RANGE_PATTERN.matcher(string);
        rangeMatcher.region(bytesMatcher.end(), string.length());
        return rangeMatcher;
    }
    return null;
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:14,代碼來源:HttpRange.java

示例15: next

import java.util.regex.Matcher; //導入方法依賴的package包/類
@Nullable
private static HttpRange next(Matcher matcher) {
    if (matcher.find()) {
        int from = StringUtils.parseInt(matcher.group(1), 0);
        int to = StringUtils.parseInt(matcher.group(2), 0);
        int length = StringUtils.parseInt(matcher.group(4), 0);
        matcher.region(matcher.end(), matcher.regionEnd());
        return new HttpRange(from, to, length);
    }
    return null;
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:12,代碼來源:HttpRange.java


注:本文中的java.util.regex.Matcher.region方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。