Class PyUnicode

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, java.lang.Iterable<java.lang.Integer>, BufferProtocol
    Direct Known Subclasses:
    PyUnicodeDerived

    public class PyUnicode
    extends PyString
    implements java.lang.Iterable<java.lang.Integer>
    a builtin python unicode string.
    See Also:
    Serialized Form
    • Field Detail

      • TYPE

        public static final PyType TYPE
    • Constructor Detail

      • PyUnicode

        public PyUnicode()
      • PyUnicode

        public PyUnicode​(java.lang.String string)
        Construct a PyUnicode interpreting the Java String argument as UTF-16.
        Parameters:
        string - UTF-16 string encoding the characters (as Java).
      • PyUnicode

        public PyUnicode​(java.lang.String string,
                         boolean isBasic)
        Construct a PyUnicode interpreting the Java String argument as UTF-16. If it is known that the string contains no supplementary characters, argument isBasic may be set true by the caller. If it is false, the PyUnicode will scan the string to find out.
        Parameters:
        string - UTF-16 string encoding the characters (as Java).
        isBasic - true if it is known that only BMP characters are present.
      • PyUnicode

        public PyUnicode​(PyType subtype,
                         java.lang.String string)
      • PyUnicode

        public PyUnicode​(PyString pystring)
      • PyUnicode

        public PyUnicode​(char c)
      • PyUnicode

        public PyUnicode​(int codepoint)
      • PyUnicode

        public PyUnicode​(int[] codepoints)
      • PyUnicode

        public PyUnicode​(java.util.Iterator<java.lang.Integer> iter)
      • PyUnicode

        public PyUnicode​(java.util.Collection<java.lang.Integer> ucs4)
    • Method Detail

      • substring

        public java.lang.String substring​(int start,
                                          int end)
        Return a substring of this object as a Java String. The indices are code point indices, not UTF-16 (char) indices. For example:
         PyUnicode u = new PyUnicode("..𐀂𐀃...");
         // (Python) u = u'..\U00010002\U00010003...'
        
         String s = u.substring(2, 4);  // = "𐀂𐀃" (Java)
         
        Overrides:
        substring in class PyString
        Parameters:
        start - the beginning index, inclusive.
        end - the ending index, exclusive.
        Returns:
        the specified substring.
      • fromInterned

        public static PyUnicode fromInterned​(java.lang.String interned)
        Creates a PyUnicode from an already interned String. Just means it won't be reinterned if used in a place that requires interned Strings.
      • isBasicPlane

        public boolean isBasicPlane()
        Determine whether the string consists entirely of basic-plane characters. For a PyString, of course, it is always true, but this is useful in cases where either a PyString or a PyUnicode is acceptable.
        Overrides:
        isBasicPlane in class PyString
        Returns:
        true if the string consists only of BMP characters
      • getCodePointCount

        public int getCodePointCount()
      • checkEncoding

        public static java.lang.String checkEncoding​(java.lang.String s)
      • createInstance

        public PyString createInstance​(java.lang.String str)
        Description copied from class: PyString
        Create an instance of the same type as this object, from the Java String given as argument. This is to be overridden in a subclass to return its own type.
        Overrides:
        createInstance in class PyString
        Parameters:
        str - to wrap
        Returns:
      • __mod__

        public PyObject __mod__​(PyObject other)
        Description copied from class: PyObject
        Equivalent to the standard Python __mod__ method
        Overrides:
        __mod__ in class PyString
        Parameters:
        other - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the mod, or null if this operation is not defined
      • __str__

        public PyString __str__()
        Description copied from class: PyObject
        Equivalent to the standard Python __str__ method. This method should not typically need to be overridden. The easiest way to configure the string representation of a PyObject is to override the standard Java toString method.
        Overrides:
        __str__ in class PyString
      • __len__

        public int __len__()
        Description copied from class: PyObject
        Equivalent to the standard Python __len__ method. Part of the mapping discipline.
        Overrides:
        __len__ in class PyString
        Returns:
        the length of the object
      • __repr__

        public PyString __repr__()
        Description copied from class: PyObject
        Equivalent to the standard Python __repr__ method. This method should not typically need to be overrriden. The easiest way to configure the string representation of a PyObject is to override the standard Java toString method.
        Overrides:
        __repr__ in class PyString
      • getInt

        public int getInt​(int i)
        Overrides:
        getInt in class PyString
      • newSubsequenceIterator

        public java.util.Iterator<java.lang.Integer> newSubsequenceIterator()
        Get an iterator over the code point sequence.
      • newSubsequenceIterator

        public java.util.Iterator<java.lang.Integer> newSubsequenceIterator​(int start,
                                                                            int stop,
                                                                            int step)
        Get an iterator over a slice of the code point sequence.
      • __add__

        public PyObject __add__​(PyObject other)
        Description copied from class: PyString
        Equivalent to the standard Python __add__ method. For a str addition means concatenation and returns a str (PyString) result, except when a PyUnicode argument is given, when a PyUnicode results.
        Overrides:
        __add__ in class PyString
        Parameters:
        other - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the add, or null if this operation is not defined.
      • partition

        public PyTuple partition​(PyObject sep)
        Description copied from class: PyString
        Equivalent to Python str.partition(), splits the PyString at the first occurrence of sepObj returning a PyTuple containing the part before the separator, the separator itself, and the part after the separator.
        Overrides:
        partition in class PyString
        Parameters:
        sep - str, unicode or object implementing BufferProtocol
        Returns:
        tuple of parts
      • rpartition

        public PyTuple rpartition​(PyObject sep)
        Description copied from class: PyString
        Equivalent to Python str.rpartition(), splits the PyString at the last occurrence of sepObj returning a PyTuple containing the part before the separator, the separator itself, and the part after the separator.
        Overrides:
        rpartition in class PyString
        Parameters:
        sep - str, unicode or object implementing BufferProtocol
        Returns:
        tuple of parts
      • iterator

        public java.util.Iterator<java.lang.Integer> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Integer>
      • __complex__

        public PyComplex __complex__()
        Description copied from class: PyObject
        Equivalent to the standard Python __complex__ method. Should only be overridden by numeric objects that can be reasonably coerced into a python complex number.
        Overrides:
        __complex__ in class PyString
        Returns:
        a complex number corresponding to the value of this object.
      • atoi

        public int atoi​(int base)
        Overrides:
        atoi in class PyString
      • atof

        public double atof()
        Description copied from class: PyString
        Convert this PyString to a floating-point value according to Python rules.
        Overrides:
        atof in class PyString
        Returns:
        the value