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

32
LINES

< > TinyBrain | #1008909 - ctxEvalPattern

JavaX fragment (include)

sbool ctxEvalPattern_debug;

static bool ctxEvalPattern(S pat) {
  ret ctxEvalPattern(pat, ctxContext().input);
}

static bool ctxEvalPattern(S pat, S input) {
  if (empty(pat)) true;
  CtxContext c = ctxContext();
  WoodyBot bot = woodyBot();
  Pattern p = null;
  if (bot != null)
    p = bot.compiledPatterns.get(pat);
  if (p == null) {
    S pat2 = ctxExpandMacros(pat, c.regexpMacros);
    S re = ctxREToJavaRE(pat2);
    if (ctxEvalPattern_debug)
      print("Java RE pattern: " + re);
    p = Pattern.compile(re, Pattern.CASE_INSENSITIVE);
  }
  if (bot != null)
    bot.compiledPatterns.put(pat, p);
  Matcher m = p.matcher(unnull(input));
  //ctxContext().matches.clear();
  if (m.find()) {
    S group = m.group();
    //print("Setting MATCH1=" + group);
    listPut(c.matches, 0, group);
    true;
  }
  false;
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, 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: 52 / 78
Version history: 14 change(s)
Referenced in: [show]