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

25
LINES

< > TinyBrain | #1008909 - ctxEvalPattern

JavaX fragment (include)

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);
    p = Pattern.compile(re, Pattern.CASE_INSENSITIVE);
  }
  if (bot != null)
    bot.compiledPatterns.put(pat, p);
  Matcher m = p.matcher(unnull(input));
  if (m.find()) {
    c.matches.add(m.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/9
Text MD5: c7e66ab18019d16aadfc0ed837c42c44
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-25 19:11:42
Source code size: 647 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 30 / 34
Version history: 8 change(s)
Referenced in: [show]