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

27
LINES

< > BotCompany Repo | #1012997 // LineBuffer - characters in, lines out - not multi-threaded!

JavaX fragment (include)

1  
sclass LineBuffer {
2  
  VF1<S> onLine;
3  
  new StringBuilder currentLine;
4  
5  
  *() {}
6  
  *(VF1<S> *onLine) {}
7  
  
8  
  void append(S s) {
9  
    append(s, onLine);
10  
  }
11  
  
12  
  void append(S s, VF1<S> onLine) {
13  
    currentLine.append(s);
14  
    if (contains(s, '\n')) {
15  
      int i = 0, j;
16  
      s = str(currentLine);
17  
      while ((j = indexOf(s, i, '\n')) >= 0) {
18  
        S line = dropTrailingBackslashR(substring(s, i, j));
19  
        callF(onLine, line);
20  
        i = j+1;
21  
      }
22  
      currentLine = new StringBuilder(substring(s, i));
23  
    }
24  
  }
25  
  
26  
  int size() { ret l(currentLine); }
27  
}

Author comment

Began life as a copy of #1007086

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: #1012997
Snippet name: LineBuffer - characters in, lines out - not multi-threaded!
Eternal ID of this version: #1012997/9
Text MD5: 5cbc97de9332915f7b91bf1090d638c0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-24 01:39:37
Source code size: 592 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 577 / 1141
Version history: 8 change(s)
Referenced in: [show references]