private String parseDatakey(String dataKey) {
   String result = dataKey;
   RegExp regex = RegExp.compile("([^\\\\/:*?\"<>|\r\n]+$)");
   MatchResult matcher = regex.exec(dataKey);
   if (regex.test(dataKey)) {
     result = matcher.getGroup(1);
   }
   return result;
 }
 /** Simple smoke test for regular expression. */
 public void testSmoke() {
   RegExp r = new RegExp("a(b+|c+)d");
   Automaton a = r.toAutomaton();
   assertTrue(a.isDeterministic());
   CharacterRunAutomaton run = new CharacterRunAutomaton(a);
   assertTrue(run.run("abbbbbd"));
   assertTrue(run.run("acd"));
   assertFalse(run.run("ad"));
 }
  public void testSpecialCase2() throws Exception {
    RegExp re = new RegExp(".+\u0775");
    String input = "\ufadc\ufffd\ub80b\uda5a\udc68\uf234\u0056\uda5b\udcc1\ufffd\ufffd\u0775";
    Automaton automaton = re.toAutomaton();
    CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton);
    ByteRunAutomaton bra = new ByteRunAutomaton(automaton);

    assertTrue(cra.run(input));

    byte[] bytes = input.getBytes("UTF-8");
    assertTrue(bra.run(bytes, 0, bytes.length)); // this one fails!
  }
  public void testSpecialCase3() throws Exception {
    RegExp re = new RegExp("(\\鯺)*(.)*\\Ӕ");
    String input =
        "\u5cfd\ufffd\ub2f7\u0033\ue304\u51d7\u3692\udb50\udfb3\u0576\udae2\udc62\u0053\u0449\u04d4";
    Automaton automaton = re.toAutomaton();
    CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton);
    ByteRunAutomaton bra = new ByteRunAutomaton(automaton);

    assertTrue(cra.run(input));

    byte[] bytes = input.getBytes("UTF-8");
    assertTrue(bra.run(bytes, 0, bytes.length));
  }
  public void testSpecialCase() {
    RegExp re = new RegExp(".?");
    Automaton automaton = re.toAutomaton();
    CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton);
    ByteRunAutomaton bra = new ByteRunAutomaton(automaton);
    // make sure character dfa accepts empty string
    assertTrue(cra.isAccept(cra.getInitialState()));
    assertTrue(cra.run(""));
    assertTrue(cra.run(new char[0], 0, 0));

    // make sure byte dfa accepts empty string
    assertTrue(bra.isAccept(bra.getInitialState()));
    assertTrue(bra.run(new byte[0], 0, 0));
  }
 public String print(String tab) {
   return tab
       + "type = "
       + type
       + Out.NL
       + tab
       + "child 1 :"
       + Out.NL
       + //$NON-NLS-1$ //$NON-NLS-2$
       r1.print(tab + "  ")
       + Out.NL
       + tab
       + "child 2 :"
       + Out.NL
       + //$NON-NLS-1$ //$NON-NLS-2$
       r2.print(tab + "  "); // $NON-NLS-1$
 }
 public static void main(String[] args) {
   Set<RunAutomaton> auts = new HashSet<RunAutomaton>();
   RegExp re = new RegExp("TEST");
   Automaton a = re.toAutomaton();
   RunAutomaton ra = new RunAutomaton(a);
   HashDispatcher.dispatch(ra, 8);
   Runnable r =
       new Runnable() {
         public void run() {
           try {
             Thread.sleep(10000);
           } catch (InterruptedException ie) {
           }
           long tps = HashDispatcher.getKtps();
           HashDispatcher.killAll();
           System.out.println(tps + " kT/s over ~10 seconds.");
           String check = Hash.getTripCode("password");
           boolean werks = check.equals("ozOtJW9BFA");
           System.out.println("Sanity check: " + werks);
         }
       };
   Thread t = new Thread(r);
   t.start();
 }
 private void processRegexps(RegExpContainer container, Element el) {
   NodeList regEls = el.getChildNodes();
   int regElsLen = regEls.getLength();
   for (int k = 0; k < regElsLen; k++) {
     Node nn = regEls.item(k);
     if ("RegExp".equals(nn.getNodeName())) {
       Element expEl = (Element) nn;
       RegExp regexp = new RegExp();
       regexp.setInput(expEl.getAttribute("input"));
       regexp.setOutput(expEl.getAttribute("output"));
       regexp.setAppendBuffer(parseAppendBuffer(expEl.getAttribute("dest")));
       regexp.setDest(parseInt(expEl.getAttribute("dest")));
       regexp.setConditional(expEl.getAttribute("conditional"));
       container.addRegExp(regexp);
       processRegexps(regexp, (Element) nn);
     } else if ("expression".equals(nn.getNodeName())) {
       Element expEl = (Element) nn;
       try {
         RegExp regexp = (RegExp) container; // cannot cast - exception see below
         Expression exp = new Expression();
         exp.setExpression(nn.getTextContent());
         exp.setNoClean(expEl.getAttribute("noclean"));
         exp.setRepeat(parseBoolean(expEl.getAttribute("repeat"), false));
         exp.setClear(parseBoolean(expEl.getAttribute("clear"), false));
         regexp.setExpression(exp);
       } catch (Exception e) {
         LOGGER.warn("unparseable expression! " + container);
         // happens here (kino.de) - the last empty expression.
         // maybe no RegExp around?
         //
         // <GetTrailer dest="5">
         // <RegExp input="$$1" output="&lt;details&gt;&lt;trailer
         // urlencoded=&quot;yes&quot;&gt;\1&lt;/trailer&gt;&lt;/details&gt;" dest="5">
         // <expression noclean="1">&lt;url&gt;([^&lt;]*)&lt;/url&gt;</expression>
         // </RegExp>
         // <expression noclean="1"/> <------------------
         // </GetTrailer>
       }
     } else {
       // skip nodest that we don't know about
       // System.out.println("Skipping Node: " + nn);
     }
   }
 }
Beispiel #9
0
 @Test
 public void complexConstructorParenthesized() {
   RegExp regexp = getWindow().createRegExp(".");
   assertEquals(".", regexp.getSource());
 }