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)

sclass LineBuffer {
  VF1<S> onLine;
  new StringBuilder currentLine;

  *() {}
  *(VF1<S> *onLine) {}
  
  void append(S s) {
    append(s, onLine);
  }
  
  void append(S s, VF1<S> onLine) {
    currentLine.append(s);
    if (contains(s, '\n')) {
      int i = 0, j;
      s = str(currentLine);
      while ((j = indexOf(s, i, '\n')) >= 0) {
        S line = dropTrailingBackslashR(substring(s, i, j));
        callF(onLine, line);
        i = j+1;
      }
      currentLine = new StringBuilder(substring(s, i));
    }
  }
  
  int size() { ret l(currentLine); }
}

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: 572 / 1136
Version history: 8 change(s)
Referenced in: [show references]