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

47
LINES

< > BotCompany Repo | #1034698 // hashRefTok - parses #<int>, #<id> and #(...) references (for Gazelle 22 project stories)

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

Transpiled version (82L) is out of date.

static LS hashRefTok(S s) {
  new ArrayList<S> tok;
  int l = s == null ? 0 : s.length();
  
  int i = 0;
  while (i < l) {
    int j = i;
    char c;
    
    // scan for whitespace
    while (j < l) {
      if (j < l-1 && s.charAt(j) == '#') {
        c = s.charAt(j+1);
        if (Character.isJavaIdentifierStart(c)
          || Character.isDigit(c)
          || c == '(')
          break;
      }
      j++;
    }
    
    tok.add(quickSubstring(s, i, j));
    i = j;
    if (i >= l) break;

    // scan for non-whitespace
    
    j = i+1; // skip #
    c = s.charAt(j);
    
    if (Character.isJavaIdentifierStart(c)) {
      do ++j; while (j < l && Character.isJavaIdentifierPart(s.charAt(j)));
    } else if (Character.isDigit(c)) {
      do ++j; while (j < l && Character.isDigit(s.charAt(j)));
    } else if (c == '(') {
      do ++j; while (j < l && s.charAt(j) != ')');
      j = Math.min(j+1, l);
    } else
      ++j; // not needed but added for safety
    
    tok.add(quickSubstring(s, i, j));
    i = j;
  }
  
  if ((tok.size() & 1) == 0) tok.add("");
  ret tok;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034698
Snippet name: hashRefTok - parses #<int>, #<id> and #(...) references (for Gazelle 22 project stories)
Eternal ID of this version: #1034698/4
Text MD5: a170c1908b73c3e29a125c5f7c680dc5
Author: stefan
Category: javax / tokenizing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-05 21:08:01
Source code size: 1130 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 89 / 148
Version history: 3 change(s)
Referenced in: [show references]