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

18
LINES

< > BotCompany Repo | #1035410 // structTokWordWrap - word-wrap a structure string

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

Libraryless. Click here for Pure Java version (8033L/45K).

1  
static S structTokWordWrap(S s) {
2  
  ret structTokWordWrap(120, s);
3  
}
4  
5  
// TODO: complete trimming
6  
static S structTokWordWrap(int cols, S s) {
7  
  int col = 0;
8  
  L<S> tok = structTok(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  
}

Author comment

Began life as a copy of #1005532

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035410
Snippet name: structTokWordWrap - word-wrap a structure string
Eternal ID of this version: #1035410/1
Text MD5: 343576267b7a4f970d560a2803acb2a0
Transpilation MD5: 284964398f68fe2fdd0abb3bb8b1f908
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-06 16:01:09
Source code size: 475 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 146 / 201
Referenced in: [show references]