Package 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:
Serializable,CharSequence,Iterable<Integer>,BufferProtocol
- Direct Known Subclasses:
PyUnicodeDerived
a builtin python unicode string.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.python.core.PyObject
PyObject.ConversionException -
Field Summary
FieldsFields inherited from class org.python.core.PyObject
gcMonitorGlobal -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEquivalent to the standard Python __add__ method.Equivalent to the standard Python __complex__ method.booleanEquivalent to the standard Python __contains__ method.Equivalent to the standard Python __eq__ method.__format__(PyObject formatSpec) Equivalent to the standard Python __ge__ method.Equivalent to the standard Python __gt__ method.Equivalent to the standard Python __le__ method.int__len__()Equivalent to the standard Python __len__ method.Equivalent to the standard Python __lt__ method.Equivalent to the standard Python __mod__ methodEquivalent to the standard Python __ne__ method.__repr__()Equivalent to the standard Python__repr__method.__str__()Equivalent to the standard Python __str__ method.doubleatof()Convert this PyString to a floating-point value according to Python rules.intatoi(int base) atol(int base) static StringcreateInstance(String str) Create an instance of the same type as this object, from the Java String given as argument.booleanEquivalent to the Pythonunicode.endswithmethod, testing whether a string ends with a specified suffix, where a sub-range is specified by[start:end].static PyUnicodefromInterned(String interned) Creates a PyUnicode from an already interned String.getBuffer(int flags) PyUnicodeimplements the interfaceBufferProtocoltechnically by inheritance fromPyString, but does not provide a buffer (in CPython).intintgetInt(int i) booleanDetermine whether the string consists entirely of basic-plane characters.iterator()Get an iterator over the code point sequence.newSubsequenceIterator(int start, int stop, int step) Get an iterator over a slice of the code point sequence.Equivalent to Pythonstr.partition(), splits thePyStringat the first occurrence ofsepObjreturning aPyTuplecontaining the part before the separator, the separator itself, and the part after the separator.rpartition(PyObject sep) Equivalent to Pythonstr.rpartition(), splits thePyStringat the last occurrence ofsepObjreturning aPyTuplecontaining the part before the separator, the separator itself, and the part after the separator.booleanstartswith(PyObject prefix, PyObject start, PyObject end) Equivalent to the Pythonunicode.startswithmethod, testing whether a string starts with a specified prefix, where a sub-range is specified by[start:end].substring(int start, int end) Return a substring of this object as a Java String.int[]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, decode, decode, decode_UnicodeEscape, encode, encode, encode, encode_UnicodeEscape, 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, zfillMethods inherited from class org.python.core.PySequence
__delitem__, __delslice__, __finditem__, __finditem__, __getitem__, __getslice__, __iter__, __nonzero__, __setitem__, __setitem__, __setslice__, isMappingType, isNumberType, isSequenceTypeMethods 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, setTypeMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmptyMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
TYPE
-
-
Constructor Details
-
PyUnicode
public PyUnicode() -
PyUnicode
Construct a PyUnicode interpreting the Java String argument as UTF-16.- Parameters:
string- UTF-16 string encoding the characters (as Java).
-
PyUnicode
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
-
PyUnicode
-
PyUnicode
-
PyUnicode
public PyUnicode(char c) -
PyUnicode
public PyUnicode(int codepoint) -
PyUnicode
public PyUnicode(int[] codepoints) -
PyUnicode
-
PyUnicode
-
-
Method Details
-
toCodePoints
public int[] toCodePoints()- Overrides:
toCodePointsin classPyString
-
getBuffer
PyUnicodeimplements the interfaceBufferProtocoltechnically by inheritance fromPyString, but does not provide a buffer (in CPython). We therefore arrange that all calls togetBufferraise an error.- Specified by:
getBufferin interfaceBufferProtocol- Overrides:
getBufferin classPyString- Parameters:
flags- consumer requirements- Returns:
- always throws a
ClassCastException - Throws:
ClassCastException- when the object only formally implementsBufferProtocol
-
substring
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) -
fromInterned
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 aPyString, of course, it is alwaystrue, but this is useful in cases where either aPyStringor aPyUnicodeis acceptable.- Overrides:
isBasicPlanein classPyString- Returns:
- true if the string consists only of BMP characters
-
getCodePointCount
public int getCodePointCount() -
checkEncoding
-
createInstance
Description copied from class:PyStringCreate 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:
createInstancein classPyString- Parameters:
str- to wrap- Returns:
- instance wrapping
str
-
__mod__
Description copied from class:PyObjectEquivalent to the standard Python __mod__ method -
__unicode__
- Overrides:
__unicode__in classPyString
-
__str__
Description copied from class:PyObjectEquivalent to the standard Python __str__ method. The default implementation (inPyObject) callsPyObject.__repr__(), making it unnecessary to override__str__in sub-classes ofPyObjectwhere both forms are the same. A common choice is to provide the same implementation to__str__andtoString, for consistency in the printed form of objects between Python and Java. -
__len__
public int __len__()Description copied from class:PyObjectEquivalent to the standard Python __len__ method. Part of the mapping discipline. -
__repr__
Description copied from class:PyObjectEquivalent to the standard Python__repr__method. Each sub-class ofPyObjectis likely to re-define this method to provide for its own reproduction. -
__eq__
Description copied from class:PyObjectEquivalent to the standard Python __eq__ method. -
__ne__
Description copied from class:PyObjectEquivalent to the standard Python __ne__ method. -
__lt__
Description copied from class:PyObjectEquivalent to the standard Python __lt__ method. -
__le__
Description copied from class:PyObjectEquivalent to the standard Python __le__ method. -
__gt__
Description copied from class:PyObjectEquivalent to the standard Python __gt__ method. -
__ge__
Description copied from class:PyObjectEquivalent to the standard Python __ge__ method. -
getInt
public int getInt(int i) -
newSubsequenceIterator
Get an iterator over the code point sequence. -
newSubsequenceIterator
Get an iterator over a slice of the code point sequence. -
__contains__
Description copied from class:PyObjectEquivalent to the standard Python __contains__ method.- Overrides:
__contains__in classPyString- Parameters:
o- the element to search for in this container.- Returns:
- the result of the search.
-
__add__
Description copied from class:PyString -
partition
Description copied from class:PyStringEquivalent to Pythonstr.partition(), splits thePyStringat the first occurrence ofsepObjreturning aPyTuplecontaining the part before the separator, the separator itself, and the part after the separator.- Overrides:
partitionin classPyString- Parameters:
sep- str, unicode or object implementingBufferProtocol- Returns:
- tuple of parts
-
rpartition
Description copied from class:PyStringEquivalent to Pythonstr.rpartition(), splits thePyStringat the last occurrence ofsepObjreturning aPyTuplecontaining the part before the separator, the separator itself, and the part after the separator.- Overrides:
rpartitionin classPyString- Parameters:
sep- str, unicode or object implementingBufferProtocol- Returns:
- tuple of parts
-
join
-
startswith
Equivalent to the Pythonunicode.startswithmethod, testing whether a string starts with a specified prefix, where a sub-range is specified by[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing".prefixcan also be a tuple of prefixes to look for.- Overrides:
startswithin classPyString- Parameters:
prefix- string to check for (or aPyTupleof them).start- start of slice.end- end of slice.- Returns:
trueif this string slice starts with a specified prefix, otherwisefalse.
-
endswith
Equivalent to the Pythonunicode.endswithmethod, testing whether a string ends with a specified suffix, where a sub-range is specified by[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing".suffixcan also be a tuple of suffixes to look for. -
__format__
- Overrides:
__format__in classPyString
-
iterator
-
__complex__
Description copied from class:PyObjectEquivalent 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 classPyString- Returns:
- a complex number corresponding to the value of this object.
-
atoi
public int atoi(int base) -
atol
-
atof
public double atof()Description copied from class:PyStringConvert this PyString to a floating-point value according to Python rules.
-