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

27
LINES

< > BotCompany Repo | #1021348 // filterChars

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

Libraryless. Click here for Pure Java version (3805L/22K).

1  
sS lambdaMapLike filterChars(IPred<Char> pred, S s) {
2  
  replace test with pred.get .
3  
  
4  
  if (empty(s)) null;
5  
  int n = l(s), i = 0;
6  
  char c = s.charAt(i);
7  
  bool totality = test(c);
8  
  for (++i; i < n; i++) {
9  
    c = s.charAt(i);
10  
    bool b = test(c);
11  
    
12  
    if (b != totality) {
13  
      // diverse case
14  
      new StringBuilder buf;
15  
      if (totality) buf.append(substring(s, 0, i));
16  
      while ping (true) {
17  
        if (b) buf.append(c);
18  
        if (++i >= n) break;
19  
        c = s.charAt(i);
20  
        b = test(c);
21  
      }
22  
      ret buf.toString();
23  
    }
24  
  }
25  
    
26  
  ret totality ? s : "";
27  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021348
Snippet name: filterChars
Eternal ID of this version: #1021348/9
Text MD5: aebaf7d53d9d53856cf59019be689704
Transpilation MD5: 881a3d943f0e2f944767c9d1a2a1279d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-16 07:32:26
Source code size: 618 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 460
Version history: 8 change(s)
Referenced in: [show references]