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

28
LINES

< > BotCompany Repo | #1013566 // ai_parse_toList1

JavaX fragment (include)

static L<S> ai_parse_toList1(S parse) {
  ret ai_parse_toList1(parse, curlySep());
}

static L<S> ai_parse_toList1(S parse, Pair<S> sep) {
  assertNempty(sep.a);
  assertNempty(sep.b);
  int i = 0;
  new L<Int> stack;
  new StringBuilder buf;
  new L<S> out;
  while ping (i < l(parse)) {
    if (substringAtIs(parse, i, sep.a)) {
      if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
      stack.add(i);
      i += l(sep.a);
    } else if (substringAtIs(parse, i, sep.b)) {
      int j = popLast(stack);
      i += l(sep.b);
      if (empty(stack))
        out.add(substring(parse, j, i));
    } else if (empty(stack))
      buf.append(parse.charAt(i++));
    else i++;
  }
  if (nempty(buf)) out.add(getAndClearStringBuilder(buf));
  ret out;
}

Author comment

Began life as a copy of #1013561

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: #1013566
Snippet name: ai_parse_toList1
Eternal ID of this version: #1013566/3
Text MD5: 1e1380f8e8cc596f5d2734fb9d944a84
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 13:48:37
Source code size: 782 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 385 / 410
Version history: 2 change(s)
Referenced in: [show references]