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: | 676 / 890 |
| Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1025611 - groupPythonStyleIndents_honoringBrackets - TODO: unclosed multi-line string literals |