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

41
LINES

< > BotCompany Repo | #1023689 // wordTok2_uncached - without strings and comments

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

Libraryless. Click here for Pure Java version (76L/1K).

1  
static LS wordTok2_uncached(String s) {
2  
  new ArrayList<S> tok;
3  
  int l = s == null ? 0 : s.length();
4  
  
5  
  int i = 0, n = 0;
6  
  while (i < l) {
7  
    int j = i;
8  
    
9  
    // scan for whitespace
10  
    while (j < l) {
11  
      char c = s.charAt(j);
12  
      break if Character.isJavaIdentifierPart(c);
13  
      ++j;
14  
      if (j >= l) break;
15  
    }
16  
    
17  
    tok.add(javaTok_substringN(s, i, j));
18  
    ++n;
19  
    i = j;
20  
    if (i >= l) break;
21  
    char c = s.charAt(i);
22  
    char d = i+1 >= l ? '\0' : s.charAt(i+1);
23  
24  
    // scan for non-whitespace
25  
    
26  
    if (Character.isJavaIdentifierStart(c)) {
27  
      do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || s.charAt(j) == '\'')); // for stuff like "don't"
28  
    } else if (Character.isDigit(c)) {
29  
      do ++j; while (j < l && Character.isDigit(s.charAt(j)));
30  
      if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L
31  
    } else
32  
      ++j;
33  
      
34  
    tok.add(javaTok_substringC(s, i, j));
35  
    ++n;
36  
    i = j;
37  
  }
38  
  
39  
  if ((tok.size() % 2) == 0) tok.add("");
40  
  ret tok;
41  
}

Author comment

Began life as a copy of #1023688

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1023689
Snippet name: wordTok2_uncached - without strings and comments
Eternal ID of this version: #1023689/8
Text MD5: 4a1a7aebc82fa5fa6513960c0fac5c9f
Transpilation MD5: d86127f78e7260089b9f3983b522466b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-02 20:41:00
Source code size: 1066 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 344 / 411
Version history: 7 change(s)
Referenced in: [show references]