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

24
LINES

< > BotCompany Repo | #1023728 // paragraphsTok - find content separated by empty lines. returns CNC. trims paragraphs

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

Libraryless. Click here for Pure Java version (1747L/11K).

1  
static LS paragraphsTok(S s) {
2  
  new ArrayList<S> tok;
3  
  int l = s == null ? 0 : s.length();
4  
  int i = 0;
5  
  while (i < l && isSpace(s.charAt(i))) ++i;
6  
  tok.add(substring(s, 0, i));
7  
  
8  
  while true {
9  
    IntRange r = tok_findNextEmptyLineWhitespace(s, i);
10  
    if (r == null) break;
11  
    
12  
    tok.add(substring(s, i, r.start));
13  
    tok.add(substring(s, r));
14  
    i = r.end;
15  
  }
16  
  
17  
  if (i < l) {
18  
    int l2 = l;
19  
    while (l2 > i+1 && isSpace(s.charAt(l2-1))) --l2;
20  
    tok.add(substring(s, i, l2));
21  
    tok.add(substring(s, l2));
22  
  }  
23  
  ret tok;
24  
}

Author comment

Began life as a copy of #1003360

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1023728
Snippet name: paragraphsTok - find content separated by empty lines. returns CNC. trims paragraphs
Eternal ID of this version: #1023728/8
Text MD5: a46203e9f45e2a72c3845a5a028b1379
Transpilation MD5: 8c6fdbe3ee823f7924aa091820138557
Author: stefan
Category: javax / tokenizing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-07 18:29:09
Source code size: 569 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 300
Version history: 7 change(s)
Referenced in: [show references]