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

29
LINES

< > BotCompany Repo | #1029294 // characterIterator

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2566L/16K).

static CharacterIterator characterIterator(S s, int from default 0) {
  ret new CharacterIterator {
    int n = l(s);
    int i = from;
    
    public bool hasNext() { ret i < n; }
    public char next() { ret s.charAt(i++); }
  };
}

static CharacterIterator characterIterator(S s, int from, int _n) {
  ret new CharacterIterator {
    int n = min(l(s), from+_n);
    int i = from;
    
    public bool hasNext() { ret i < n; }
    public char next() { ret s.charAt(i++); }
  };
}

static CharacterIterator characterIterator(char[] s, int from, int _n) {
  ret new CharacterIterator {
    int n = min(l(s), from+_n);
    int i = from;
    
    public bool hasNext() { ret i < n; }
    public char next() { ret s[i++]; }
  };
}

Author comment

Began life as a copy of #1029163

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029294
Snippet name: characterIterator
Eternal ID of this version: #1029294/3
Text MD5: 6ee69df9eafd6e23cf002fb1b71fe32a
Transpilation MD5: 020e9dfb37f54c28e1e972e2bba5ef7e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-09 15:30:24
Source code size: 756 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 294 / 400
Version history: 2 change(s)
Referenced in: [show references]