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

36
LINES

< > BotCompany Repo | #1032802 // RegExp - encapsulate a regular expression (unparsed and parsed, optionally CI)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5017L/28K).

1  
persistable srecord RegExp(S pattern, bool caseInsensitive) {
2  
  transient Pattern compiled;
3  
  S error;
4  
  
5  
  *(S *pattern) {}
6  
7  
  // TODO: don't compile again when error detected?
8  
  java.util.regex.Pattern compile aka get() {
9  
    try {
10  
      compiled if null = compileRegexpPossiblyIC(pattern, caseInsensitive);
11  
      error = null;
12  
      ret compiled;
13  
    } catch e {
14  
      error = exceptionToStringShort(e);
15  
      null;
16  
    }
17  
  }
18  
  
19  
  bool valid() {
20  
    ret compile() != null;
21  
  }
22  
  
23  
  bool containsSpecialChars() {
24  
    ret containsRegExpSpecialChars(pattern);
25  
  }
26  
  
27  
  bool containedIn(S s) {
28  
    ret regexpContains(getForce(), s);
29  
  }
30  
  
31  
  java.util.regex.Pattern getForce() {
32  
    var pattern = get();
33  
    if (error != null) fail(error, pattern);
34  
    ret pattern;
35  
  }
36  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1032802
Snippet name: RegExp - encapsulate a regular expression (unparsed and parsed, optionally CI)
Eternal ID of this version: #1032802/14
Text MD5: 823482a7bccdd8145b98140fd69cf41a
Transpilation MD5: 0ef2c1b3e4d161f3ec8c62ed5bb16e25
Author: stefan
Category: javax / regexp
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-11-14 20:57:10
Source code size: 805 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 241 / 415
Version history: 13 change(s)
Referenced in: [show references]