Package java.util.regex

Examples of java.util.regex.MatchResult.groupCount()


        && !scanner.hasNext("--" + boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
      if (scanner.hasNext(REG_EX_HEADER)) {
        scanner.next(REG_EX_HEADER);
        currentLineNumber++;
        MatchResult result = scanner.match();
        if (result.groupCount() == 2) {
          String headerName = result.group(1).trim().toLowerCase(Locale.ENGLISH);
          String headerValue = result.group(2).trim();
          if (HttpHeaders.ACCEPT.equalsIgnoreCase(headerName)) {
            List<String> acceptHeaders = parseAcceptHeaders(headerValue);
            headers.put(headerName, acceptHeaders);
View Full Code Here


      if (uriObject.isAbsolute()) {
        Pattern regexRequestUri = Pattern.compile(baseUri + "/([^/][^?]*)(\\?.*)?");
        if (uriScanner.hasNext(regexRequestUri)) {
          uriScanner.next(regexRequestUri);
          MatchResult result = uriScanner.match();
          if (result.groupCount() == 2) {
            odataPathSegmentsAsString = result.group(1);
            queryParametersAsString = result.group(2) != null ? result.group(2) : "";
          } else {
            uriScanner.close();
            throw new BatchException(BatchException.INVALID_URI.addContent(currentLineNumber));
View Full Code Here

      } else {
        Pattern regexRequestUri = Pattern.compile("([^/][^?]*)(\\?.*)?");
        if (uriScanner.hasNext(regexRequestUri)) {
          uriScanner.next(regexRequestUri);
          MatchResult result = uriScanner.match();
          if (result.groupCount() == 2) {
            odataPathSegmentsAsString = result.group(1);
            queryParametersAsString = result.group(2) != null ? result.group(2) : "";
          } else {
            uriScanner.close();
            throw new BatchException(BatchException.INVALID_URI.addContent(currentLineNumber));
View Full Code Here

    Map<String, String> queryParametersMap = new HashMap<String, String>();
    Pattern regex = Pattern.compile("(?:" + baseUri + "/)?" + "[^?]+" + "\\?(.*)");
    if (uriScanner.hasNext(regex)) {
      uriScanner.next(regex);
      MatchResult uriResult = uriScanner.match();
      if (uriResult.groupCount() == 1) {
        String queryParams = uriResult.group(1);
        Scanner queryParamsScanner = new Scanner(queryParams);
        queryParamsScanner.useDelimiter("&");
        while (queryParamsScanner.hasNext(REG_EX_QUERY_PARAMETER)) {
          queryParamsScanner.next(REG_EX_QUERY_PARAMETER);
View Full Code Here

        Scanner queryParamsScanner = new Scanner(queryParams);
        queryParamsScanner.useDelimiter("&");
        while (queryParamsScanner.hasNext(REG_EX_QUERY_PARAMETER)) {
          queryParamsScanner.next(REG_EX_QUERY_PARAMETER);
          MatchResult result = queryParamsScanner.match();
          if (result.groupCount() == 2) {
            String systemQueryOption = result.group(1);
            String value = result.group(2);
            queryParametersMap.put(systemQueryOption, Decoder.decode(value));
          } else {
            queryParamsScanner.close();
View Full Code Here

    }
    if (contentTypeScanner.hasNext(REG_EX_BOUNDARY_PARAMETER)) {
      contentTypeScanner.next(REG_EX_BOUNDARY_PARAMETER);
      MatchResult result = contentTypeScanner.match();
      contentTypeScanner.close();
      if (result.groupCount() == 1 && result.group(1).trim().matches(REG_EX_BOUNDARY)) {
        return trimQuota(result.group(1).trim());
      } else {
        throw new BatchException(BatchException.INVALID_BOUNDARY);
      }
    } else {
View Full Code Here

    while (scanner.hasNext() && !(scanner.hasNext(REG_EX_BLANK_LINE))) {
      if (scanner.hasNext(REG_EX_HEADER)) {
        scanner.next(REG_EX_HEADER);
        currentLineNumber++;
        MatchResult result = scanner.match();
        if (result.groupCount() == 2) {
          String headerName = result.group(1).trim().toLowerCase(Locale.ENGLISH);
          String headerValue = result.group(2).trim();
          headers.put(headerName, headerValue);
        }
      } else {
View Full Code Here

    // Scanner s2 = new Scanner(input);
    Scanner s2 = new Scanner (input);
    s2.findInLine ("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
    MatchResult mResult = s2.match ();
    for (i = 1; i <= mResult.groupCount (); i++)
      {
  this.myHarness.check (mResult.group (i), values[i],
            "wrong result : \"" + mResult.group (i) +
            "\" != \"" + values[i] + "\"");
  // System.out.println(mResult.group(i));
View Full Code Here

        final MatchResult mr = matchResults.peek();
        if (mr == null) {
            return null;
        }

        String finalGroup = mr.group(mr.groupCount());
        // We have found a match but the right hand path pattern did not match anything
        // so just returning an empty string as a final matching group result.
        // Otherwise a non-empty patterns would fail to match the right-hand-path properly.
        // See also PatternWithGroups.match(CharSequence) implementation.
        return finalGroup == null ? "" : finalGroup;
View Full Code Here

        assertEquals(3, result.end());
        assertEquals(2, result.start(0));
        assertEquals(3, result.end(0));
        assertEquals("2", result.group());
        assertEquals("2", result.group(0));
        assertEquals(0, result.groupCount());
        try {
            result.start(1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // Expected
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.