Package org.python.core
Class PyString
- java.lang.Object
-
- org.python.core.PyObject
-
- org.python.core.PySequence
-
- org.python.core.PyBaseString
-
- org.python.core.PyString
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,BufferProtocol
- Direct Known Subclasses:
PyShadowString,PyStringDerived,PyUnicode,SyspathArchive
public class PyString extends PyBaseString implements BufferProtocol
A builtin python string.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.python.core.PyObject
PyObject.ConversionException
-
-
Field Summary
Fields Modifier and Type Field Description static PyTypeTYPE-
Fields inherited from class org.python.core.PyObject
gcMonitorGlobal
-
-
Constructor Summary
Constructors Constructor Description PyString()PyString(char c)PyString(java.lang.String string)PyString(PyType subType, java.lang.String string)Fundamental constructor forPyStringobjects when the client provides a JavaString, necessitating that we range check the characters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PyObject__add__(PyObject other)Equivalent to the standard Python __add__ method.int__cmp__(PyObject other)Equivalent to the standard Python __cmp__ 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.PyFloat__float__()Equivalent to the standard Python __float__ method.PyObject__format__(PyObject formatSpec)PyObject__ge__(PyObject other)Equivalent to the standard Python __ge__ method.PyTuple__getnewargs__()PyObject__gt__(PyObject other)Equivalent to the standard Python __gt__ method.PyObject__int__()Equivalent to the standard Python __int__ method.PyObject__invert__()Equivalent to the standard Python __invert__ method.PyObject__le__(PyObject other)Equivalent to the standard Python __le__ method.int__len__()Equivalent to the standard Python __len__ method.PyObject__long__()Equivalent to the standard Python __long__ method.PyObject__lt__(PyObject other)Equivalent to the standard Python __lt__ method.PyObject__mod__(PyObject other)Equivalent to the standard Python __mod__ methodPyObject__mul__(PyObject o)Equivalent to the standard Python __mul__ method.PyObject__ne__(PyObject other)Equivalent to the standard Python __ne__ method.PyObject__neg__()Equivalent to the standard Python __neg__ method.PyObject__pos__()Equivalent to the standard Python __pos__ method.PyString__repr__()Equivalent to the standard Python__repr__method.PyObject__rmul__(PyObject o)Equivalent to the standard Python __rmul__ method.PyString__str__()Equivalent to the standard Python __str__ method.java.lang.Object__tojava__(java.lang.Class<?> c)Equivalent to the Jython __tojava__ method.PyUnicode__unicode__()doubleasDouble()Convert this object into a double.intasInt()Convert this object into an int.longasLong()Convert this object longo an long.java.lang.StringasName(int index)java.lang.StringasString()java.lang.StringasString(int index)doubleatof()Convert this PyString to a floating-point value according to Python rules.intatoi()intatoi(int base)PyLongatol()PyLongatol(int base)java.lang.Stringcapitalize()java.lang.Stringcenter(int width)charcharAt(int index)intcount(java.lang.String sub)Equivalent tocount(PyObject)specialized toString.intcount(java.lang.String sub, PyObject start)Equivalent tocount(PyObject, PyObject)specialized toString.intcount(java.lang.String sub, PyObject start, PyObject end)Equivalent tocount(PyObject, PyObject, PyObject)specialized toString.intcount(PyObject sub)Return the number of non-overlapping occurrences of substringsub.intcount(PyObject sub, PyObject start)Return the number of non-overlapping occurrences of substringsubin the range[start:].intcount(PyObject sub, PyObject start, PyObject end)Return the number of non-overlapping occurrences of substringsubin the range[start:end].PyStringcreateInstance(java.lang.String str)Create an instance of the same type as this object, from the Java String given as argument.PyObjectdecode()PyObjectdecode(java.lang.String encoding)PyObjectdecode(java.lang.String encoding, java.lang.String errors)static java.lang.Stringdecode_UnicodeEscape(java.lang.String str, int start, int end, java.lang.String errors, boolean unicode)java.lang.Stringencode()java.lang.Stringencode(java.lang.String encoding)java.lang.Stringencode(java.lang.String encoding, java.lang.String errors)static java.lang.Stringencode_UnicodeEscape(java.lang.String str, boolean use_quotes)booleanendswith(PyObject suffix)Equivalent to the Pythonstr.endswithmethod, testing whether a string ends with a specified suffix.booleanendswith(PyObject suffix, PyObject start)Equivalent to the Pythonstr.endswithmethod, testing whether a string ends with a specified suffix, where a sub-range is specified by[start:].booleanendswith(PyObject suffix, PyObject start, PyObject end)Equivalent to the Pythonstr.endswithmethod, testing whether a string ends with a specified suffix, where a sub-range is specified by[start:end].java.lang.Stringexpandtabs()java.lang.Stringexpandtabs(int tabsize)intfind(java.lang.String sub)Equivalent tofind(PyObject)specialized toString.intfind(java.lang.String sub, PyObject start)Equivalent tofind(PyObject, PyObject)specialized toString.intfind(java.lang.String sub, PyObject start, PyObject end)Equivalent tofind(PyObject, PyObject, PyObject)specialized toString.intfind(PyObject sub)Return the lowest index in the string where substringsubis found.intfind(PyObject sub, PyObject start)Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:].intfind(PyObject sub, PyObject start, PyObject end)Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:end].static PyStringfromInterned(java.lang.String interned)Creates a PyString from an already interned String.PyBuffergetBuffer(int flags)Return a read-only buffer view of the contents of the string, treating it as a sequence of unsigned bytes.intgetInt(int i)java.lang.StringgetString()inthashCode()intindex(java.lang.String sub)Equivalent toindex(PyObject)specialized toString.intindex(java.lang.String sub, PyObject start)Equivalent toindex(PyObject, PyObject)specialized toString.intindex(java.lang.String sub, PyObject start, PyObject end)Equivalent toindex(PyObject, PyObject, PyObject)specialized toString.intindex(PyObject sub)Return the lowest index in the string where substringsubis found.intindex(PyObject sub, PyObject start)Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:].intindex(PyObject sub, PyObject start, PyObject end)Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:end].java.lang.StringinternedString()booleanisalnum()booleanisalpha()booleanisBasicPlane()Determine whether the string consists entirely of basic-plane characters.booleanisdecimal()booleanisdigit()booleanislower()booleanisnumeric()booleanisspace()booleanistitle()booleanisunicode()booleanisupper()PyStringjoin(PyObject seq)intlength()java.lang.Stringljust(int width)java.lang.Stringljust(int width, java.lang.String padding)java.lang.Stringlower()java.lang.Stringlstrip()Equivalent of Pythonstr.lstrip()with no argument, meaning strip whitespace.java.lang.Stringlstrip(java.lang.String stripChars)Equivalent of Pythonstr.lstrip().PyObjectlstrip(PyObject stripChars)Equivalent of Pythonstr.lstrip().PyTuplepartition(PyObject sepObj)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.PyStringreplace(PyObject oldPiece, PyObject newPiece)Equivalent to Python str.replace(old, new), returning a copy of the string with all occurrences of substring old replaced by new.PyStringreplace(PyObject oldPiece, PyObject newPiece, int count)Equivalent to Python str.replace(old, new[, count]), returning a copy of the string with all occurrences of substring old replaced by new.intrfind(java.lang.String sub)Equivalent tofind(PyObject)specialized toString.intrfind(java.lang.String sub, PyObject start)Equivalent tofind(PyObject, PyObject)specialized toString.intrfind(java.lang.String sub, PyObject start, PyObject end)Equivalent tofind(PyObject, PyObject, PyObject)specialized toString.intrfind(PyObject sub)Return the highest index in the string where substringsubis found.intrfind(PyObject sub, PyObject start)Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:].intrfind(PyObject sub, PyObject start, PyObject end)Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:end].intrindex(java.lang.String sub)Equivalent torindex(PyObject)specialized toString.intrindex(java.lang.String sub, PyObject start)Equivalent torindex(PyObject, PyObject)specialized toString.intrindex(java.lang.String sub, PyObject start, PyObject end)Equivalent torindex(PyObject, PyObject, PyObject)specialized toString.intrindex(PyObject sub)Return the highest index in the string where substringsubis found.intrindex(PyObject sub, PyObject start)Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:].intrindex(PyObject sub, PyObject start, PyObject end)Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:end].java.lang.Stringrjust(int width)PyTuplerpartition(PyObject sepObj)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.PyListrsplit()Equivalent to Pythonstr.rsplit(), splitting on runs of whitespace.PyListrsplit(java.lang.String sep)Equivalent to Pythonstr.rsplit(), splitting on a specified string.PyListrsplit(java.lang.String sep, int maxsplit)Equivalent to Pythonstr.rsplit(), splitting on a specified string.PyListrsplit(PyObject sep)PyListrsplit(PyObject sep, int maxsplit)Asrsplit(PyObject)but ifmaxsplit>=0 and there are more feasible splits thanmaxsplitthe last element of the list contains the rest of the string.java.lang.Stringrstrip()Equivalent of Pythonstr.rstrip()with no argument, meaning strip whitespace.java.lang.Stringrstrip(java.lang.String stripChars)Equivalent of Pythonstr.rstrip().PyObjectrstrip(PyObject stripChars)Equivalent of Pythonstr.rstrip().PyListsplit()Equivalent to Pythonstr.split(), splitting on runs of whitespace.PyListsplit(java.lang.String sep)Equivalent to Pythonstr.split(), splitting on a specified string.PyListsplit(java.lang.String sep, int maxsplit)Equivalent to Pythonstr.split(), splitting on a specified string.PyListsplit(PyObject sep)PyListsplit(PyObject sep, int maxsplit)Assplit(PyObject)but ifmaxsplit>=0 and there are more feasible splits thanmaxsplit, the last element of the list contains the rest of the string.PyListsplitlines()PyListsplitlines(boolean keepends)booleanstartswith(PyObject prefix)Equivalent to the Pythonstr.startswithmethod testing whether a string starts with a specified prefix.booleanstartswith(PyObject prefix, PyObject start)Equivalent to the Pythonstr.startswithmethod, testing whether a string starts with a specified prefix, where a sub-range is specified by[start:].booleanstartswith(PyObject prefix, PyObject start, PyObject end)Equivalent to the Pythonstr.startswithmethod, testing whether a string starts with a specified prefix, where a sub-range is specified by[start:end].PyObjectstr___mod__(PyObject other)java.lang.Stringstrip()Equivalent of Pythonstr.strip()with no argument, meaning strip whitespace.java.lang.Stringstrip(java.lang.String stripChars)Equivalent of Pythonstr.strip().PyObjectstrip(PyObject stripChars)Equivalent of Pythonstr.strip().java.lang.CharSequencesubSequence(int start, int end)java.lang.Stringsubstring(int start, int end)Return a substring of this object as a Java String.java.lang.Stringswapcase()java.lang.Stringtitle()byte[]toBytes()int[]toCodePoints()java.lang.StringtoString()java.lang.Stringtranslate(java.lang.String table)Equivalent totranslate(PyObject)specialized toString.java.lang.Stringtranslate(java.lang.String table, java.lang.String deletechars)Equivalent totranslate(PyObject, PyObject)specialized toString.java.lang.Stringtranslate(PyObject table)Equivalent to Pythonstr.translatereturning a copy of this string where the characters have been mapped through the translationtable.java.lang.Stringtranslate(PyObject table, PyObject deletechars)Equivalent to Pythonstr.translatereturning a copy of this string where all characters (bytes) occurring in the argumentdeletecharsare removed (if it is notnull), and the remaining characters have been mapped through the translationtable.java.lang.Stringupper()java.lang.Stringzfill(int width)-
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
-
-
-
-
Field Detail
-
TYPE
public static final PyType TYPE
-
-
Constructor Detail
-
PyString
public PyString()
-
PyString
public PyString(PyType subType, java.lang.String string)
Fundamental constructor forPyStringobjects when the client provides a JavaString, necessitating that we range check the characters.- Parameters:
subType- the actual type being constructedstring- a Java String to be wrapped
-
PyString
public PyString(java.lang.String string)
-
PyString
public PyString(char c)
-
-
Method Detail
-
getString
public java.lang.String getString()
-
fromInterned
public static PyString fromInterned(java.lang.String interned)
Creates a PyString 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.- Returns:
- true
-
toCodePoints
public int[] toCodePoints()
-
getBuffer
public PyBuffer getBuffer(int flags)
Return a read-only buffer view of the contents of the string, treating it as a sequence of unsigned bytes. The caller specifies its requirements and navigational capabilities in theflagsargument (see the constants in interfacePyBUFfor an explanation). The method may return the same PyBuffer object to more than one consumer.- Specified by:
getBufferin interfaceBufferProtocol- Parameters:
flags- consumer requirements- Returns:
- the requested buffer
-
substring
public java.lang.String substring(int start, int end)Return a substring of this object as a Java String.- Parameters:
start- the beginning index, inclusive.end- the ending index, exclusive.- Returns:
- the specified substring.
-
__str__
public PyString __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.
-
__unicode__
public PyUnicode __unicode__()
- Overrides:
__unicode__in classPyObject
-
__len__
public int __len__()
Description copied from class:PyObjectEquivalent to the standard Python __len__ method. Part of the mapping discipline.
-
toString
public java.lang.String toString()
-
internedString
public java.lang.String internedString()
-
__repr__
public PyString __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.
-
encode_UnicodeEscape
public static java.lang.String encode_UnicodeEscape(java.lang.String str, boolean use_quotes)
-
decode_UnicodeEscape
public static java.lang.String decode_UnicodeEscape(java.lang.String str, int start, int end, java.lang.String errors, boolean unicode)
-
__cmp__
public int __cmp__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __cmp__ method.
-
__eq__
public PyObject __eq__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __eq__ method.- Overrides:
__eq__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
__ne__
public PyObject __ne__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __ne__ method.- Overrides:
__ne__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
__lt__
public PyObject __lt__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __lt__ method.- Overrides:
__lt__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
__le__
public PyObject __le__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __le__ method.- Overrides:
__le__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
__gt__
public PyObject __gt__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __gt__ method.- Overrides:
__gt__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
__ge__
public PyObject __ge__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __ge__ method.- Overrides:
__ge__in classPySequence- Parameters:
other- the object to compare this with.- Returns:
- the result of the comparison.
-
toBytes
public byte[] toBytes()
- Returns:
- a byte array with one byte for each char in this object's underlying String. Each byte contains the low-order bits of its corresponding char.
-
__tojava__
public java.lang.Object __tojava__(java.lang.Class<?> c)
Description copied from class:PyObjectEquivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special objectPy.NoConversionif thisPyObjectcan not be converted to the desired Java class.- Overrides:
__tojava__in classPySequence- Parameters:
c- the Class to convert thisPyObjectto.
-
getInt
public int getInt(int i)
-
createInstance
public PyString createInstance(java.lang.String str)
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.- Parameters:
str- to wrap- Returns:
- instance wrapping
str
-
__contains__
public boolean __contains__(PyObject o)
Description copied from class:PyObjectEquivalent to the standard Python __contains__ method.- Overrides:
__contains__in classPyObject- Parameters:
o- the element to search for in this container.- Returns:
- the result of the search.
-
__mul__
public PyObject __mul__(PyObject o)
Description copied from class:PyObjectEquivalent to the standard Python __mul__ method.
-
__rmul__
public PyObject __rmul__(PyObject o)
Description copied from class:PyObjectEquivalent to the standard Python __rmul__ method.
-
__getnewargs__
public PyTuple __getnewargs__()
- Overrides:
__getnewargs__in classPyObject
-
__mod__
public PyObject __mod__(PyObject other)
Description copied from class:PyObjectEquivalent to the standard Python __mod__ method
-
__int__
public PyObject __int__()
Description copied from class:PyObjectEquivalent to the standard Python __int__ method. Should only be overridden by numeric objects that can be reasonably coerced into an integer.
-
__long__
public PyObject __long__()
Description copied from class:PyObjectEquivalent to the standard Python __long__ method. Should only be overridden by numeric objects that can be reasonably coerced into a python long.
-
__float__
public PyFloat __float__()
Description copied from class:PyObjectEquivalent to the standard Python __float__ method. Should only be overridden by numeric objects that can be reasonably coerced into a python float.
-
__pos__
public PyObject __pos__()
Description copied from class:PyObjectEquivalent to the standard Python __pos__ method.
-
__neg__
public PyObject __neg__()
Description copied from class:PyObjectEquivalent to the standard Python __neg__ method.
-
__invert__
public PyObject __invert__()
Description copied from class:PyObjectEquivalent to the standard Python __invert__ method.- Overrides:
__invert__in classPyObject- Returns:
- ~this.
-
__complex__
public PyComplex __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 classPyObject- Returns:
- a complex number corresponding to the value of this object.
-
lower
public java.lang.String lower()
-
upper
public java.lang.String upper()
-
title
public java.lang.String title()
-
swapcase
public java.lang.String swapcase()
-
strip
public java.lang.String strip()
Equivalent of Pythonstr.strip()with no argument, meaning strip whitespace. Any whitespace byte/character will be discarded from either end of thisstr.- Returns:
- a new String, stripped of the whitespace characters/bytes
-
strip
public java.lang.String strip(java.lang.String stripChars)
Equivalent of Pythonstr.strip().- Parameters:
stripChars- characters to strip from either end of this str/bytes, or null- Returns:
- a new String, stripped of the specified characters/bytes
-
strip
public PyObject strip(PyObject stripChars)
Equivalent of Pythonstr.strip(). Any byte/character matching one of those instripCharswill be discarded from either end of thisstr. IfstripChars == null, whitespace will be stripped. IfstripCharsis aPyUnicode, the result will also be aPyUnicode.- Parameters:
stripChars- characters to strip from either end of this str/bytes, or null- Returns:
- a new
PyString(orPyUnicode), stripped of the specified characters/bytes
-
lstrip
public java.lang.String lstrip()
Equivalent of Pythonstr.lstrip()with no argument, meaning strip whitespace. Any whitespace byte/character will be discarded from the left of thisstr.- Returns:
- a new String, stripped of the whitespace characters/bytes
-
lstrip
public java.lang.String lstrip(java.lang.String stripChars)
Equivalent of Pythonstr.lstrip().- Parameters:
stripChars- characters to strip from the left end of this str/bytes, or null- Returns:
- a new String, stripped of the specified characters/bytes
-
lstrip
public PyObject lstrip(PyObject stripChars)
Equivalent of Pythonstr.lstrip(). Any byte/character matching one of those instripCharswill be discarded from the left end of thisstr. IfstripChars == null, whitespace will be stripped. IfstripCharsis aPyUnicode, the result will also be aPyUnicode.- Parameters:
stripChars- characters to strip from the left end of this str/bytes, or null- Returns:
- a new
PyString(orPyUnicode), stripped of the specified characters/bytes
-
rstrip
public java.lang.String rstrip()
Equivalent of Pythonstr.rstrip()with no argument, meaning strip whitespace. Any whitespace byte/character will be discarded from the right end of thisstr.- Returns:
- a new String, stripped of the whitespace characters/bytes
-
rstrip
public java.lang.String rstrip(java.lang.String stripChars)
Equivalent of Pythonstr.rstrip().- Parameters:
stripChars- characters to strip from either end of this str/bytes, or null- Returns:
- a new String, stripped of the specified characters/bytes
-
rstrip
public PyObject rstrip(PyObject stripChars)
Equivalent of Pythonstr.rstrip(). Any byte/character matching one of those instripCharswill be discarded from the right end of thisstr. IfstripChars == null, whitespace will be stripped. IfstripCharsis aPyUnicode, the result will also be aPyUnicode.- Parameters:
stripChars- characters to strip from the right end of this str/bytes, or null- Returns:
- a new
PyString(orPyUnicode), stripped of the specified characters/bytes
-
split
public PyList split()
Equivalent to Pythonstr.split(), splitting on runs of whitespace.- Returns:
- list(str) result
-
split
public PyList split(java.lang.String sep)
Equivalent to Pythonstr.split(), splitting on a specified string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)- Returns:
- list(str) result
-
split
public PyList split(java.lang.String sep, int maxsplit)
Equivalent to Pythonstr.split(), splitting on a specified string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)maxsplit- maximum number of splits to make (there may bemaxsplit+1parts).- Returns:
- list(str) result
-
split
public PyList split(PyObject sep)
Equivalent to Pythonstr.split()returning aPyListofPyStrings (orPyUnicodes). Thestrwill be split at each occurrence ofsep. Ifsep == null, whitespace will be used as the criterion. Ifsephas zero length, a PythonValueErroris raised.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)- Returns:
- list(str) result
-
split
public PyList split(PyObject sep, int maxsplit)
Assplit(PyObject)but ifmaxsplit>=0 and there are more feasible splits thanmaxsplit, the last element of the list contains the rest of the string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)maxsplit- maximum number of splits to make (there may bemaxsplit+1parts).- Returns:
- list(str) result
-
rsplit
public PyList rsplit()
Equivalent to Pythonstr.rsplit(), splitting on runs of whitespace.- Returns:
- list(str) result
-
rsplit
public PyList rsplit(java.lang.String sep)
Equivalent to Pythonstr.rsplit(), splitting on a specified string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)- Returns:
- list(str) result
-
rsplit
public PyList rsplit(java.lang.String sep, int maxsplit)
Equivalent to Pythonstr.rsplit(), splitting on a specified string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)maxsplit- maximum number of splits to make (there may bemaxsplit+1parts).- Returns:
- list(str) result
-
rsplit
public PyList rsplit(PyObject sep)
Equivalent to Pythonstr.rsplit()returning aPyListofPyStrings (orPyUnicodes). Thestrwill be split at each occurrence ofsep, working from the right. Ifsep == null, whitespace will be used as the criterion. Ifsephas zero length, a PythonValueErroris raised.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)- Returns:
- list(str) result
-
rsplit
public PyList rsplit(PyObject sep, int maxsplit)
Asrsplit(PyObject)but ifmaxsplit>=0 and there are more feasible splits thanmaxsplitthe last element of the list contains the rest of the string.- Parameters:
sep- string to use as separator (ornullif to split on whitespace)maxsplit- maximum number of splits to make (there may bemaxsplit+1parts).- Returns:
- list(str) result
-
partition
public PyTuple partition(PyObject sepObj)
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.- Parameters:
sepObj- str, unicode or object implementingBufferProtocol- Returns:
- tuple of parts
-
rpartition
public PyTuple rpartition(PyObject sepObj)
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.- Parameters:
sepObj- str, unicode or object implementingBufferProtocol- Returns:
- tuple of parts
-
splitlines
public PyList splitlines()
-
splitlines
public PyList splitlines(boolean keepends)
-
index
public int index(PyObject sub)
Return the lowest index in the string where substringsubis found. RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
index
public int index(PyObject sub, PyObject start) throws PyException
Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:]. RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.start- start of slice.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
index
public int index(PyObject sub, PyObject start, PyObject end) throws PyException
Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing". RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.start- start of slice.end- end of slice.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
index
public int index(java.lang.String sub)
Equivalent toindex(PyObject)specialized toString.
-
index
public int index(java.lang.String sub, PyObject start)Equivalent toindex(PyObject, PyObject)specialized toString.
-
index
public int index(java.lang.String sub, PyObject start, PyObject end)Equivalent toindex(PyObject, PyObject, PyObject)specialized toString.
-
rindex
public int rindex(PyObject sub)
Return the highest index in the string where substringsubis found. RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
rindex
public int rindex(PyObject sub, PyObject start) throws PyException
Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:]. RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.start- start of slice.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
rindex
public int rindex(PyObject sub, PyObject start, PyObject end) throws PyException
Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing". RaisesValueErrorif the substring is not found.- Parameters:
sub- substring to find.start- start of slice.end- end of slice.- Returns:
- index of
subin this object. - Throws:
PyException-ValueErrorif not found.
-
rindex
public int rindex(java.lang.String sub)
Equivalent torindex(PyObject)specialized toString.
-
rindex
public int rindex(java.lang.String sub, PyObject start)Equivalent torindex(PyObject, PyObject)specialized toString.
-
rindex
public int rindex(java.lang.String sub, PyObject start, PyObject end)Equivalent torindex(PyObject, PyObject, PyObject)specialized toString.
-
count
public int count(PyObject sub)
Return the number of non-overlapping occurrences of substringsub.- Parameters:
sub- substring to find.- Returns:
- count of occurrences.
-
count
public int count(PyObject sub, PyObject start)
Return the number of non-overlapping occurrences of substringsubin the range[start:].- Parameters:
sub- substring to find.start- start of slice.- Returns:
- count of occurrences.
-
count
public int count(PyObject sub, PyObject start, PyObject end)
Return the number of non-overlapping occurrences of substringsubin the range[start:end]. Optional argumentsstartandendare interpreted as in slice notation.- Parameters:
sub- substring to find.start- start of slice.end- end of slice.- Returns:
- count of occurrences.
-
count
public int count(java.lang.String sub)
Equivalent tocount(PyObject)specialized toString.
-
count
public int count(java.lang.String sub, PyObject start)Equivalent tocount(PyObject, PyObject)specialized toString.
-
count
public int count(java.lang.String sub, PyObject start, PyObject end)Equivalent tocount(PyObject, PyObject, PyObject)specialized toString.
-
find
public int find(PyObject sub)
Return the lowest index in the string where substringsubis found.- Parameters:
sub- substring to find.- Returns:
- index of
subin this object or -1 if not found.
-
find
public int find(PyObject sub, PyObject start)
Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:].- Parameters:
sub- substring to find.start- start of slice.- Returns:
- index of
subin this object or -1 if not found.
-
find
public int find(PyObject sub, PyObject start, PyObject end)
Return the lowest index in the string where substringsubis found, such thatsubis contained in the slices[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing".- Parameters:
sub- substring to find.start- start of slice.end- end of slice.- Returns:
- index of
subin this object or -1 if not found.
-
find
public int find(java.lang.String sub)
Equivalent tofind(PyObject)specialized toString.
-
find
public int find(java.lang.String sub, PyObject start)Equivalent tofind(PyObject, PyObject)specialized toString.
-
find
public int find(java.lang.String sub, PyObject start, PyObject end)Equivalent tofind(PyObject, PyObject, PyObject)specialized toString.
-
rfind
public int rfind(PyObject sub)
Return the highest index in the string where substringsubis found.- Parameters:
sub- substring to find.- Returns:
- index of
subin this object or -1 if not found.
-
rfind
public int rfind(PyObject sub, PyObject start)
Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:].- Parameters:
sub- substring to find.start- start of slice.- Returns:
- index of
subin this object or -1 if not found.
-
rfind
public int rfind(PyObject sub, PyObject start, PyObject end)
Return the highest index in the string where substringsubis found, such thatsubis contained in the slices[start:end]. Argumentsstartandendare interpreted as in slice notation, with null orPy.Nonerepresenting "missing".- Parameters:
sub- substring to find.start- start of slice.end- end of slice.- Returns:
- index of
subin this object or -1 if not found.
-
rfind
public int rfind(java.lang.String sub)
Equivalent tofind(PyObject)specialized toString.
-
rfind
public int rfind(java.lang.String sub, PyObject start)Equivalent tofind(PyObject, PyObject)specialized toString.
-
rfind
public int rfind(java.lang.String sub, PyObject start, PyObject end)Equivalent tofind(PyObject, PyObject, PyObject)specialized toString.
-
atof
public double atof()
Convert this PyString to a floating-point value according to Python rules.- Returns:
- the value
-
atoi
public int atoi()
-
atoi
public int atoi(int base)
-
atol
public PyLong atol()
-
atol
public PyLong atol(int base)
-
ljust
public java.lang.String ljust(int width)
-
ljust
public java.lang.String ljust(int width, java.lang.String padding)
-
rjust
public java.lang.String rjust(int width)
-
center
public java.lang.String center(int width)
-
zfill
public java.lang.String zfill(int width)
-
expandtabs
public java.lang.String expandtabs()
-
expandtabs
public java.lang.String expandtabs(int tabsize)
-
capitalize
public java.lang.String capitalize()
-
replace
public PyString replace(PyObject oldPiece, PyObject newPiece)
Equivalent to Python str.replace(old, new), returning a copy of the string with all occurrences of substring old replaced by new. If either argument is aPyUnicode(or this object is), the result will be aPyUnicode.- Parameters:
oldPiece- to replace where found.newPiece- replacement text.- Returns:
- PyString (or PyUnicode if any string is one), this string after replacements.
-
replace
public PyString replace(PyObject oldPiece, PyObject newPiece, int count)
Equivalent to Python str.replace(old, new[, count]), returning a copy of the string with all occurrences of substring old replaced by new. If argumentcountis nonnegative, only the firstcountoccurrences are replaced. If either argument is aPyUnicode(or this object is), the result will be aPyUnicode.- Parameters:
oldPiece- to replace where found.newPiece- replacement text.count- maximum number of replacements to make, or -1 meaning all of them.- Returns:
- PyString (or PyUnicode if any string is one), this string after replacements.
-
startswith
public boolean startswith(PyObject prefix)
Equivalent to the Pythonstr.startswithmethod testing whether a string starts with a specified prefix.prefixcan also be a tuple of prefixes to look for.- Parameters:
prefix- string to check for (or aPyTupleof them).- Returns:
trueif this string slice starts with a specified prefix, otherwisefalse.
-
startswith
public boolean startswith(PyObject prefix, PyObject start)
Equivalent to the Pythonstr.startswithmethod, testing whether a string starts with a specified prefix, where a sub-range is specified by[start:].startis interpreted as in slice notation, with null orPy.Nonerepresenting "missing".prefixcan also be a tuple of prefixes to look for.- Parameters:
prefix- string to check for (or aPyTupleof them).start- start of slice.- Returns:
trueif this string slice starts with a specified prefix, otherwisefalse.
-
startswith
public boolean startswith(PyObject prefix, PyObject start, PyObject end)
Equivalent to the Pythonstr.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.- 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
public boolean endswith(PyObject suffix)
Equivalent to the Pythonstr.endswithmethod, testing whether a string ends with a specified suffix.suffixcan also be a tuple of suffixes to look for.- Parameters:
suffix- string to check for (or aPyTupleof them).- Returns:
trueif this string slice ends with a specified suffix, otherwisefalse.
-
endswith
public boolean endswith(PyObject suffix, PyObject start)
Equivalent to the Pythonstr.endswithmethod, testing whether a string ends with a specified suffix, where a sub-range is specified by[start:].startis interpreted as in slice notation, with null orPy.Nonerepresenting "missing".suffixcan also be a tuple of suffixes to look for.- Parameters:
suffix- string to check for (or aPyTupleof them).start- start of slice.- Returns:
trueif this string slice ends with a specified suffix, otherwisefalse.
-
endswith
public boolean endswith(PyObject suffix, PyObject start, PyObject end)
Equivalent to the Pythonstr.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.- Parameters:
suffix- string to check for (or aPyTupleof them).start- start of slice.end- end of slice.- Returns:
trueif this string slice ends with a specified suffix, otherwisefalse.
-
translate
public java.lang.String translate(PyObject table)
Equivalent to Pythonstr.translatereturning a copy of this string where the characters have been mapped through the translationtable.tablemust be equivalent to a string of length 256 (if it is notnull).- Parameters:
table- of character (byte) translations (ornull)- Returns:
- transformed byte string
-
translate
public java.lang.String translate(PyObject table, PyObject deletechars)
Equivalent to Pythonstr.translatereturning a copy of this string where all characters (bytes) occurring in the argumentdeletecharsare removed (if it is notnull), and the remaining characters have been mapped through the translationtable.tablemust be equivalent to a string of length 256 (if it is notnull).- Parameters:
table- of character (byte) translations (ornull)deletechars- set of characters to remove (ornull)- Returns:
- transformed byte string
-
translate
public java.lang.String translate(java.lang.String table)
Equivalent totranslate(PyObject)specialized toString.
-
translate
public java.lang.String translate(java.lang.String table, java.lang.String deletechars)Equivalent totranslate(PyObject, PyObject)specialized toString.
-
islower
public boolean islower()
-
isupper
public boolean isupper()
-
isalpha
public boolean isalpha()
-
isalnum
public boolean isalnum()
-
isdecimal
public boolean isdecimal()
-
isdigit
public boolean isdigit()
-
isnumeric
public boolean isnumeric()
-
istitle
public boolean istitle()
-
isspace
public boolean isspace()
-
isunicode
public boolean isunicode()
-
encode
public java.lang.String encode()
-
encode
public java.lang.String encode(java.lang.String encoding)
-
encode
public java.lang.String encode(java.lang.String encoding, java.lang.String errors)
-
decode
public PyObject decode()
-
decode
public PyObject decode(java.lang.String encoding)
-
decode
public PyObject decode(java.lang.String encoding, java.lang.String errors)
-
__format__
public PyObject __format__(PyObject formatSpec)
- Overrides:
__format__in classPyObject
-
asString
public java.lang.String asString(int index) throws PyObject.ConversionException- Overrides:
asStringin classPyObject- Throws:
PyObject.ConversionException
-
asInt
public int asInt()
Description copied from class:PyObjectConvert this object into an int. Throws a PyException on failure.
-
asLong
public long asLong()
Description copied from class:PyObjectConvert this object longo an long. Throws a PyException on failure.
-
asDouble
public double asDouble()
Description copied from class:PyObjectConvert this object into a double. Throws a PyException on failure.
-
asName
public java.lang.String asName(int index) throws PyObject.ConversionException- Overrides:
asNamein classPyObject- Throws:
PyObject.ConversionException
-
charAt
public char charAt(int index)
- Specified by:
charAtin interfacejava.lang.CharSequence- Overrides:
charAtin classPyBaseString
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence- Overrides:
lengthin classPyBaseString
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence- Overrides:
subSequencein classPyBaseString
-
-