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)

static S javaTokWordWrap(S s) {
  ret javaTokWordWrap(120, s);
}

// TODO: complete trimming
static S javaTokWordWrap(int cols, S s) {
  int col = 0;
  L<S> tok = javaTok(s);
  for (int i = 0; i < l(tok); i++) {
    S t = tok.get(i);
    if (odd(i) && col >= cols && !containsNewLine(t))
      tok.set(i, t = rtrimSpaces(t) + "\n");
    int idx = t.lastIndexOf('\n');
    if (idx >= 0) col = l(t)-(idx+1);
    else col += l(t);
  }
  ret join(tok);
}

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz, 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: 382 / 376
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1005532 & http://1005532.tinybrain.de