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).

// drop only /* */ comments
sS tok_javaDropSlashStarCommentsFromWhitespace(S s) {
  int l = l(s), j = 0;
  new StringBuilder buf;
  while (j < l) {
    int i = j;
    char c = s.charAt(j);
    char d = j+1 >= l ? '\0' : s.charAt(j+1);
    if (c == '/' && d == '*') {
      do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/"));
      j = Math.min(j+2, l);
    } else if (c == '/' && d == '/') {
      do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
      buf.append(substring(s, i, j)); // keep comment
    } else {
      buf.append(c); ++j;
    }
  }
  ret str(buf);
}

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: 113 / 159
Referenced in: [show references]