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).

/* e.g.
  if (x exists):
    ask (what is x?)
  else:
    ask (does x exist?)
  => a list with two elements
  
  input has to be starting at column 1! (call autoUnindent if unsure)
*/
static LS groupPythonStyleIndents(S text) {
  LS lines = lines(text);
  new LS out;
  int startOfBlock = 0;
  for i over lines: {
    bool indented = startsWithSpace(lines.get(i));
    if (!indented) {
      addIfNempty(out, lines_rtrim(subList(lines, startOfBlock, i)));
      startOfBlock = i;
    }
  }
  addIfNempty(out, lines_rtrim(subList(lines, startOfBlock)));
  ret out;
}

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: 202 / 267
Referenced in: [show references]