pybind11/docs/advanced/cast
Jason Rhinelander 11a337f16f Unicode fixes and docs (#624)
* Propagate unicode conversion failure

If returning a std::string with invalid utf-8 data, we currently fail
with an uninformative TypeError instead of propagating the
UnicodeDecodeError that Python sets on failure.

* Add support for u16/u32strings and literals

This adds support for wchar{16,32}_t character literals and the
associated std::u{16,32}string types.  It also folds the
character/string conversion into a single type_caster template, since
the type casters for string and wstring were mostly the same anyway.

* Added too-long and too-big character conversion errors

With this commit, when casting to a single character, as opposed to a
C-style string, we make sure the input wasn't a multi-character string
or a single character with codepoint too large for the character type.

This also changes the character cast op to CharT instead of CharT& (we
need to be able to return a temporary decoded char value, but also
because there's little gained by bothering with an lvalue return here).

Finally it changes the char caster to 'has-a-string-caster' instead of
'is-a-string-caster' because, with the cast_op change above, there's
nothing at all gained from inheritance.  This also lets us remove the
`success` from the string caster (which was only there for the char
caster) into the char caster itself.  (I also renamed it to 'none' and
inverted its value to better reflect its purpose).  The None -> nullptr
loading also now takes place only under a `convert = true` load pass.
Although it's unlikely that a function taking a char also has overloads
that can take a None, it seems marginally more correct to treat it as a
conversion.

This commit simplifies the size assumptions about character sizes with
static_asserts to back them up.
2017-02-14 11:08:19 +01:00
..
chrono.rst Automate generation of reference docs with doxygen and breathe (#598) 2017-01-31 16:54:08 +01:00
custom.rst add note about custom type casters (fixes #480) 2016-11-04 11:06:22 +01:00
eigen.rst Reorganize documentation 2016-10-20 15:21:34 +02:00
functional.rst Reorganize documentation 2016-10-20 15:21:34 +02:00
index.rst RFC - Add documentation for strings and Unicode issues (#636) 2017-02-02 13:56:31 +01:00
overview.rst Unicode fixes and docs (#624) 2017-02-14 11:08:19 +01:00
stl.rst Docs: Fix several errors of examples from the doc (#592) 2017-01-13 11:15:52 +01:00
strings.rst RFC - Add documentation for strings and Unicode issues (#636) 2017-02-02 13:56:31 +01:00