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

20
LINES

< > BotCompany Repo | #1037247 // tok_javaDropSlashStarCommentsFromWhitespace

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

Libraryless. Click here for Pure Java version (172L/2K).

1  
// drop only /* */ comments
2  
sS tok_javaDropSlashStarCommentsFromWhitespace(S s) {
3  
  int l = l(s), j = 0;
4  
  new StringBuilder buf;
5  
  while (j < l) {
6  
    int i = j;
7  
    char c = s.charAt(j);
8  
    char d = j+1 >= l ? '\0' : s.charAt(j+1);
9  
    if (c == '/' && d == '*') {
10  
      do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/"));
11  
      j = Math.min(j+2, l);
12  
    } else if (c == '/' && d == '/') {
13  
      do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
14  
      buf.append(substring(s, i, j)); // keep comment
15  
    } else {
16  
      buf.append(c); ++j;
17  
    }
18  
  }
19  
  ret str(buf);
20  
}

Author comment

Began life as a copy of #1008628

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1037247
Snippet name: tok_javaDropSlashStarCommentsFromWhitespace
Eternal ID of this version: #1037247/1
Text MD5: 2b8d38ea0aafa2f99b8919cb3ff1bddd
Transpilation MD5: 0e59e6e6344a64586a66aed606ee1f82
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-09-16 13:18:01
Source code size: 616 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 129 / 184
Referenced in: [show references]