std::to_string() can also convert a floating-point argument to string,
using the "%f" printf format (see
http://en.cppreference.com/w/cpp/string/basic_string/to_string )
So add this support to our to_sstring() as well.
Note that if you want to use a different format, e.g., "%g", you can,
by using the to_sstring_sprintf function, for example
to_sstring_sprintf(12345678.9, "%g")
results in "1.23457e+07".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
The constructor from "const char_type *" wouldn't really work when
char_type != char, because strlen() won't work on such pointers.
It is more convenient to have a constructor from an ordinary const char *
(e.g., a C string literal), and solve the type problem with an ugly cast.
This only makes sense when sizeof(char_type)==1 (i.e., it is char, unsigned
char, or signed char), but I think we make this assumption in other places
as well (e.g., in determining the size we need to allocate).
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
std::string has an operator[] to get access (read or modify) to one
character in the string. This patch adds the same operator for our
sstring.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
The basic_sstring<> template allows picking char_type - which instead of
being just "char" could be chosen to be something similar, like "unsigned char"
or "signed char".
Unfortunately some hard-coded uses of "char" were left in the code. This
did not cause any problems for existing code because of implicit conversions,
but it does cause problems once I try to implement operator[] when char_type
is not char. This results in an attempt to return a reference to the result
of a conversion, which is not allowed.
So this patch fixes the leftover uses of "char" to "char_type".
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
sstring's std::string conversion uses c_str() to construct the value,
but the conversion is broken if the value contains NUL - both sstring and
std::string can contain NULs, but C strings use them as a terminator.
Fix by using the size+length std::string constructor.
Releases owenrship of the data and gives it away as
temporary_buffer. This way we can avoid allocation when putting rvalue
sstring if it's already using external storage. Except we need to
allocate a deleter which uses delete[], but this can be fixed later.
It concatenates multiple string-like entities in one go and gives away
an sstring. It does at most one allocation for the final sstring and
one copy per each string. Works with heterogenous arguments, both
sstrings and constant strings are supported, string_views are planned.
It's required for instantiating a sstring with the constructor
basic_sstring(initialized_later, size_t size).
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>