From ea7e6a5174f1bdfc51ada864736d354706534d8b Mon Sep 17 00:00:00 2001 From: Aura Linden Date: Tue, 14 Jan 2014 15:28:35 -0800 Subject: Some cleanup of string to wstring conversion and vice versa. --- indra/llcommon/stringize.h | 51 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/stringize.h') 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,20 +31,63 @@ #include #include +#include /** - * 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 -std::string stringize(const T& item) +template +std::basic_string gstringize(const T& item) { - std::ostringstream out; + std::basic_ostringstream 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(s); +} + +/** + * Specialization of gstringize for std::string return types + */ +template +std::string stringize(const T& item) +{ + return gstringize(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(item.c_str()); +} + +/** + * Specialization of gstringize for std::wstring return types + */ +template +std::wstring wstringize(const T& item) +{ + return gstringize(item); +} + /** * stringize_f(functor) */ -- cgit v1.2.3