Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > TinyBrain | #1008909 - ctxEvalPattern

JavaX fragment (include)

1  
sbool ctxEvalPattern_debug;
2  
3  
static bool ctxEvalPattern(S pat) {
4  
  ret ctxEvalPattern(pat, ctxContext().input);
5  
}
6  
7  
static bool ctxEvalPattern(S pat, S input) {
8  
  if (empty(pat)) true;
9  
  CtxContext c = ctxContext();
10  
  WoodyBot bot = woodyBot();
11  
  Pattern p = null;
12  
  if (bot != null)
13  
    p = bot.compiledPatterns.get(pat);
14  
  if (p == null) {
15  
    S pat2 = ctxExpandMacros(pat, c.regexpMacros);
16  
    S re = ctxREToJavaRE(pat2);
17  
    if (ctxEvalPattern_debug)
18  
      print("Java RE pattern: " + re);
19  
    p = Pattern.compile(re, Pattern.CASE_INSENSITIVE);
20  
  }
21  
  if (bot != null)
22  
    bot.compiledPatterns.put(pat, p);
23  
  Matcher m = p.matcher(unnull(input));
24  
  //ctxContext().matches.clear();
25  
  if (m.find()) {
26  
    S group = m.group();
27  
    //print("Setting MATCH1=" + group);
28  
    listPut(c.matches, 0, group);
29  
    true;
30  
  }
31  
  false;
32  
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1008909
Snippet name: ctxEvalPattern
Eternal ID of this version: #1008909/15
Text MD5: 7db0f862e235bd60bfef48daf5c4c128
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-04 18:18:09
Source code size: 855 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 92 / 124
Version history: 14 change(s)
Referenced in: [show]