Package java.util.regex

Examples of java.util.regex.MatchResult


      Pattern pattern = fmt.regexPattern;
      Matcher matcher = pattern.matcher(eventStr);
      if (! matcher.matches()) {
        continue;
      }
      MatchResult res = matcher.toMatchResult();
      for (int grp=1; grp <= res.groupCount(); grp++) {
        String value = res.group(grp);
        if (grp == SYSLOG_TIMESTAMP_POS) {
          timeStampString = value;

          // apply available format replacements to timestamp
          if (value != null) {
View Full Code Here


    if (o2.global) {
     
      ESeq result = ERT.NIL;
     
      while (matcher.find()) {
        MatchResult mr = matcher.toMatchResult();
     
        ESeq list;
        if (o2.capture_spec == am_all) {
          ESeq l = ERT.NIL;
          for (int i = mr.groupCount(); i >= 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
         
          result = result.cons(l);
        } else if ((list = o2.capture_spec.testSeq()) != null) {
          ESeq l = ERT.NIL;
          while (!list.isNil()) {
            EObject group = list.head();
            ESmall num;
            EAtom nam;
            EString nam2;
            if ((num=group.testSmall()) != null)
            {
              l = l.cons( capture (subject, mr, num.value, o2 ));
            } else if ((nam=group.testAtom()) != null) {
              Integer groupNo = o2.named_groups.get(nam.getName());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else if ((nam2=group.testString()) != null) {
              Integer groupNo = o2.named_groups.get(nam2.stringValue());
              if (groupNo != null) {
                l = l.cons( capture (subject, mr, groupNo.intValue(), o2 ));
              }
            } else {
              throw new NotImplemented("named capture groups");
            }
            list = list.tail();
          }
          result = result.cons(l);

        } else {
          throw new NotImplemented("global and not all");
        }
      }
     
      if (result == ERT.NIL) {
        return am_nomatch;
      } else {
         return new ETuple2(am_match, result.reverse());
      }
     
    } else {
     
      if (matcher.find()) {
       
        if (o2.capture_spec  == am_none) {
          return am_match;
        }
       
        MatchResult mr = matcher.toMatchResult();
     
        int max = mr.groupCount();
        while( mr.start(max) == -1)
          max -= 1;
       
        ESeq il;
        if (o2.capture_spec == am_all) {
          ESeq l = ERT.NIL;
          for (int i = max; i >= 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
          return new ETuple2(am_match, l);
         
        } else if (o2.capture_spec == am_all_but_first) {
          ESeq l = ERT.NIL;
          for (int i = max; i > 0; i--) {
            l = l.cons( capture (subject, mr, i, o2) );
          }
          return new ETuple2(am_match, l);
         
        } else if (o2.capture_spec == am_first) {
          EObject l = capture (subject, mr, 0, o2);
          return new ETuple2(am_match, l);
         
        } else if ((il = o2.capture_spec.testSeq()) != null) {
         
          ESeq out = ERT.NIL;
         
           for (; !il.isNil(); il = il.tail()) {
             EObject what = il.head();
            ESmall idx = what.testSmall();
             EAtom nam;
            if (idx != null && mr.start(idx.value) != -1) {
               EObject val = capture (subject, mr, idx.value, o2);
               out = out.cons(val);
             } else if ((nam=what.testAtom())!=null) {
               Integer idx2 = o2.named_groups.get(nam.getName());
               if (idx2 != null) {
View Full Code Here

        }

        void parseMacKeyHeaderLine(String line, KatResult kr) {
            Scanner ls = new Scanner(line);
            ls.findInLine(".*=\\s*(\\d+) .*");
            MatchResult result = null;
            try {
                result = ls.match();
            } catch (Exception e) {
                System.out.println("Mac header: " + line);
                e.printStackTrace();
                System.exit(1);
            }
            kr.macKeyLen = Integer.parseInt(result.group(1));
            kr.macKey = new byte[kr.macKeyLen];
            state = MacKey;
        }
View Full Code Here

        void parseHeaderLine(String line, KatResult kr) {
            Scanner lineScanner = new Scanner(line);
            lineScanner
                    .findInLine(":Skein-(\\d+):\\s*(\\d+)-.*=\\s*(\\d+) bits(.*)");
            MatchResult result = null;
            try {
                result = lineScanner.match();
            } catch (Exception e) {
                System.out.println("Header line: " + line);
                e.printStackTrace();
                System.exit(1);
            }

            kr.stateSize = Integer.parseInt(result.group(1));
            kr.hashBitLength = Integer.parseInt(result.group(2));
            kr.msgLength = Integer.parseInt(result.group(3));
            kr.restOfLine = result.group(4);

            if ((kr.msgLength == 0) || (kr.msgLength % 8) != 0)
                kr.msg = new byte[(kr.msgLength >> 3) + 1];
            else
                kr.msg = new byte[kr.msgLength >> 3];
View Full Code Here

            // Split into "proxyAddr:proxyPort".
            proxyAddr = null;
            int proxyPort = 8080;
            try {
                s.findInLine("(http://|)([^:/]+)(:|)([0-9]*)(/|)");
                MatchResult m = s.match();
                if (m.groupCount() >= 2) {
                    proxyAddr = m.group(2);
                }
                if ((m.groupCount() >= 4) && (!m.group(4).isEmpty())) {
                    proxyPort = Integer.parseInt(m.group(4));
                }
            } finally {
                s.close();
            }
            if (proxyAddr != null) {
View Full Code Here

            String next = scanner.findWithinHorizon(tagTokenPattern, 0);
            if (next == null) {
                return null;
            }
            if (first && wrapToken) {
                MatchResult mres = scanner.match();
                wrapHead = ((RecordableInputStream)in).getText(mres.start());
                wrapTail = buildXMLTail(wrapHead);
            }

            // build answer accordingly to whether namespaces should be inherited or not
            if (inheritNamespaceToken != null && rootTokenNamespaces != null) {
View Full Code Here

  }

  // Apply each known pattern to message
  private void formatHeaders() {
    Scanner scanner = new Scanner(baos.toString());
    MatchResult res = null;

    for(int p=0; p < formats.size(); p++) {
      SyslogFormater fmt = formats.get(p);
      try {
        scanner.findInLine(fmt.regexPattern);
        res = scanner.match();
      } catch (IllegalStateException e) {
        // Ignore and move on ..
        continue;
      }
      for (int grp=1; grp <= res.groupCount(); grp++) {
        String value = res.group(grp);
        if (grp == SYSLOG_TIMESTAMP_POS) {
          // apply available format replacements to timestamp
          if (value != null) {
            for (int sp=0; sp < fmt.searchPattern.size(); sp++) {
              value = value.replaceAll(fmt.searchPattern.get(sp), fmt.replacePattern.get(sp));
View Full Code Here

      new HtmlWriter(writer, prefix);
    page.render(htmlWriter, request);
    Pattern pathFinder = Pattern.compile("(href|src)=\"([^\"]*)\"");
    Matcher matcher = pathFinder.matcher(writer.toString());
    while (matcher.find()) {
      MatchResult result = matcher.toMatchResult();
      String[] components = result.group(2).trim().split("/");
      ConsolePageTest.assertEquals("Missing initial /","", components[0]);
      ConsolePageTest.assertEquals(jstd, components[1]);
      ConsolePageTest.assertFalse("Second component should not be the prefix.",
        jstd.equals(components[2]));
    }
View Full Code Here

            initialState = State.valueOf(String.valueOf(options.get(OPTION_START_STATE)));
        }
        state.push(initialState);

        while (source.hasMore()) {
            MatchResult m = null;

            if ((m = source.scan(SPACE)) != null) {
                encoder.textToken(m.group(), TokenType.space);
            }
            else if (media_blocks(source, encoder, value_expected, state)) {

            }
            else if ((m = source.scan(COMMENT)) != null) {
                encoder.textToken(m.group(), TokenType.comment);
            }
            else if ((m = source.scan(BRACKET_OPEN)) != null) {
                value_expected = false;
                encoder.textToken(m.group(), TokenType.operator);
                state.push(State.block);
            }
            else if ((m = source.scan(BRACKET_CLOSE)) != null) {
                value_expected = false;
                encoder.textToken(m.group(), TokenType.operator);
                if (state.peek() == State.block || state.peek() == State.media) {
                    state.pop();
                }
            }
            else if ((m = source.scan(STRING)) != null) {
                encoder.beginGroup(TokenType.string);
                encoder.textToken(m.group().substring(0, 1), TokenType.delimiter);
                if (m.group().length() > 2) {
                    encoder.textToken(m.group().substring(1, m.group().length() - 1), TokenType.content);
                }
                if (m.group().length() >= 2) {
                    encoder.textToken(m.group().substring(m.group().length() - 1), TokenType.delimiter);
                }
                encoder.endGroup(TokenType.string);
            }
            else if ((m = source.scan(FUNCTION)) != null) {
                encoder.beginGroup(TokenType.function);
                Matcher functionMatcher = FUNCTION_NAME.matcher(m.group());
                functionMatcher.lookingAt();
                String start = functionMatcher.group();
                encoder.textToken(start, TokenType.delimiter);
                if (PARENTHESES_END.matcher(m.group().substring(m.group().length() - 1)).matches()) {
                    if (m.group().length() > start.length() + 1) {
                        encoder.textToken(m.group().substring(start.length(), m.group().length() - 1), TokenType.content);
                        encoder.textToken(")", TokenType.delimiter);
                    }
                }
                else if (m.group().length() > start.length()) {
                    encoder.textToken(m.group().substring(start.length(), m.group().length() - 1), TokenType.content);
                }
                encoder.endGroup(TokenType.function);
            }
            else if ((m = source.scan(FLOAT)) != null) {
                encoder.textToken(m.group(), TokenType.float_);
            }
            else if ((m = source.scan(HEX_COLOR)) != null) {
                encoder.textToken(m.group(), TokenType.color);
            }
            else if ((m = source.scan(IMPORTANT)) != null) {
                encoder.textToken(m.group(), TokenType.important);
            }
            else if ((m = source.scan(COLOR)) != null) {
                encoder.textToken(m.group(), TokenType.color);
            }
            else if ((m = source.scan(AT_KEYWORD)) != null) {
                encoder.textToken(m.group(), TokenType.directive);
            }
            else if ((m = source.scan(OPERATOR)) != null) {
                if (":".equals(m.group())) {
                    value_expected = true;
                }
                else if (";".equals(m.group())) {
                    value_expected = false;
                }
                encoder.textToken(m.group(), TokenType.operator);
            }
            else {
                encoder.textToken(source.next(), TokenType.error);
            }
        }
View Full Code Here

            }
        }
    }

    private boolean media_blocks(StringScanner source, Encoder encoder, boolean value_expected, Stack<State> state) {
        MatchResult m;
        switch (state.peek()) {

            case initial:
            case media:
                if ((m = source.scan(TAG)) != null) {
                    encoder.textToken(m.group(), TokenType.tag);
                    return true;
                }
                else if ((m = source.scan(Class)) != null) {
                    encoder.textToken(m.group(), TokenType.class_);
                    return true;
                }
                else if ((m = source.scan(ID)) != null) {
                    encoder.textToken(m.group(), TokenType.id);
                    return true;
                }
                else if ((m = source.scan(PSEUDO_CLASS)) != null) {
                    encoder.textToken(m.group(), TokenType.pseudo_class);
                    return true;
                }
                else if ((m = source.scan(ATTRIBUTE_SELECTOR)) != null) {
                    encoder.textToken(m.group().substring(0, 1), TokenType.operator);
                    if (m.group().length() > 2) {
                        encoder.textToken(m.group().substring(1, m.group().length() - 1), TokenType.attribute_name);
                    }
                    if (SQUARE_END.matcher(m.group().substring(m.group().length() - 1)).matches()) {
                        encoder.textToken(m.group().substring(m.group().length() - 1), TokenType.operator);
                    }
                    return true;
                }
                else if ((m = source.scan(MEDIA)) != null) {
                    encoder.textToken(m.group(), TokenType.directive);
                    state.push(State.media_before_name);
                    return true;
                }
                break;

            case block:
                if ((m = source.scan(KEY_VALUE)) != null) {
                    if (value_expected) {
                        encoder.textToken(m.group(), TokenType.value);
                    }
                    else {
                        encoder.textToken(m.group(), TokenType.key);
                    }
                    return true;
                }
                break;

            case media_before_name:
                if ((m = source.scan(IDENT)) != null) {
                    encoder.textToken(m.group(), TokenType.type);
                    state.pop();
                    state.push(State.media_after_name);
                    return true;
                }
                break;

            case media_after_name:
                if ((m = source.scan(BRACKET_OPEN)) != null) {
                    encoder.textToken(m.group(), TokenType.operator);
                    state.pop();
                    state.push(State.media);
                    return true;
                }
                break;
View Full Code Here

TOP

Related Classes of java.util.regex.MatchResult

Copyright © 2018 www.massapicom. 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.