Top Description Inners Fields Constructors Methods
org.python.core

public Class PyUnicode

extends PyString
implements Iterable<Integer>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Known Direct Subclasses
org.python.core.PyUnicodeDerived
Annotations
@Untraversable
@ExposedType
name:unicode
base:PyBaseString
doc:unicode(object=\'\') -> unicode object unicode(string[, encoding[, errors]]) -> unicode object Create a new Unicode object from the given encoded string. encoding defaults to the current default string encoding. errors can be \'strict\', \'replace\' or \'ignore\' and defaults to \'strict\'.
Imports
java.io.Serializable, java.util.Collection, .Collections, .Iterator, .LinkedList, .List, .Set, org.python.core.stringlib.FieldNameIterator, .MarkupIterator, org.python.expose.ExposedMethod, .ExposedNew, .ExposedType, .MethodType, org.python.modules._codecs, org.python.util.Generic, com.google.common.base.CharMatcher

a builtin python unicode string.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
PyUnicode.IndexTranslator

Index translation between code point index (as seen by Python) and UTF-16 index (as used in the Java String.

private class
private static class
private static class
private class
private abstract class
private static class
private static class
private class
PyUnicode.SubsequenceIteratorBasic

An iterator returning code points from this array, for use when basic plane.

private class
PyUnicode.SubsequenceIteratorImpl

An iterator returning code points from this array, for use when not basic plane.

private class
PyUnicode.Supplementary

A class of index translation that uses the cumulative count so far of supplementary characters, tabulated in blocks of a standard size.

private class

Field Summary

Modifier and TypeField and Description
pack-priv static final PyUnicode.IndexTranslator
BASIC

A singleton provides the translation service (which is a pass-through) for all BMP strings.

private static final boolean
DEBUG_NON_BMP_METHODS

Nearly every significant method comes in two versions: one applicable when the string contains only basic plane characters, and one that is correct when supplementary characters are also present.

private final PyUnicode.IndexTranslator
translator

The instance of index translation in use in this string.

public static final PyType
private static final PyUnicode[]
unichars

Table used by from(char) to intern single byte strings.

Inherited from org.python.core.PyString:
internedstring

Constructor Summary

AccessConstructor and Description
public
public
PyUnicode(String
UTF-16 string encoding the characters (as Java).
string
)

Construct a PyUnicode interpreting the Java String argument as UTF-16.

public
PyUnicode(String
UTF-16 string encoding the characters (as Java).
string
,
boolean
true if it is known that only BMP characters are present.
isBasic
)

Construct a PyUnicode interpreting the Java String argument as UTF-16.

public
PyUnicode(PyType subtype, String string)

public
PyUnicode(PyString pystring)

public
PyUnicode(PyType subtype, PyString pystring)

public
PyUnicode(char c)

public
PyUnicode(int codepoint)

public
PyUnicode(int[] codepoints)

pack-priv
public
public
private
PyUnicode(PyType
actual type to create.
subtype
,
String
UTF-16 string encoding the characters (as Java).
string
,
boolean
true if it is known that only BMP characters are present.
isBasic
)

Fundamental all-features constructor on which the others depend.

Method Summary

Modifier and TypeMethod and Description
public PyObject
__add__(PyObject
the object to perform this binary operation with (the right-hand operand).
other
)

Overrides org.python.core.PyString.__add__.

Equivalent to the standard Python __add__ method.

public PyComplex
__complex__()

Overrides org.python.core.PyString.__complex__.

Equivalent to the standard Python __complex__ method.

public boolean
__contains__(PyObject
the element to search for in this container.
o
)

Overrides org.python.core.PyString.__contains__.

Equivalent to the standard Python __contains__ method.

public PyObject
__eq__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__eq__.

Equivalent to the standard Python __eq__ method.

public PyObject
public PyObject
__ge__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__ge__.

Equivalent to the standard Python __ge__ method.

public PyObject
__gt__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__gt__.

Equivalent to the standard Python __gt__ method.

public PyObject
__le__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__le__.

Equivalent to the standard Python __le__ method.

public int
__len__()

Overrides org.python.core.PyString.__len__.

Equivalent to the standard Python __len__ method.

public PyObject
__lt__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__lt__.

Equivalent to the standard Python __lt__ method.

public PyObject
__mod__(PyObject
the object to perform this binary operation with (the right-hand operand).
other
)

Overrides org.python.core.PyString.__mod__.

Equivalent to the standard Python __mod__ method

public PyObject
__ne__(PyObject
the object to compare this with.
other
)

Overrides org.python.core.PyString.__ne__.

Equivalent to the standard Python __ne__ method.

public PyString
__repr__()

Overrides org.python.core.PyString.__repr__.

Equivalent to the standard Python __repr__ method.

public PyString
__str__()

Overrides org.python.core.PyString.__str__.

Equivalent to the standard Python __str__ method.

public PyUnicode
protected int
_findLeft(int
rightmost extent of string search
right
)

Overrides org.python.core.PyString._findLeft.

Helper for strip, lstrip implementation, when stripping whitespace.

protected int
_findRight()

Overrides org.python.core.PyString._findRight.

Helper for strip, rstrip implementation, when stripping whitespace.

public double
atof()

Overrides org.python.core.PyString.atof.

Convert this PyString to a floating-point value according to Python rules.

public int
atoi(int base)

Overrides org.python.core.PyString.atoi.

public PyLong
atol(int base)

Overrides org.python.core.PyString.atol.

private static int

Returns:

2 if a surrogate pair stands at p, 1 if not
calcAdvance
(String
of UTF-16 code units
string
,
int
index into that string
p
)

Called at each code point index, returns 2 if this is a surrogate pair, 1 otherwise, and detects lone surrogates as an error.

private static String

Returns:

String from codepoint
checkedCPString
(int
to translate
codePoint
)

Translate a code point to a Java String, guaranteeing validity.

private static String

Returns:

String from codepoint
checkedCPString
(int[]
to translate
codePoints
)

Translate a code point to a Java String, guaranteeing validity.

public static String
private PyUnicode.IndexTranslator

Returns:

chosen IndexTranslator
chooseIndexTranslator
()

Choose an IndexTranslator implementation for efficient working, according to the contents of the PyString#string.

private static String

Returns:

an equivalent String
coerceForComparison
(PyObject
the object to coerce
o
)

Interpret the object as a Java String for use in comparison.

private static PyUnicode

Returns:

an equivalent PyUnicode (or o itself, or null)
coerceStripSepToUnicode
(PyObject
the object to coerce
o
,
String
of method
name
)

Helper used in .strip() to "coerce" a method argument into a PyUnicode (which it may already be).

private static String

Returns:

an equivalent String (and never null)
coerceToString
(PyObject
the object to coerce
o
)

Interpret the object as a Java String representing characters as UTF-16, or raise an error if the type does not admit this conversion.

private static String

Returns:

an equivalent String or null
coerceToString
(PyObject
the object to coerce
o
,
boolean
iff true allow a null or none argument
allowNullArgument
)

Interpret the object as a Java String representing characters as UTF-16, or optionally as null (for a null or None argument if the second argument is true).

private static String

Returns:

an equivalent String
coerceToStringOrNull
(PyObject
the object to coerce
o
)

Interpret the object as a Java String representing characters as UTF-16, or return null if the type does not admit this conversion.

private static PyUnicode

Returns:

an equivalent PyUnicode (or o itself)
coerceToUnicode
(PyObject
the object to coerce
o
)

Interpret the object as a PyUnicode, or raise a TypeError if the type does not admit this conversion.

private static PyUnicode

Returns:

an equivalent PyUnicode (or o itself)
coerceToUnicodeOrNull
(PyObject
the object to coerce
o
)

Interpret the object as a PyUnicode, or return null if the type does not admit this conversion.

public PyString
createInstance(String
to wrap
string
)

Overrides org.python.core.PyString.createInstance.

Create an instance of the same type as this object, from the Java String given as argument.

protected PyString
createInstance(String
UTF-16 string encoding the characters (as Java).
string
,
boolean
true if it is known that only BMP characters are present.
isBasic
)

Overrides org.python.core.PyString.createInstance.

Create an instance of the same type as this object, from the Java String given as argument.

private String

Returns:

a valid decimal as an encoded String
encodeDecimal
()

Encode unicode into a valid decimal String.

private String

Returns:

a valid decimal as an encoded String
encodeDecimalBasic
()

Encode unicode in the basic plane into a valid decimal String.

public boolean

Returns:

true if this string slice ends with a specified suffix, otherwise false.
endswith
(PyObject
string to check for (or a PyTuple of them).
suffix
,
PyObject
start of slice.
start
,
PyObject
end of slice.
end
)

Overrides org.python.core.PyString.endswith.

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

private static PyException
errorCoercingToUnicode(PyObject o)

Construct exception "coercing to Unicode: ..."

public static PyUnicode

Returns:

a new or re-used PyUnicode
from
(char
to convert to a PyUnicode.
c
)

Return a not-necessarily new PyUnicode from a Java char.

public static PyUnicode

Returns:

a new or cached PyUnicode for the character
fromCodepoint
(int
of the single character required
codepoint
)

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

private static StringBuilder
public static PyUnicode
fromInterned(String
String representing bytes
s
)

Hides org.python.core.PyString.fromInterned.

Returns a PyUnicode from an already interned String.

public static PyUnicode

Returns:

a new or re-used PyUnicode
fromString
(String
UTF-16 string encoding the characters (as Java).
s
,
boolean
true if it is known that only BMP characters are present.
isBasic
)

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

protected PyString
fromSubstring(int
first included character.
begin
,
int
first excluded character.
end
)

Overrides org.python.core.PyString.fromSubstring.

Return a new object of the same type as this one equal to the slice [begin:end].

public synchronized PyBuffer

Returns:

always throws a ClassCastException
getBuffer
(int
consumer requirements
flags
)

Overrides org.python.core.PyString.getBuffer.

Implements org.python.core.BufferProtocol.getBuffer.

PyUnicode implements the interface BufferProtocol technically by inheritance from PyString, but does not provide a buffer (in CPython).

public int
public int
protected PyObject
getslice(int
the position of the first element.
start
,
int
one more than the position of the last element.
stop
,
int
the step size.
step
)

Overrides org.python.core.PyString.getslice.

Returns a range of elements from the sequence.

private static int[]

Returns:

the index (counts) or null if basic plane
getSupplementaryCounts
(final String
to index
string
)

Generate the table that is used by the class Supplementary to accelerate access to the the implementation string.

public boolean

Returns:

true if the string consists only of BMP characters
isBasicPlane
()

Overrides org.python.core.PyString.isBasicPlane.

Determine whether the string consists entirely of basic-plane characters.

private static boolean
isPythonSpace(int ch)

Define what characters are to be treated as a space according to Python 2.

public Iterator<Integer>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public PyString
private PyUnicode.SplitIterator
newSplitIterator(PyUnicode sep, int maxsplit)

public Iterator<Integer>
newSubsequenceIterator()

Get an iterator over the code point sequence.

public Iterator<Integer>
newSubsequenceIterator(int start, int stop, int step)

Get an iterator over a slice of the code point sequence.

private static String
padding(int n, int pad)

private static int
public PyTuple
partition(PyObject
str, unicode or object implementing BufferProtocol
sep
)

Overrides org.python.core.PyString.partition.

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.

protected PyObject
pyget(int
index of element to return.
i
)

Overrides org.python.core.PyString.pyget.

Returns the element of the sequence at the given index.

public PyTuple
rpartition(PyObject
str, unicode or object implementing BufferProtocol
sep
)

Overrides org.python.core.PyString.rpartition.

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.

protected PyList
rsplitfields(int
limit on the number of splits (if >=0)
maxsplit
)

Overrides org.python.core.PyString.rsplitfields.

Helper function for .rsplit, in str and (when overridden) in unicode, splitting on white space and returning a list of the separated parts.

protected PyList
splitfields(int
limit on the number of splits (if >=0)
maxsplit
)

Overrides org.python.core.PyString.splitfields.

Helper function for .split, in str and (when overridden) in unicode, splitting on white space and returning a list of the separated parts.

public boolean

Returns:

true if this string slice starts with a specified prefix, otherwise false.
startswith
(PyObject
string to check for (or a PyTuple of them).
prefix
,
PyObject
start of slice.
start
,
PyObject
end of slice.
end
)

Overrides org.python.core.PyString.startswith.

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

public String
substring(int
the beginning index, inclusive.
start
,
int
the ending index, exclusive.
end
)

Overrides org.python.core.PyString.substring.

Return a substring of this object as a Java String.

public int[]
protected int[]
translateIndices(PyObject
Python start of slice
start
,
PyObject
Python end of slice
end
)

Overrides org.python.core.PyString.translateIndices.

Many of the string methods deal with slices specified using Python slice semantics: endpoints, which are PyObjects, may be null or None (meaning default to one end or the other) or may be negative (meaning "from the end").

pack-priv final PyObject
pack-priv final int
pack-priv final boolean
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyTuple
pack-priv final PyObject
pack-priv final PyObject
pack-priv final int
pack-priv final PyObject
pack-priv final int
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyString
pack-priv final PyObject
pack-priv final PyString
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
unicode_center(int width, String padding)

pack-priv final int
pack-priv final PyObject
unicode_decode(PyObject[] args, String[] keywords)

pack-priv final String
unicode_encode(PyObject[] args, String[] keywords)

pack-priv final boolean
unicode_endswith(PyObject suffix, PyObject startObj, PyObject endObj)

pack-priv final PyObject
unicode_expandtabs(int tabsize)

pack-priv final int
unicode_find(PyObject subObj, PyObject start, PyObject end)

pack-priv final PyObject
unicode_format(PyObject[] args, String[] keywords)

pack-priv final int
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean
pack-priv final PyUnicode
pack-priv final PyObject
unicode_ljust(int width, String padding)

pack-priv final PyObject
pack-priv final PyObject
pack-priv static final PyObject
unicode_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords)

pack-priv final PyTuple
pack-priv final PyString
unicode_replace(PyObject oldPieceObj, PyObject newPieceObj, int count)

pack-priv final int
pack-priv final int
pack-priv final PyObject
unicode_rjust(int width, String padding)

pack-priv final PyTuple
pack-priv final PyList
unicode_rsplit(PyObject sepObj, int maxsplit)

pack-priv final PyObject
pack-priv final PyList
unicode_split(PyObject sepObj, int maxsplit)

pack-priv final PyList
unicode_splitlines(boolean keepends)

pack-priv final boolean
unicode_startswith(PyObject prefix, PyObject startObj, PyObject endObj)

pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
pack-priv final PyObject
unicode_zfill(int width)

private static PyException

Returns:

an exception
unpairedSurrogate
(int
index within that sequence of the problematic code unit
p
,
int
the code unit
c
)

Return a ready-to-throw exception indicating an unpaired surrogate.

Inherited from org.python.core.PyString:
__cmp____float____getnewargs____int____invert____long____mul____neg____pos____rmul____tojava___count_find_lstrip_lstrip_replace_rfind_rsplit_rstrip_rstrip_split_strip_stripasDoubleasIntasLongasNameasStringasStringasU16BytesOrErroratoiatolbuildFormattedStringcapitalizecentercharAtcharsFitWidthcheckIndexcountcountcountcountcountcountdecodedecodedecodedecode_UnicodeEscapeencodeencodeencodeencode_UnicodeEscapeencode_UnicodeEscapeendswithendswithexpandtabsexpandtabsfindfindfindfindfindfindgetStringhashCodeindexindexindexindexindexindexinternedStringisalnumisalphaisdecimalisdigitislowerisnumericisspaceistitleisunicodeisupperlengthljustljustlowerlstriplstriplstripprepareFormatterrepeatreplacereplacerfindrfindrfindrfindrfindrfindrindexrindexrindexrindexrindexrindexrjustrsplitrsplitrsplitrsplitrsplitrstriprstriprstripsplitsplitsplitsplitsplitsplitlinessplitlinesstartswithstartswithstr___add__str___cmp__str___contains__str___eq__str___format__str___ge__str___getitem__str___getnewargs__str___getslice__str___gt__str___hash__str___le__str___len__str___lt__str___mod__str___mul__str___ne__str___repr__str___rmul__str___str__str__formatter_field_name_splitstr__formatter_parserstr_capitalizestr_centerstr_countstr_decodestr_encodestr_endswithstr_expandtabsstr_findstr_formatstr_indexstr_isalnumstr_isalphastr_isdecimalstr_isdigitstr_islowerstr_isnumericstr_isspacestr_istitlestr_isunicodestr_isupperstr_joinstr_ljuststr_lowerstr_lstripstr_newstr_partitionstr_replacestr_rfindstr_rindexstr_rjuststr_rpartitionstr_rsplitstr_rstripstr_splitstr_splitlinesstr_startswithstr_stripstr_swapcasestr_titlestr_translatestr_upperstr_zfillstripstripstripsubSequenceswapcasetitletoBytestoStringtranslatetranslatetranslatetranslateunicodeJoinunicodePartitionunicodeRpartitionunsupportedopMessageupperzfill