mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 09:46:10 +00:00
Add py::str::format() method
This commit is contained in:
@@ -385,8 +385,18 @@ public:
|
||||
pybind11_fail("Unable to extract string contents! (invalid type)");
|
||||
return std::string(buffer, (size_t) length);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
str format(Args &&...args) const {
|
||||
return attr("format").cast<object>()(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
inline namespace literals {
|
||||
/// String literal version of str
|
||||
inline str operator"" _s(const char *s, size_t size) { return {s, size}; }
|
||||
}
|
||||
|
||||
inline pybind11::str handle::str() const {
|
||||
PyObject *strValue = PyObject_Str(m_ptr);
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
|
||||
Reference in New Issue
Block a user