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

static LS wordTok2_uncached(String s) {
  new ArrayList<S> tok;
  int l = s == null ? 0 : s.length();
  
  int i = 0, n = 0;
  while (i < l) {
    int j = i;
    
    // scan for whitespace
    while (j < l) {
      char c = s.charAt(j);
      break if Character.isJavaIdentifierPart(c);
      ++j;
      if (j >= l) break;
    }
    
    tok.add(javaTok_substringN(s, i, j));
    ++n;
    i = j;
    if (i >= l) break;
    char c = s.charAt(i);
    char d = i+1 >= l ? '\0' : s.charAt(i+1);

    // scan for non-whitespace
    
    if (Character.isJavaIdentifierStart(c)) {
      do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || s.charAt(j) == '\'')); // for stuff like "don't"
    } else if (Character.isDigit(c)) {
      do ++j; while (j < l && Character.isDigit(s.charAt(j)));
      if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L
    } else
      ++j;
      
    tok.add(javaTok_substringC(s, i, j));
    ++n;
    i = j;
  }
  
  if ((tok.size() % 2) == 0) tok.add("");
  ret tok;
}

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: 222 / 292
Version history: 7 change(s)
Referenced in: [show references]