Class CodePointIterator

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static CodePointIterator EMPTY
      The empty code point iterator.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      ByteIterator asLatin1()
      Get a byte iterator over the latin-1 encoding of this code point iterator.
      ByteIterator asUtf8()
      Get a byte iterator over the UTF-8 encoding of this code point iterator.
      ByteIterator asUtf8​(boolean escapeNul)
      Get a byte iterator over the UTF-8 encoding of this code point iterator.
      ByteIterator base32Decode()
      Base32-decode the current stream.
      ByteIterator base32Decode​(Base32Alphabet alphabet)
      Base32-decode the current stream.
      ByteIterator base32Decode​(Base32Alphabet alphabet, boolean requirePadding)
      Base32-decode the current stream.
      ByteIterator base64Decode()
      Base64-decode the current stream.
      ByteIterator base64Decode​(Base64Alphabet alphabet)
      Base64-decode the current stream.
      ByteIterator base64Decode​(Base64Alphabet alphabet, boolean requirePadding)
      Base64-decode the current stream.
      boolean contentEquals​(java.lang.String other)
      Determine if the remaining contents of this iterator are identical to the given string.
      boolean contentEquals​(CodePointIterator other)
      Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator.
      CodePointIterator delimitedBy​(int... delims)
      Get a sub-iterator that is delimited by the given code points.
      java.lang.StringBuilder drainTo​(java.lang.StringBuilder b)
      Drain all the remaining code points in this iterator to the given string builder.
      java.lang.StringBuilder drainTo​(java.lang.StringBuilder b, int delim, int n)
      Drain all the remaining code points in this iterator to the given string builder, inserting the given delimiter after every n code points.
      java.lang.StringBuilder drainTo​(java.lang.StringBuilder b, java.lang.String prefix, int n)
      Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix before every n code points.
      java.lang.StringBuilder drainTo​(java.lang.StringBuilder b, java.lang.String prefix, int delim, int n)
      Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix and delimiter before and after every n code points, respectively.
      java.lang.String drainToString()
      Drain all the remaining code points in this iterator to a new string.
      java.lang.String drainToString​(int delim, int n)
      Drain all the remaining code points in this iterator to a new string, inserting the given delimiter after every n code points.
      java.lang.String drainToString​(java.lang.String prefix, int n)
      Drain all the remaining code points in this iterator to a new string, inserting the given prefix before every n code points.
      java.lang.String drainToString​(java.lang.String prefix, int delim, int n)
      Drain all the remaining code points in this iterator to a new string, inserting the given prefix and delimiter before and after every n code points, respectively.
      abstract long getIndex()
      Get the current offset, by code point.
      abstract boolean hasNext()
      Determine if there are more code points after the current code point.
      abstract boolean hasPrevious()
      Determine if there are more code points before the current code point.
      ByteIterator hexDecode()
      Hex-decode the current stream.
      CodePointIterator limitedTo​(long size)
      Return a copy of this iterator which is limited to the given number of code points after the current one.
      abstract int next()
      Get the next code point.
      static CodePointIterator ofChars​(char[] chars)
      Get a code point iterator for a character array.
      static CodePointIterator ofChars​(char[] chars, int offs)
      Get a code point iterator for a character array.
      static CodePointIterator ofChars​(char[] chars, int offs, int len)
      Get a code point iterator for a character array.
      static CodePointIterator ofLatin1Bytes​(byte[] bytes)
      Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.
      static CodePointIterator ofLatin1Bytes​(byte[] bytes, int offs, int len)
      Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.
      static CodePointIterator ofString​(java.lang.String string)
      Get a code point iterator for a string.
      static CodePointIterator ofString​(java.lang.String string, int offs, int len)
      Get a code point iterator for a string.
      static CodePointIterator ofUtf8Bytes​(byte[] bytes)
      Get a code point iterator for a UTF-8 encoded byte array.
      static CodePointIterator ofUtf8Bytes​(byte[] bytes, int offs, int len)
      Get a code point iterator for a UTF-8 encoded array.
      abstract int peekNext()
      Peek at the next code point without advancing.
      abstract int peekPrevious()
      Peek at the previous code point without moving backwards.
      abstract int previous()
      Get the previous code point.
      CodePointIterator skip​(java.util.function.IntPredicate predicate)
      Get a sub-iterator that removes code points based on a predicate.
      CodePointIterator skipAll()
      Skip all the remaining code points in this iterator.
      CodePointIterator skipCrLf()
      Get a sub-iterator that removes the following code points: 10(\n) and 13(\r).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Method Detail

      • hasNext

        public abstract boolean hasNext()
        Determine if there are more code points after the current code point.
        Specified by:
        hasNext in interface BiDirIntIterator
        Specified by:
        hasNext in interface IntIterator
        Returns:
        true if there are more code points, false otherwise
      • hasPrevious

        public abstract boolean hasPrevious()
        Determine if there are more code points before the current code point.
        Specified by:
        hasPrevious in interface BiDirIntIterator
        Returns:
        true if there are more code points, false otherwise
      • next

        public abstract int next()
                          throws java.util.NoSuchElementException
        Get the next code point.
        Specified by:
        next in interface BiDirIntIterator
        Specified by:
        next in interface IntIterator
        Returns:
        the next code point
        Throws:
        java.util.NoSuchElementException - if hasNext() returns false
      • peekNext

        public abstract int peekNext()
                              throws java.util.NoSuchElementException
        Peek at the next code point without advancing.
        Specified by:
        peekNext in interface BiDirIntIterator
        Specified by:
        peekNext in interface IntIterator
        Returns:
        the next code point
        Throws:
        java.util.NoSuchElementException - if hasNext() returns false
      • previous

        public abstract int previous()
                              throws java.util.NoSuchElementException
        Get the previous code point.
        Specified by:
        previous in interface BiDirIntIterator
        Returns:
        the previous code point
        Throws:
        java.util.NoSuchElementException - if hasPrevious() returns false
      • peekPrevious

        public abstract int peekPrevious()
                                  throws java.util.NoSuchElementException
        Peek at the previous code point without moving backwards.
        Specified by:
        peekPrevious in interface BiDirIntIterator
        Returns:
        the previous code point
        Throws:
        java.util.NoSuchElementException - if hasPrevious() returns false
      • getIndex

        public abstract long getIndex()
        Get the current offset, by code point.
        Specified by:
        getIndex in interface IndexIterator
        Returns:
        the code point offset
      • contentEquals

        public final boolean contentEquals​(CodePointIterator other)
        Determine if the remaining contents of this iterator are identical to the remaining contents of the other iterator. If the contents are not equal, the iterators will be positioned at the location of the first difference (i.e. the code point returned by next() will be the differing code point. If the contents are equal, the iterators will both be positioned at the end of their contents.
        Parameters:
        other - the other byte iterator
        Returns:
        true if the contents are equal, false otherwise
      • contentEquals

        public boolean contentEquals​(java.lang.String other)
        Determine if the remaining contents of this iterator are identical to the given string. If the contents are not equal, the iterator will be positioned at the location of the first difference (i.e. the code point returned by next() will be the differing code point. If the contents are equal, the iterator will be positioned at the end of its contents.
        Parameters:
        other - the other string
        Returns:
        true if the contents are equal, false otherwise
      • limitedTo

        public final CodePointIterator limitedTo​(long size)
        Return a copy of this iterator which is limited to the given number of code points after the current one. Advancing the returned iterator will also advance this one.
        Parameters:
        size - the number of code points
        Returns:
        the limited code point iterator
      • delimitedBy

        public final CodePointIterator delimitedBy​(int... delims)
        Get a sub-iterator that is delimited by the given code points. The returned iterator offset starts at 0 and cannot be backed up before that point. The returned iterator will return false for hasNext() if the next character in the encapsulated iterator is a delimiter or if the underlying iterator returns false for hasNext().
        Parameters:
        delims - the code point delimiters
        Returns:
        the sub-iterator
      • drainTo

        public java.lang.StringBuilder drainTo​(java.lang.StringBuilder b)
        Drain all the remaining code points in this iterator to the given string builder.
        Parameters:
        b - the string builder
        Returns:
        the same string builder
      • skipAll

        public CodePointIterator skipAll()
        Skip all the remaining code points in this iterator. (Useful in combination with delimitedBy(int...))
        Returns:
        the same code point iterator
      • drainTo

        public java.lang.StringBuilder drainTo​(java.lang.StringBuilder b,
                                               java.lang.String prefix,
                                               int delim,
                                               int n)
        Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix and delimiter before and after every n code points, respectively.
        Parameters:
        b - the string builder
        prefix - the prefix
        delim - the delimiter
        n - the number of code points between each prefix and delimiter
        Returns:
        the same string builder
      • drainTo

        public java.lang.StringBuilder drainTo​(java.lang.StringBuilder b,
                                               int delim,
                                               int n)
        Drain all the remaining code points in this iterator to the given string builder, inserting the given delimiter after every n code points.
        Parameters:
        b - the string builder
        delim - the delimiter
        n - the number of code points between each delimiter
        Returns:
        the same string builder
      • drainTo

        public java.lang.StringBuilder drainTo​(java.lang.StringBuilder b,
                                               java.lang.String prefix,
                                               int n)
        Drain all the remaining code points in this iterator to the given string builder, inserting the given prefix before every n code points.
        Parameters:
        b - the string builder
        prefix - the prefix
        n - the number of code points between each prefix
        Returns:
        the same string builder
      • drainToString

        public java.lang.String drainToString()
        Drain all the remaining code points in this iterator to a new string.
        Returns:
        the string
      • drainToString

        public java.lang.String drainToString​(java.lang.String prefix,
                                              int delim,
                                              int n)
        Drain all the remaining code points in this iterator to a new string, inserting the given prefix and delimiter before and after every n code points, respectively.
        Parameters:
        prefix - the prefix
        delim - the delimiter
        n - the number of code points between each prefix and delimiter
        Returns:
        the string
      • drainToString

        public java.lang.String drainToString​(int delim,
                                              int n)
        Drain all the remaining code points in this iterator to a new string, inserting the given delimiter after every n code points.
        Parameters:
        delim - the delimiter
        n - the number of code points between each delimiter
        Returns:
        the string
      • drainToString

        public java.lang.String drainToString​(java.lang.String prefix,
                                              int n)
        Drain all the remaining code points in this iterator to a new string, inserting the given prefix before every n code points.
        Parameters:
        prefix - the prefix
        n - the number of code points between each prefix
        Returns:
        the string
      • base64Decode

        public ByteIterator base64Decode​(Base64Alphabet alphabet,
                                         boolean requirePadding)
        Base64-decode the current stream.
        Parameters:
        alphabet - the alphabet to use
        requirePadding - true to require padding, false if padding is optional
        Returns:
        an iterator over the decoded bytes
      • base32Decode

        public ByteIterator base32Decode​(Base32Alphabet alphabet,
                                         boolean requirePadding)
        Base32-decode the current stream.
        Parameters:
        alphabet - the alphabet to use
        requirePadding - true to require padding, false if padding is optional
        Returns:
        an iterator over the decoded bytes
      • hexDecode

        public ByteIterator hexDecode()
        Hex-decode the current stream.
        Returns:
        an iterator over the decoded bytes
      • base64Decode

        public ByteIterator base64Decode​(Base64Alphabet alphabet)
        Base64-decode the current stream.
        Parameters:
        alphabet - the alphabet to use
        Returns:
        an iterator over the decoded bytes
      • base64Decode

        public ByteIterator base64Decode()
        Base64-decode the current stream.
        Returns:
        an iterator over the decoded bytes
      • base32Decode

        public ByteIterator base32Decode​(Base32Alphabet alphabet)
        Base32-decode the current stream.
        Parameters:
        alphabet - the alphabet to use
        Returns:
        an iterator over the decoded bytes
      • base32Decode

        public ByteIterator base32Decode()
        Base32-decode the current stream.
        Returns:
        an iterator over the decoded bytes
      • asLatin1

        public ByteIterator asLatin1()
        Get a byte iterator over the latin-1 encoding of this code point iterator.
        Returns:
        the byte iterator
      • asUtf8

        public ByteIterator asUtf8()
        Get a byte iterator over the UTF-8 encoding of this code point iterator.
        Returns:
        the byte iterator
      • asUtf8

        public ByteIterator asUtf8​(boolean escapeNul)
        Get a byte iterator over the UTF-8 encoding of this code point iterator.
        Parameters:
        escapeNul - true to escape NUL (0) characters as two bytes, false to encode them as one byte
        Returns:
        the byte iterator
      • ofString

        public static CodePointIterator ofString​(java.lang.String string)
        Get a code point iterator for a string.
        Parameters:
        string - the string
        Returns:
        the code point iterator
      • ofString

        public static CodePointIterator ofString​(java.lang.String string,
                                                 int offs,
                                                 int len)
        Get a code point iterator for a string.
        Parameters:
        string - the string
        Returns:
        the code point iterator
      • ofChars

        public static CodePointIterator ofChars​(char[] chars)
        Get a code point iterator for a character array.
        Parameters:
        chars - the array
        Returns:
        the code point iterator
      • ofChars

        public static CodePointIterator ofChars​(char[] chars,
                                                int offs)
        Get a code point iterator for a character array.
        Parameters:
        chars - the array
        offs - the array offset
        Returns:
        the code point iterator
      • ofChars

        public static CodePointIterator ofChars​(char[] chars,
                                                int offs,
                                                int len)
        Get a code point iterator for a character array.
        Parameters:
        chars - the array
        offs - the array offset
        len - the number of characters to include
        Returns:
        the code point iterator
      • ofUtf8Bytes

        public static CodePointIterator ofUtf8Bytes​(byte[] bytes)
        Get a code point iterator for a UTF-8 encoded byte array.
        Parameters:
        bytes - the array
        Returns:
        the code point iterator
      • ofUtf8Bytes

        public static CodePointIterator ofUtf8Bytes​(byte[] bytes,
                                                    int offs,
                                                    int len)
        Get a code point iterator for a UTF-8 encoded array.
        Parameters:
        bytes - the array
        offs - the array offset
        len - the number of characters to include
        Returns:
        the code point iterator
      • ofLatin1Bytes

        public static CodePointIterator ofLatin1Bytes​(byte[] bytes)
        Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.
        Parameters:
        bytes - the array
        Returns:
        the code point iterator
      • ofLatin1Bytes

        public static CodePointIterator ofLatin1Bytes​(byte[] bytes,
                                                      int offs,
                                                      int len)
        Get a code point iterator for a ISO-8859-1 (Latin-1) encoded array.
        Parameters:
        bytes - the array
        offs - the array offset
        len - the number of characters to include
        Returns:
        the code point iterator
      • skipCrLf

        public CodePointIterator skipCrLf()
        Get a sub-iterator that removes the following code points: 10(\n) and 13(\r).
        Returns:
        the code point iterator
      • skip

        public CodePointIterator skip​(java.util.function.IntPredicate predicate)
        Get a sub-iterator that removes code points based on a predicate.
        Parameters:
        predicate - a IntPredicate that evaluates the code points that should be skipper. Returning true from the predicate indicates that the code point must be skipped.
        Returns:
        the code point iterator