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

29
LINES

< > BotCompany Repo | #1017544 // splitAtTokens

JavaX fragment (include)

static L<S> splitAtTokens(S s, LS tokens) {
  ret splitAtTokens(javaTok(s), tokens);
}

static L<S> splitAtTokens(L<S> tok, LS tokens) {
  new L<S> l;
  int i = 0;
  while (i < l(tok)) {
    int j = indexOfSubList(tok, tokens, i);
    if (i >= l(tok)) break;
    if (j < 0) j = l(tok);
    l.add(trimJoin(tok.subList(i, j)));
    i = j+l(tokens);
  }
  ret l;
}

static L<S> splitAtTokens(L<S> tok, S... tokens) {
  new L<S> l;
  int i = 0;
  while (i < l(tok)) {
    int j = indexOfSubList(tok, tokens, i);
    if (i >= l(tok)) break;
    if (j < 0) j = l(tok);
    l.add(trimJoin(tok.subList(i, j)));
    i = j+l(tokens);
  }
  ret l;
}

Author comment

Began life as a copy of #1011989

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017544
Snippet name: splitAtTokens
Eternal ID of this version: #1017544/3
Text MD5: acd1b1307e488e0692e664d6b3380989
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-03 19:57:39
Source code size: 666 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 462 / 485
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1017691 - splitAtTokens_once (first occurrence, returns null if list not found)
#1021387 - splitAtTokenIndices - assumes one split token
#1022372 - splitAtEquals_pair - honors tokens and brackets
#1033108 - tok_splitAtAnyOperator [seems to work]