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

26
LINES

< > BotCompany Repo | #1029559 // characterClassIteratorFromMiniRegexp_v1 - only supports optional characters ("ab?c", dev.)

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

Libraryless. Click here for Pure Java version (2767L/18K).

1  
static CharacterClassIterator characterClassIteratorFromMiniRegexp_v1(S regexp, int i default 0) {
2  
  int l = l(regexp);
3  
  if (i >= l) ret new CCI_End;
4  
  char c = regexp.charAt(i);
5  
  
6  
  // backslash (escaped character)
7  
  if (c == '\\' && i+1 < l)
8  
    ret CCI_SingleChar(regexp.charAt(i+1),
9  
      characterClassIteratorFromMiniRegexp_v1(regexp, i+2));
10  
      
11  
  // optional character
12  
  if (i+1 < l && regexp.charAt(i+1) == '?') {
13  
    CharacterClassIterator rest = characterClassIteratorFromMiniRegexp_v1(regexp, i+2);
14  
    // TODO: coalesce choice objects when rest is already a choice?
15  
    new HashMap<Char, CharacterClassIterator> map; // TODO: optional comparator
16  
    fOr (char cc : rest.acceptedChars())
17  
      map.put(cc, rest);
18  
    // may override an assignment made above
19  
    map.put(c, new CCI_SingleChar(c, rest));
20  
    ret CCI_Choice(rest.canEndHere(), map);
21  
  }
22  
  
23  
  // normal character
24  
  ret CCI_SingleChar(regexp.charAt(i),
25  
    characterClassIteratorFromMiniRegexp_v1(regexp, i+1));
26  
}

Author comment

Began life as a copy of #1029557

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029559
Snippet name: characterClassIteratorFromMiniRegexp_v1 - only supports optional characters ("ab?c", dev.)
Eternal ID of this version: #1029559/7
Text MD5: 485acf71783a39ce6a13945b51bbb4a1
Transpilation MD5: a0cabbbc47485a40727788a245ed9b24
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-23 12:58:48
Source code size: 1016 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 210 / 306
Version history: 6 change(s)
Referenced in: [show references]