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

18
LINES

< > BotCompany Repo | #1005532 // javaTokWordWrap - word-wrap a text preserving javaTok tokens

JavaX fragment (include)

1  
static S javaTokWordWrap(S s) {
2  
  ret javaTokWordWrap(120, s);
3  
}
4  
5  
// TODO: complete trimming
6  
static S javaTokWordWrap(int cols, S s) {
7  
  int col = 0;
8  
  L<S> tok = javaTok(s);
9  
  for (int i = 0; i < l(tok); i++) {
10  
    S t = tok.get(i);
11  
    if (odd(i) && col >= cols && !containsNewLine(t))
12  
      tok.set(i, t = rtrimSpaces(t) + "\n");
13  
    int idx = t.lastIndexOf('\n');
14  
    if (idx >= 0) col = l(t)-(idx+1);
15  
    else col += l(t);
16  
  }
17  
  ret join(tok);
18  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

No comments. add comment

Snippet ID: #1005532
Snippet name: javaTokWordWrap - word-wrap a text preserving javaTok tokens
Eternal ID of this version: #1005532/4
Text MD5: 5f44e074f27482ca3f68b3ce05d27abf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-07 17:19:36
Source code size: 467 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 663 / 707
Version history: 3 change(s)
Referenced in: [show references]