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

31
LINES

< > BotCompany Repo | #1033230 // dropSpaceEtc

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

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

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

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033230
Snippet name: dropSpaceEtc
Eternal ID of this version: #1033230/2
Text MD5: ca2dac2fa0167b86c8a1eb627dd7ce5a
Transpilation MD5: 14513bc3ef903e52cd347809d1bf4f8f
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:33:27
Source code size: 719 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 104 / 163
Version history: 1 change(s)
Referenced in: [show references]