当前位置: 首页>>代码示例>>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;未经允许,请勿转载。