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

23
LINES

< > BotCompany Repo | #1018479 // lines_iterator

JavaX fragment (include)

static IterableIterator<S> lines_iterator(fS s) {
  if (s == null) ret emptyIterableIterator();
  ret iteratorFromFunction(new F0<S> {
    int start = 0;
    
    S get() {
      int i = toLines_nextLineBreak(s, start);
      if (i < 0) {
        S toReturn = s.length() > start ? s.substring(start) : null;
        start = s.length();
        ret toReturn;
      }

      S toReturn = s.substring(start, i);
      if (s.charAt(i) == '\r' && i+1 < s.length() && s.charAt(i+1) == '\n')
        i += 2;
      else
        ++i;
      start = i;
      ret toReturn;
    }
  });
}

Author comment

Began life as a copy of #1001950

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018479
Snippet name: lines_iterator
Eternal ID of this version: #1018479/6
Text MD5: e06d09cecad0c28157281c7e27303f19
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-01 18:12:19
Source code size: 597 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 405 / 443
Version history: 5 change(s)
Referenced in: [show references]