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

29
LINES

< > BotCompany Repo | #1000510 // FNonMarkedAsList

JavaX fragment (include)

1  
static class FNonMarkedAsList extends FunctionImpl {
2  
  public O process(Object _in) {
3  
    String in = cast _in;
4  
    L<int> m = getFindMarkers2(in);
5  
    new L<S> list;
6  
    for (int i = 0; i < m.size(); i += 2) {
7  
      int from = i == 0 ? 0 : m.get(i-1);
8  
      int to = i == m.size()-1 ? in.length() : m.get(i);
9  
      if (to > from)
10  
        list.add(in.substring(from, to));
11  
    }
12  
    ret list;
13  
  }
14  
  
15  
  static L<int> getFindMarkers2(String s) {
16  
    L<int> l = new ArrayList<Integer>();
17  
    int i = 0;
18  
    while (i < s.length()) {
19  
      int j = s.indexOf("[[", i);
20  
      if (j < 0) break;
21  
      int k = s.indexOf("]]", j+2);
22  
      if (k < 0) break;
23  
      l.add(j);
24  
      l.add(k+2);
25  
      i = k+2;
26  
    }
27  
    return l;
28  
  }
29  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000510
Snippet name: FNonMarkedAsList
Eternal ID of this version: #1000510/1
Text MD5: fadac218cc7f2a984a301b746079b143
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-09 20:26:41
Source code size: 749 bytes / 29 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 573 / 1284
Referenced in: [show references]