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

28
LINES

< > BotCompany Repo | #1008322 // rules_unfoldIndented

JavaX fragment (include)

1  
static S rules_unfoldIndented(S s, S prefix) {
2  
  if (containsTabs(s)) warn("Tabs in input");
3  
  s = s.replace("\t", "  ");
4  
  L<S> lines = toLines(s);
5  
  for i over lines: {
6  
    S line = lines.get(i);
7  
    S trimmed = trim(line);
8  
    if (empty(trimmed)) continue;
9  
    int n = getIndent(line);
10  
    int j = i+1;
11  
    bool any = false;
12  
    while (j < l(lines)) {
13  
      if (emptyAfterTrim(lines.get(j))) ++j;
14  
      else if (getIndent(lines.get(j)) > n) { ++j; any = true; }
15  
      else break;
16  
    }
17  
    if (!any) continue;
18  
    lines.set(i, "");
19  
    while (i+1 < j) {
20  
      ++i;
21  
      S l = lines.get(i);
22  
      if (!emptyAfterTrim(l))
23  
        lines.set(i, rep(' ', getIndent(l)) + prefix
24  
          + "(" + trimmed + ") & " + trim(l));
25  
    }
26  
  }
27  
  ret fromLines(lines);
28  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008322
Snippet name: rules_unfoldIndented
Eternal ID of this version: #1008322/10
Text MD5: 3ae1f1bcec807e6d2448ed2cb1403b48
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-07 21:38:16
Source code size: 786 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 389 / 434
Version history: 9 change(s)
Referenced in: [show references]