diff options
author | Monty Brandenberg <monty@lindenlab.com> | 2014-05-22 22:08:54 +0000 |
---|---|---|
committer | Monty Brandenberg <monty@lindenlab.com> | 2014-05-22 22:08:54 +0000 |
commit | 060c728970dc78d30f2cebdbeda7e56ea8de46e2 (patch) | |
tree | 8f00ce1b3bd564bc6cb81a2bc39a081eb3deca35 /indra/llcommon/stringize.h | |
parent | f8874d04b8ca238ee99dc464055295cff417a9b2 (diff) | |
parent | 644ca6a0f8a7759119814f88df93b8e838321a12 (diff) |
Merge. Pull in viewer-release after release of 3.7.8
Diffstat (limited to 'indra/llcommon/stringize.h')
-rwxr-xr-x | indra/llcommon/stringize.h | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/indra/llcommon/stringize.h b/indra/llcommon/stringize.h index 72f2e58ce1..2df008febb 100755 --- a/indra/llcommon/stringize.h +++ b/indra/llcommon/stringize.h @@ -31,21 +31,64 @@ #include <sstream> #include <boost/lambda/lambda.hpp> +#include <llstring.h> /** - * stringize(item) encapsulates an idiom we use constantly, using + * gstringize(item) encapsulates an idiom we use constantly, using * operator<<(std::ostringstream&, TYPE) followed by std::ostringstream::str() + * or their wstring equivalents * to render a string expressing some item. */ -template <typename T> -std::string stringize(const T& item) +template <typename CHARTYPE, typename T> +std::basic_string<CHARTYPE> gstringize(const T& item) { - std::ostringstream out; + std::basic_ostringstream<CHARTYPE> out; out << item; return out.str(); } /** + *partial specialization of stringize for handling wstring + *TODO: we should have similar specializations for wchar_t[] but not until it is needed. + */ +inline std::string stringize(const std::wstring& item) +{ + LL_WARNS() << "WARNING: Possible narrowing" << LL_ENDL; + + std::string s; + + s = wstring_to_utf8str(item); + return gstringize<char>(s); +} + +/** + * Specialization of gstringize for std::string return types + */ +template <typename T> +std::string stringize(const T& item) +{ + return gstringize<char>(item); +} + +/** + * Specialization for generating wstring from string. + * Both a convenience function and saves a miniscule amount of overhead. + */ +inline std::wstring wstringize(const std::string& item) +{ + return gstringize<wchar_t>(item.c_str()); +} + +/** + * Specialization of gstringize for std::wstring return types + */ +template <typename T> +std::wstring wstringize(const T& item) +{ + return gstringize<wchar_t>(item); +} + +/** * stringize_f(functor) */ template <typename Functor> |