diff options
author | Aura Linden <aura@lindenlab.com> | 2014-04-07 17:04:09 -0700 |
---|---|---|
committer | Aura Linden <aura@lindenlab.com> | 2014-04-07 17:04:09 -0700 |
commit | d476b12ae56ef5ebb5785a0a0f8503e5965d1970 (patch) | |
tree | 90aa656652fe2b49f5a95b9f123a288ace7a312e /indra/llcommon/stringize.h | |
parent | dfd78e83d91832b486a5bba6b1bb1cce621163ab (diff) | |
parent | 7e966f28da79d2d24f93a2615c8807421300700c (diff) |
Merged viewer release into vivox
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..acae74b584 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) +{ + llwarns << "WARNING: Possible narrowing" << llendl; + + 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> |