2.7.2 Strings
The version API often used char*
for both setting and
setting string values. This is not a problem for setting (although
encodings can be an issue), but can introduce subtle bugs in the
lifetimes of pointers if the buffer stack isn't used properly. PlStringBuffers
makes the buffer stack easier to use, but it would be preferable to
avoid its use altogether. C++, unlike C, has a standard string that
allows easily keeping a copy rather than dealing with a pointer that
might become invalid. (Also, C++ strings can contain null characters.)
C++ has default conversion operators from char*
to
std::string
, so some of the API support only
std::string
, even though this can cause a small
inefficiency. If this proves to be a problem, additional overloaded
functions and methods can be provided in future (note that some
compilers have optimizations that reduce the overheads of using
std::string
); but for performance-critical code, the C
functions can still be used.
There still remains the problems of Unicode and encodings.
std::wstring
is one way of dealing with this. And for
interfaces that use std::string
, an encoding can be
specified.24As of 2023-04, this
had only been partially implemented. Some of the details
for this - such as the default encoding - may change slightly in the
future.