org.python.core

## Class PyUnicode

- java.lang.Object
- - org.python.core.PyObject
  - - org.python.core.PySequence
    - - org.python.core.PyBaseString
      - - org.python.core.PyString
        - - org.python.core.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

### Nested Class Summary

### Nested classes/interfaces inherited from class org.python.core.PyObject

`PyObject.ConversionException`

### Field Summary

Fields
`static PyType` `TYPE`

### Fields inherited from class org.python.core.PyObject

`gcMonitorGlobal`

### Constructor Summary

Constructors
Constructor and Description
`PyUnicode()`
`PyUnicode(char c)`
`PyUnicode(java.util.Collection<java.lang.Integer> ucs4)`
`PyUnicode(int codepoint)`
`PyUnicode(int[] codepoints)`
`PyUnicode(java.util.Iterator<java.lang.Integer> iter)`
`PyUnicode(PyString pystring)`
`PyUnicode(PyType subtype, PyString pystring)`
`PyUnicode(PyType subtype, java.lang.String string)`
`PyUnicode(java.lang.String string)` Construct a PyUnicode interpreting the Java String argument as UTF-16.
`PyUnicode(java.lang.String string, boolean isBasic)` Construct a PyUnicode interpreting the Java String argument as UTF-16.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`PyObject` `__add__(PyObject other)` Equivalent to the standard Python __add__ method.
`PyComplex` `__complex__()` Equivalent to the standard Python __complex__ method.
`boolean` `__contains__(PyObject o)` Equivalent to the standard Python __contains__ method.
`PyObject` `__eq__(PyObject other)` Equivalent to the standard Python __eq__ method.
`PyObject` `__format__(PyObject formatSpec)`
`PyObject` `__ge__(PyObject other)` Equivalent to the standard Python __ge__ method.
`PyObject` `__gt__(PyObject other)` Equivalent to the standard Python __gt__ method.
`PyObject` `__le__(PyObject other)` Equivalent to the standard Python __le__ method.
`int` `__len__()` Equivalent to the standard Python __len__ method.
`PyObject` `__lt__(PyObject other)` Equivalent to the standard Python __lt__ method.
`PyObject` `__mod__(PyObject other)` Equivalent to the standard Python __mod__ method
`PyObject` `__ne__(PyObject other)` Equivalent to the standard Python __ne__ method.
`PyString` `__repr__()` Equivalent to the standard Python `__repr__` method.
`PyString` `__str__()` Equivalent to the standard Python __str__ method.
`PyUnicode` `__unicode__()`
`double` `atof()` Convert this PyString to a floating-point value according to Python rules.
`int` `atoi(int base)`
`PyLong` `atol(int base)`
`static java.lang.String` `checkEncoding(java.lang.String s)`
`PyString` `createInstance(java.lang.String string)` Create an instance of the same type as this object, from the Java String given as argument.
`boolean` `endswith(PyObject suffix, PyObject start, PyObject end)` Equivalent to the Python `unicode.endswith` method, testing whether a string ends with a specified suffix, where a sub-range is specified by `[start:end]`.
`static PyUnicode` `from(char c)` Return a not-necessarily new `PyUnicode` from a Java `char`.
`static PyUnicode` `fromCodepoint(int codepoint)` Return a not-necessarily new `PyUnicode` from a Java code point.
`static PyUnicode` `fromInterned(java.lang.String s)` Returns a PyUnicode from an already interned String.
`static PyUnicode` `fromString(java.lang.String s, boolean isBasic)` Return a not-necessarily new `PyUnicode` from a Java `String`.
`PyBuffer` `getBuffer(int flags)` `PyUnicode` implements the interface `BufferProtocol` technically by inheritance from `PyString`, but does not provide a buffer (in CPython).
`int` `getCodePointCount()`
`int` `getInt(int i)`
`boolean` `isBasicPlane()` Determine whether the string consists entirely of basic-plane characters.
`java.util.Iterator<java.lang.Integer>` `iterator()`
`PyString` `join(PyObject seq)`
`java.util.Iterator<java.lang.Integer>` `newSubsequenceIterator()` Get an iterator over the code point sequence.
`java.util.Iterator<java.lang.Integer>` `newSubsequenceIterator(int start, int stop, int step)` Get an iterator over a slice of the code point sequence.
`PyTuple` `partition(PyObject sep)` 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.
`PyTuple` `rpartition(PyObject sep)` 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.
`boolean` `startswith(PyObject prefix, PyObject start, PyObject end)` Equivalent to the Python `unicode.startswith` method, testing whether a string starts with a specified prefix, where a sub-range is specified by `[start:end]`.
`java.lang.String` `substring(int start, int end)` Return a substring of this object as a Java String.
`int[]` `toCodePoints()`

### Methods inherited from class org.python.core.PyString

`__cmp__, __float__, __getnewargs__, __int__, __invert__, __long__, __mul__, __neg__, __pos__, __rmul__, __tojava__, asDouble, asInt, asLong, asName, asString, asString, atoi, atol, capitalize, center, charAt, count, count, count, count, count, count, decode_UnicodeEscape, decode, decode, decode, encode_UnicodeEscape, encode, encode, encode, endswith, endswith, expandtabs, expandtabs, find, find, find, find, find, find, getString, hashCode, index, index, index, index, index, index, internedString, isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace, istitle, isunicode, isupper, length, ljust, ljust, lower, lstrip, lstrip, lstrip, replace, replace, rfind, rfind, rfind, rfind, rfind, rfind, rindex, rindex, rindex, rindex, rindex, rindex, rjust, rsplit, rsplit, rsplit, rsplit, rsplit, rstrip, rstrip, rstrip, split, split, split, split, split, splitlines, splitlines, startswith, startswith, str___mod__, strip, strip, strip, subSequence, swapcase, title, toBytes, toString, translate, translate, translate, translate, upper, zfill`

### Methods inherited from class org.python.core.PySequence

`__delitem__, __delslice__, __finditem__, __finditem__, __getitem__, __getslice__, __iter__, __nonzero__, __setitem__, __setitem__, __setslice__, isMappingType, isNumberType, isSequenceType`

### Methods inherited from class org.python.core.PyObject

`__abs__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __coerce__, __coerce_ex__, __delattr__, __delattr__, __delete__, __delitem__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __floordiv__, __get__, __getattr__, __getattr__, __getitem__, __getslice__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __lshift__, __not__, __oct__, __or__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce__, __reduce_ex__, __reduce_ex__, __rfloordiv__, __rlshift__, __rmod__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __sub__, __truediv__, __trunc__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _doget, _doget, _doset, _eq, _floordiv, _ge, _gt, _iadd, _iand, _idiv, _idivmod, _ifloordiv, _ilshift, _imod, _imul, _in, _ior, _ipow, _irshift, _is, _isnot, _isub, _itruediv, _ixor, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _truediv, _xor, asIndex, asIndex, asInt, asIterable, asLong, asName, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, equals, fastGetClass, fastGetDict, getDict, getType, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Methods inherited from interface java.lang.CharSequence

`chars, codePoints`

### 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(PyType subtype,
                     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

#### toCodePoints

    public int[] toCodePoints()

Overrides:
  `toCodePoints` in class `PyString`

#### getBuffer

    public PyBuffer getBuffer(int flags)
                       throws java.lang.ClassCastException

`PyUnicode` implements the interface `BufferProtocol` technically by inheritance from `PyString`, but does not provide a buffer (in CPython). We therefore arrange that all calls to `getBuffer` raise an error.

Specified by:
  `getBuffer` in interface `BufferProtocol`
Overrides:
  `getBuffer` in class `PyString`
Parameters:
  `flags` - consumer requirements
Returns:
  always throws a `ClassCastException`
Throws:
  `java.lang.ClassCastException` - when the object only formally implements `BufferProtocol`

#### 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 s)

Returns a PyUnicode from an already interned String. Just means it won't be re-interned if used in a place that requires interned Strings.

#### fromString

    public static PyUnicode fromString(java.lang.String s,
                                       boolean isBasic)

Return a not-necessarily new `PyUnicode` from a Java `String`.

Parameters:
  `s` - UTF-16 string encoding the characters (as Java).
  `isBasic` - true if it is known that only BMP characters are present.
Returns:
  a new or re-used `PyUnicode`

#### from

    public static PyUnicode from(char c)

Return a not-necessarily new `PyUnicode` from a Java `char`. Some low index chars (ASCII) return a re-used `PyUnicode`. This method does not assume the character is basic-plane.

Parameters:
  `c` - to convert to a `PyUnicode`.
Returns:
  a new or re-used `PyUnicode`

#### fromCodepoint

    public static PyUnicode fromCodepoint(int codepoint)

Return a not-necessarily new `PyUnicode` from a Java code point.

Parameters:
  `codepoint` - of the single character required
Returns:
  a new or cached `PyUnicode` for the character

#### 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 string)

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:
  `string` - to wrap
Returns:
  instance wrapping `str`

#### __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

#### __unicode__

    public PyUnicode __unicode__()

Overrides:
  `__unicode__` in class `PyString`

#### __str__

    public PyString __str__()

Description copied from class: `PyObject`
Equivalent to the standard Python __str__ method. The default implementation (in `PyObject`) calls `PyObject.__repr__()`, making it unnecessary to override `__str__` in sub-classes of `PyObject` where both forms are the same. A common choice is to provide the same implementation to `__str__` and `toString`, for consistency in the printed form of objects between Python and Java.

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. Each sub-class of `PyObject` is likely to re-define this method to provide for its own reproduction.

Overrides:
  `__repr__` in class `PyString`

#### __eq__

    public PyObject __eq__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __eq__ method.

Overrides:
  `__eq__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### __ne__

    public PyObject __ne__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __ne__ method.

Overrides:
  `__ne__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### __lt__

    public PyObject __lt__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __lt__ method.

Overrides:
  `__lt__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### __le__

    public PyObject __le__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __le__ method.

Overrides:
  `__le__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### __gt__

    public PyObject __gt__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __gt__ method.

Overrides:
  `__gt__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### __ge__

    public PyObject __ge__(PyObject other)

Description copied from class: `PyObject`
Equivalent to the standard Python __ge__ method.

Overrides:
  `__ge__` in class `PyString`
Parameters:
  `other` - the object to compare this with.
Returns:
  the result of the comparison.

#### 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.

#### __contains__

    public boolean __contains__(PyObject o)

Description copied from class: `PyObject`
Equivalent to the standard Python __contains__ method.

Overrides:
  `__contains__` in class `PyString`
Parameters:
  `o` - the element to search for in this container.
Returns:
  the result of the search.

#### __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

#### join

    public PyString join(PyObject seq)

Overrides:
  `join` in class `PyString`

#### startswith

    public boolean startswith(PyObject prefix,
                              PyObject start,
                              PyObject end)

Equivalent to the Python `unicode.startswith` method, testing whether a string starts with a specified prefix, where a sub-range is specified by `[start:end]`. Arguments `start` and `end` are interpreted as in slice notation, with null or `Py.None` representing "missing". `prefix` can also be a tuple of prefixes to look for.

Overrides:
  `startswith` in class `PyString`
Parameters:
  `prefix` - string to check for (or a `PyTuple` of them).
  `start` - start of slice.
  `end` - end of slice.
Returns:
  `true` if this string slice starts with a specified prefix, otherwise `false`.

#### endswith

    public boolean endswith(PyObject suffix,
                            PyObject start,
                            PyObject end)

Equivalent to the Python `unicode.endswith` method, testing whether a string ends with a specified suffix, where a sub-range is specified by `[start:end]`. Arguments `start` and `end` are interpreted as in slice notation, with null or `Py.None` representing "missing". `suffix` can also be a tuple of suffixes to look for.

Overrides:
  `endswith` in class `PyString`
Parameters:
  `suffix` - string to check for (or a `PyTuple` of them).
  `start` - start of slice.
  `end` - end of slice.
Returns:
  `true` if this string slice ends with a specified suffix, otherwise `false`.

#### __format__

    public PyObject __format__(PyObject formatSpec)

Overrides:
  `__format__` in class `PyString`

#### 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`

#### atol

    public PyLong atol(int base)

Overrides:
  `atol` 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