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

22
LINES

< > BotCompany Repo | #1028757 // javaTok_simpleSpacesAndTrim

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

Libraryless. Click here for Pure Java version (4079L/24K).

static LS javaTok_simpleSpacesAndTrim(S s) {
  ret javaTok_simpleSpacesAndTrim(javaTok(s));
}
  
static LS javaTok_simpleSpacesAndTrim(LS tok) {
  int n = l(tok);
  for (int i = 0; i < n; i += 2) {
    int nIdx = i;
    S space = tok.get(nIdx);
    S prev = get(tok, nIdx-1), next = get(tok, nIdx+1);
    
    if (empty(space)) // no space anyway? keep that
      space = "";
    else if (prev == null || next == null) // end of string - no spaces either
      space = "";
    else if (isBracket(prev) && isBracket(next))
      space = "";
      
    tok.set(i, space);
  }
  ret tok;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1028757
Snippet name: javaTok_simpleSpacesAndTrim
Eternal ID of this version: #1028757/8
Text MD5: 182b99c7abef171beafa74a5789293c4
Transpilation MD5: 9e70e093086d24b333ff363b9c2172fd
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 10:21:53
Source code size: 607 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 222 / 318
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)