1 | sS indentStructureString(int levels default 100, S s) { |
2 | if (s == null) null; |
3 | LS tok = javaTokForStructure(s); |
4 | new StringBuilder buf; |
5 | int indent = 0; |
6 | levels = clampToInt(levels*2L); |
7 | for i over tok: { |
8 | S t = tok.get(i); |
9 | if (isOpeningBracket(t)) { |
10 | int j = i+5; |
11 | if (containsClosingBracket(subList(tok, i+2, i+5))) { |
12 | buf.append(joinSubList(tok, i, j)); |
13 | i = j-1; |
14 | } else { |
15 | indent += 2; |
16 | buf.append(t); |
17 | if (indent <= levels) |
18 | buf.append("\n").append(spaces(indent)); |
19 | } |
20 | } else if (isClosingBracket(t)) { |
21 | indent -= 2; |
22 | if (indent < levels) |
23 | buf.append("\n").append(spaces(indent)); |
24 | buf.append(t); |
25 | } else if (indent <= levels && eq(t, ",")) { |
26 | buf.append(t).append("\n").append(spaces(indent)); |
27 | i++; |
28 | } else |
29 | buf.append(t); |
30 | } |
31 | ret str(buf); |
32 | } |
Began life as a copy of #1021424
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035337 |
Snippet name: | indentStructureString backup |
Eternal ID of this version: | #1035337/1 |
Text MD5: | 7e555da62ed9915b24925aff66548c43 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-01 17:56:31 |
Source code size: | 907 bytes / 32 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 123 / 127 |
Referenced in: | [show references] |