Пример #1
0
 public SymbolMatch makeMatch(ScanString input) {
   for (Matcher matcher : getWikiMatchers()) {
     Maybe<Integer> matchLength = matcher.makeMatch(input);
     if (!matchLength.isNothing()) return new SymbolMatch(this, input, matchLength.getValue());
   }
   return SymbolMatch.noMatch;
 }
Пример #2
0
 public void testInvalidGroup(String text, String regexp, int group) {
   Pattern p = Pattern.compile(regexp, options);
   Matcher m = p.matcher(utf8Slice(text));
   m.find();
   m.group(group);
   fail(); // supposed to have exception by now
 }
 public static <T> void assertMismatchDescription(
     String expected, Matcher<? super T> matcher, T arg) {
   assertFalse("Precondtion: Matcher should not match item.", matcher.matches(arg));
   Description description = new StringDescription();
   matcher.describeMismatch(arg, description);
   assertEquals("Expected mismatch description", expected, description.toString().trim());
 }
Пример #4
0
  private int find() {
    int ret = -1;
    try {
      ret = matcher.find();
      if (ret < 0) return ret;
      Submatched[][] groups = matcher.getMatched();
      int index = 0;
      for (int i = 0; i < groups.length; ++i) {
        Submatched[] m = groups[i];
        System.out.println(
            "[GROUP" + index + "]--------------------------------------------------");
        ++index;
        for (int j = 0; j < m.length; ++j) {
          System.out.print('[');
          System.out.print(m[j].toString());
          System.out.print(']');
        }
        System.out.print("\n");
      }
    } catch (EOFException ex) {
      System.out.println("not matched");
      // this.assertTrue(false);
    } catch (IOException ex) {
      ex.printStackTrace();
      this.assertTrue(false);
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }

    return ret;
  }
Пример #5
0
  private static List<ParameterTypes> findCallable(
      ParameterTypes[] callables, IRubyObject... args) {
    List<ParameterTypes> retainedCallables = new ArrayList<ParameterTypes>(callables.length);
    List<ParameterTypes> incomingCallables =
        new ArrayList<ParameterTypes>(Arrays.asList(callables));

    for (int currentArg = 0; currentArg < args.length; currentArg++) {
      retainedCallables.clear();
      for (Matcher matcher : MATCH_SEQUENCE) {
        for (Iterator<ParameterTypes> callableIter = incomingCallables.iterator();
            callableIter.hasNext(); ) {
          ParameterTypes callable = callableIter.next();
          Class[] types = callable.getParameterTypes();

          if (matcher.match(types[currentArg], args[currentArg])) {
            callableIter.remove();
            retainedCallables.add(callable);
          }
        }
      }
      incomingCallables.clear();
      incomingCallables.addAll(retainedCallables);
    }

    return retainedCallables;
  }
Пример #6
0
 public void setUp() throws Exception {
   context = new ContextBase();
   matcher = new Matcher();
   matcher.setContext(context);
   matcher.setName("testMatcher");
   super.setUp();
 }
Пример #7
0
 public void test19() throws IOException {
   this.init("abcabcabcabc;", "(abc)+;");
   this.find();
   Submatched[][] groups = matcher.getMatched();
   assertEquals(groups.length, 2);
   assertEquals(groups[0][0].toString(), "abcabcabcabc;");
   assertEquals(groups[1].length, 4);
   for (int i = 0; i < 4; ++i) {
     assertEquals(groups[1][i].toString(), "abc");
   }
   //////////////////////////////////////////////////////
   this.init("abcabcabcabc", "(abc)+");
   this.find();
   groups = matcher.getMatched();
   assertEquals(groups.length, 2);
   assertEquals(groups[0][0].toString(), "abcabcabcabc");
   assertEquals(groups[1].length, 4);
   for (int i = 0; i < 4; ++i) {
     assertEquals(groups[1][i].toString(), "abc");
   }
   //////////////////////////////////////////////////////
   this.init("abcabc;", "(abc)+");
   this.find();
   groups = matcher.getMatched();
   assertEquals(groups.length, 2);
   assertEquals(groups[0][0].toString(), "abcabc");
   assertEquals(groups[1].length, 2);
   for (int i = 0; i < 2; ++i) {
     assertEquals(groups[1][i].toString(), "abc");
   }
 }
Пример #8
0
  public void test_base5() throws PatternCompiler_E, IOException { // ^$
    init("########\n abcd1234\nefgh1234\n########\n", "(^\\w+$)\\s+");
    find();
    Submatched[][] groups = matcher.getMatched();
    assertEquals(groups.length, 2);
    assertEquals(groups[0][0].toString(), "efgh1234\n");
    assertEquals(groups[0].length, 1);
    assertEquals(groups[1][0].toString(), "efgh1234");

    init("########\n abcd1234\nefgh1234 ########\n", "(^\\w+)\\s+");
    find();
    groups = matcher.getMatched();
    assertEquals(groups.length, 2);
    assertEquals(groups[0][0].toString(), "efgh1234 ");
    assertEquals(groups[0].length, 1);
    assertEquals(groups[1][0].toString(), "efgh1234");

    init("########\n abcd1234\nefgh1234\n########\n", "^(\\w+$)\\s+");
    find();
    groups = matcher.getMatched();
    assertEquals(groups.length, 2);
    assertEquals(groups[0][0].toString(), "efgh1234\n");
    assertEquals(groups[0].length, 1);
    assertEquals(groups[1][0].toString(), "efgh1234");
  }
Пример #9
0
 public void match(
     final String expression, final Handler<Triple> handler, final TweetContext context)
     throws MatcherException {
   for (Matcher m : componentMatchers) {
     m.match(expression, handler, context);
   }
 }
Пример #10
0
  public void testGroup(String text, String regexp, String[] output) {
    // RE2
    Pattern p = Pattern.compile(regexp, options);
    Matcher matchString = p.matcher(utf8Slice(text));
    assertEquals(true, matchString.find());
    assertEquals(utf8Slice(output[0]), matchString.group());
    for (int i = 0; i < output.length; i++) {
      assertEquals(output[i] == null ? null : utf8Slice(output[i]), matchString.group(i));
    }
    assertEquals(output.length - 1, matchString.groupCount());

    // JDK
    java.util.regex.Pattern pj = java.util.regex.Pattern.compile(regexp);
    java.util.regex.Matcher matchStringj = pj.matcher(text);
    // java.util.regex.Matcher matchBytes =
    //   p.matcher(text.getBytes(Charsets.UTF_8));
    assertEquals(true, matchStringj.find());
    // assertEquals(true, matchBytes.find());
    assertEquals(output[0], matchStringj.group());
    // assertEquals(output[0], matchBytes.group());
    for (int i = 0; i < output.length; i++) {
      assertEquals(output[i], matchStringj.group(i));
      // assertEquals(output[i], matchBytes.group(i));
    }
  }
Пример #11
0
  private static boolean assignableAndPrimitivableWithVarargs(
      ParameterTypes paramTypes, IRubyObject... args) {
    // bail out if this is not a varargs method
    if (!paramTypes.isVarArgs()) return false;

    Class[] types = paramTypes.getParameterTypes();

    Class varArgArrayType = types[types.length - 1];
    Class varArgType = varArgArrayType.getComponentType();

    // if there's no args, we only match when there's just varargs
    if (args.length == 0) {
      return types.length <= 1;
    }

    // dig out as many trailing args as will fit, ensuring they match varargs type
    int nonVarargs = types.length - 1;
    for (int i = args.length - 1; i >= nonVarargs; i--) {
      if (!(ASSIGNABLE.match(varArgType, args[i]) || PRIMITIVABLE.match(varArgType, args[i]))) {
        return false;
      }
    }

    // check remaining args
    for (int i = 0; i < nonVarargs; i++) {
      if (!(ASSIGNABLE.match(types[i], args[i]) || PRIMITIVABLE.match(types[i], args[i]))) {
        return false;
      }
    }
    return true;
  }
Пример #12
0
 @Override
 public boolean hasCustomJavaCode() {
   if (super.hasCustomJavaCode()) return true;
   for (Matcher operand : operands) {
     if (operand.hasCustomJavaCode()) return true;
   }
   return false;
 }
 @Override
 public void describeTo(Description description) {
   description.appendText("a Complex number having ");
   reMatcher.describeTo(description);
   description.appendText(" as real part and ");
   imMatcher.describeTo(description);
   description.appendText(" as imaginary part");
 }
Пример #14
0
 private boolean nothingMatch(ParsingState parsingState) {
   for (Matcher matcher : super.children) {
     if (matcher.isMatching(parsingState)) {
       return false;
     }
   }
   return true;
 }
Пример #15
0
 public void testPartRegion() throws Exception {
   matcher.setRegex("test");
   matcher.start();
   assertTrue(matcher.matches("test"));
   assertTrue(matcher.matches("xxxxtest"));
   assertTrue(matcher.matches("testxxxx"));
   assertTrue(matcher.matches("xxxxtestxxxx"));
 }
Пример #16
0
 public void test54() throws PatternCompiler_E, IOException {
   String reg = "^\\w+\n(\\s+.*\n)*\\s+student\n(\\s+(\\d+)\n){3}";
   init(
       "\nPoint\n   66\n   32\nAlbert\n  ...\n  ¶àÐеļò½é,±ÈÈçÌس¤¡¢Ï²ºÃµÈ\n  ...\n   student\n   173\n   16\n   62\n",
       reg);
   matcher.clear();
   matcher.add(reg, false);
   assertEquals(0, find());
 }
Пример #17
0
 @Override
 protected String __javaCode(String variable) {
   StringBuilder buff = new StringBuilder();
   for (Matcher operand : operands) {
     if (buff.length() > 0) buff.append(" || ");
     buff.append('(').append(operand._javaCode(variable)).append(')');
   }
   return buff.toString();
 }
Пример #18
0
  @Override
  public boolean matches(Player p) {
    for (Matcher matcher : matchers) {
      if (matcher.matches(p)) {
        return true;
      }
    }

    return false;
  }
Пример #19
0
 @Override
 public String toString() {
   StringBuilder buff = new StringBuilder();
   for (Matcher operand : operands) {
     String msg = operand._toString();
     if (buff.length() == 0 || !msg.startsWith("[^")) msg = msg.substring(1, msg.length() - 1);
     buff.append(msg);
   }
   return '[' + buff.toString() + ']';
 }
Пример #20
0
  public void testCaseSensitive() throws Exception {
    matcher.setRegex("test");
    matcher.setCaseSensitive(true);
    matcher.start();

    assertFalse(matcher.matches("TEST"));
    assertFalse(matcher.matches("tEst"));
    assertFalse(matcher.matches("tESt"));
    assertFalse(matcher.matches("TesT"));
  }
Пример #21
0
	void search() {
		int i=0;
		Matcher matcher=new Matcher(a,b);
		while (i<a.length-1) {
			int j=i;
			matcher.findBiggestMatchForFrom(i,j);
			
			findbiggestmatchfrom(i,j,0);

		}
	}
Пример #22
0
  @Test
  public void testIllegalFilterSyntax() {
    String configuratorKey = Matcher.createTargetKey(ApplicationConfiguration.class);
    when(httpServiceReference.getProperty(configuratorKey)).thenReturn("(((");

    try {
      matcher.matches();
      fail();
    } catch (IllegalArgumentException expected) {
    }
  }
Пример #23
0
  // Tests that both RE2 and JDK's Matchers do the same replaceFist.
  public void testReplaceFirst(String orig, String regex, String repl, String actual) {
    Pattern p = Pattern.compile(regex, options);
    Matcher m = p.matcher(utf8Slice(orig));
    String replaced = m.replaceFirst(utf8Slice(repl)).toStringUtf8();
    assertEquals(actual, replaced);

    // JDK's
    java.util.regex.Pattern pj = java.util.regex.Pattern.compile(regex);
    java.util.regex.Matcher mj = pj.matcher(orig);
    replaced = mj.replaceFirst(repl);
    assertEquals(actual, replaced);
  }
Пример #24
0
  private static boolean assignableOrDuckable(ParameterTypes paramTypes, IRubyObject... args) {
    Class[] types = paramTypes.getParameterTypes();

    if (args.length != types.length) return false;

    for (int i = 0; i < types.length; i++) {
      if (!(ASSIGNABLE.match(types[i], args[i]) || DUCKABLE.match(types[i], args[i]))) {
        return false;
      }
    }
    return true;
  }
Пример #25
0
  public void testFindNoMatch(String text, String regexp, int start) {
    // RE2
    Pattern p = Pattern.compile(regexp, options);
    Matcher matchString = p.matcher(utf8Slice(text));
    // RE2Matcher matchBytes = p.matcher(text.getBytes(Charsets.UTF_8));
    assertFalse(matchString.find(start));
    // assertFalse(matchBytes.find(start));

    // JDK
    java.util.regex.Pattern pj = java.util.regex.Pattern.compile(regexp);
    java.util.regex.Matcher matchStringj = pj.matcher(text);
    assertFalse(matchStringj.find(start));
  }
Пример #26
0
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.network.Endpoint#stop()
  */
 @Override
 public synchronized void stop() {
   if (!started) {
     LOGGER.log(Level.INFO, "Endpoint at " + getAddress() + " is already stopped");
   } else {
     LOGGER.log(Level.INFO, "Stopping endpoint at address " + getAddress());
     started = false;
     connector.stop();
     matcher.stop();
     for (EndpointObserver obs : observers) obs.stopped(this);
     matcher.clear();
   }
 }
 @Override
 public StorageResults fetch(Expression userQuery) {
   Expression expression = userQuery.normalize();
   Matcher matcher = expression.accept(new MatcherCreator());
   List<DataRecord> matchRecords = new LinkedList<DataRecord>();
   for (DataRecord dataRecord : storage) {
     if (matcher.match(dataRecord)) {
       matchRecords.add(dataRecord);
     }
   }
   List<DataRecord> filteredRecords = expression.accept(new Filter(matchRecords));
   return new InMemoryStorageResults(filteredRecords);
 }
Пример #28
0
  // Tests that both RE2 and JDK's Patterns/Matchers give the same groupCount.
  public void testGroupCount(String pattern, int count) {
    // RE2
    Pattern p = Pattern.compile(pattern, options);
    Matcher m = p.matcher(utf8Slice("x"));
    assertEquals(count, p.groupCount());
    assertEquals(count, m.groupCount());

    // JDK
    java.util.regex.Pattern pj = java.util.regex.Pattern.compile(pattern);
    java.util.regex.Matcher mj = pj.matcher("x");
    // java.util.regex.Pattern doesn't have group count in JDK.
    assertEquals(count, mj.groupCount());
  }
Пример #29
0
  private List<PsiElement> _process(final Matcher matcher, final boolean resolve) {
    final XmlTag root = matcher.getRoot();
    if (root == null || myHistory.contains(root)) {
      return Collections.emptyList();
    }
    myHistory.add(root);
    final List<PsiElement> found = new ArrayList<PsiElement>();

    try {
      if (matcher.isRecursive()) {
        root.accept(
            new XmlRecursiveElementVisitor() {
              @Override
              public void visitXmlTag(XmlTag tag) {
                final Matcher.Result match = matcher.match(tag);
                if (match != null) {
                  if (match.chain != null) {
                    found.addAll(_process(match.chain, resolve));
                  } else {
                    assert match.result != null;
                    found.add(match.result);
                    if (resolve) throw Stop.DONE;
                  }
                }
                super.visitXmlTag(tag);
              }
            });
      } else {
        root.acceptChildren(
            new XmlElementVisitor() {

              @Override
              public void visitXmlTag(XmlTag tag) {
                final Matcher.Result match = matcher.match(tag);
                if (match != null) {
                  if (match.chain != null) {
                    found.addAll(_process(match.chain, resolve));
                  } else {
                    assert match.result != null;
                    found.add(match.result);
                    if (resolve) throw Stop.DONE;
                  }
                }
              }
            });
      }
    } catch (Stop e) {
      /* processing stopped */
    }
    return found;
  }
Пример #30
0
  public void testFind(String text, String regexp, int start, String output) {
    // RE2
    Pattern p = Pattern.compile(regexp, options);
    Matcher matchString = p.matcher(utf8Slice(text));
    assertTrue(matchString.find(start));
    assertEquals(utf8Slice(output), matchString.group());
    assertTrue(p.find(utf8Slice(text)));

    // JDK
    java.util.regex.Pattern pj = java.util.regex.Pattern.compile(regexp);
    java.util.regex.Matcher matchStringj = pj.matcher(text);
    assertTrue(matchStringj.find(start));
    assertEquals(output, matchStringj.group());
  }