MCPcopy Create free account
hub / github.com/google/re2j / StringIterator

Class StringIterator

java/com/google/re2j/Parser.java:706–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704 // lookingAt().
705 // Only use pop() to advance over possibly non-ASCII runes.
706 private static class StringIterator {
707 private final String str; // a stream of UTF-16 codes
708 private int pos = 0; // current position in UTF-16 string
709
710 StringIterator(String str) {
711 this.str = str;
712 }
713
714 // Returns the cursor position. Do not interpret the result!
715 int pos() {
716 return pos;
717 }
718
719 // Resets the cursor position to a previous value returned by pos().
720 void rewindTo(int pos) {
721 this.pos = pos;
722 }
723
724 // Returns true unless the stream is exhausted.
725 boolean more() {
726 return pos < str.length();
727 }
728
729 // Returns the rune at the cursor position.
730 // Precondition: |more()|.
731 int peek() {
732 return str.codePointAt(pos);
733 }
734
735 // Advances the cursor by |n| positions, which must be ASCII runes.
736 //
737 // (In practise, this is only ever used to skip over regexp
738 // metacharacters that are ASCII, so there is no numeric difference
739 // between indices into UTF-8 bytes, UTF-16 codes and runes.)
740 void skip(int n) {
741 pos += n;
742 }
743
744 // Advances the cursor by the number of cursor positions in |s|.
745 void skipString(String s) {
746 pos += s.length();
747 }
748
749 // Returns the rune at the cursor position, and advances the cursor
750 // past it. Precondition: |more()|.
751 int pop() {
752 int r = str.codePointAt(pos);
753 pos += Character.charCount(r);
754 return r;
755 }
756
757 // Equivalent to both peek() == c but more efficient because we
758 // don't support surrogates. Precondition: |more()|.
759 boolean lookingAt(char c) {
760 return str.charAt(pos) == c;
761 }
762
763 // Equivalent to rest().startsWith(s).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…