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

23
LINES

< > BotCompany Repo | #1025586 // groupPythonStyleIndents

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

Libraryless. Click here for Pure Java version (2406L/15K).

1  
/* e.g.
2  
  if (x exists):
3  
    ask (what is x?)
4  
  else:
5  
    ask (does x exist?)
6  
  => a list with two elements
7  
  
8  
  input has to be starting at column 1! (call autoUnindent if unsure)
9  
*/
10  
static LS groupPythonStyleIndents(S text) {
11  
  LS lines = lines(text);
12  
  new LS out;
13  
  int startOfBlock = 0;
14  
  for i over lines: {
15  
    bool indented = startsWithSpace(lines.get(i));
16  
    if (!indented) {
17  
      addIfNempty(out, lines_rtrim(subList(lines, startOfBlock, i)));
18  
      startOfBlock = i;
19  
    }
20  
  }
21  
  addIfNempty(out, lines_rtrim(subList(lines, startOfBlock)));
22  
  ret out;
23  
}

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: #1025586
Snippet name: groupPythonStyleIndents
Eternal ID of this version: #1025586/1
Text MD5: 979751ce52255562535375664e056cbf
Transpilation MD5: bb562ea53ea71d2636439bb626a99091
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-05 17:01:18
Source code size: 587 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 296 / 389
Referenced in: [show references]