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

31
LINES

< > BotCompany Repo | #1013561 // ai_parse_toList

JavaX fragment (include)

1  
static O ai_parse_toList(S parse) {
2  
  ret ai_parse_toList(parse, curlySep());
3  
}
4  
5  
// returns L or S
6  
static O ai_parse_toList(S parse, Pair<S> sep) {
7  
  assertNempty(sep.a);
8  
  assertNempty(sep.b);
9  
  int i = 0;
10  
  new L<Int> stack;
11  
  new StringBuilder buf;
12  
  new L out;
13  
  while ping (i < l(parse)) {
14  
    if (substringAtIs(parse, i, sep.a)) {
15  
      if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
16  
      i += l(sep.a);
17  
      stack.add(i);
18  
    } else if (substringAtIs(parse, i, sep.b)) {
19  
      int j = popLast(stack);
20  
      if (empty(stack))
21  
        //out.add(ll(substring(parse, j, i)));
22  
        out.add(ll(ai_parse_toList(substring(parse, j, i))));
23  
      i += l(sep.b);
24  
    } else if (empty(stack))
25  
      buf.append(parse.charAt(i++));
26  
    else i++;
27  
  }
28  
  //if (empty(out)) ret parse;
29  
  if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
30  
  ret recursivelyUnpackSingleElementList(out);
31  
}

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: #1013561
Snippet name: ai_parse_toList
Eternal ID of this version: #1013561/14
Text MD5: fcb85aa88391f0b0202e8b6ab0bfd29e
Author: stefan
Category: javax / general parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-09 14:01:34
Source code size: 926 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 470 / 536
Version history: 13 change(s)
Referenced in: [show references]