/** * Create an iterator for the parts of this field name (and extract the head name field, which * may be an empty string). * * @param fieldNameObject */ public FieldNameIterator(PyString fieldNameObject) { // Extract UTF-16 string but remember whether PyString or PyUnicode shouyld result. this(fieldNameObject.getString(), !(fieldNameObject instanceof PyUnicode)); }
/** * Return a substring of this object as a Java String. * * @param start the beginning index, inclusive. * @param end the ending index, exclusive. * @return the specified substring. */ public String substring(int start, int end) { return getString().substring(start, end); }
/** * @return 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. */ public byte[] toBytes() { return StringUtil.toBytes(getString()); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___eq___doc) final PyObject str___eq__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().equals(s) ? Py.True : Py.False; }
@ExposedMethod(doc = BuiltinDocs.str___contains___doc) final boolean str___contains__(PyObject o) { String other = asUTF16StringOrError(o); return getString().indexOf(other) >= 0; }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___ne___doc) final PyObject str___ne__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().equals(s) ? Py.False : Py.True; }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___le___doc) final PyObject str___le__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().compareTo(s) <= 0 ? Py.True : Py.False; }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___ge___doc) final PyObject str___ge__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().compareTo(s) >= 0 ? Py.True : Py.False; }
@ExposedMethod(doc = BuiltinDocs.str___str___doc) final PyString str___str__() { if (getClass() == PyString.class) { return this; } return new PyString(getString(), true); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___gt___doc) final PyObject str___gt__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().compareTo(s) > 0 ? Py.True : Py.False; }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___lt___doc) final PyObject str___lt__(PyObject other) { String s = coerce(other); if (s == null) { return null; } return getString().compareTo(s) < 0 ? Py.True : Py.False; }
@ExposedMethod(doc = BuiltinDocs.str___mod___doc) public PyObject str___mod__(PyObject other) { StringFormatter fmt = new StringFormatter(getString(), false); return fmt.format(other); }
@ExposedMethod(doc = BuiltinDocs.object___format___doc) final PyObject object___format__(PyObject formatSpec) { if (formatSpec != null && formatSpec instanceof PyString && !((PyString)formatSpec).getString().isEmpty()) { Py.warning(Py.PendingDeprecationWarning, "object.__format__ with a non-empty format string is deprecated"); } return __str__().__format__(formatSpec); }
@Override public void write(DataOutput out) throws IOException { PyString pyString; try { pyString = cPickle.dumps(getPyObject()); } catch (PyException e) { LOG.fatal("Could not serialize wrapped Jython value: " + getPyObject().__str__()); throw e; } WritableUtils.writeString(out, pyString.getString()); }
public void write(PyObject o) { if (o instanceof PyUnicode) { write(((PyUnicode) o).getString()); } else if (o instanceof PyString) { write(((PyString) o).getString()); } else { throw Py.TypeError("write requires a string as its argument"); } }