diff options
author | Josh Bell <josh@lindenlab.com> | 2007-12-21 06:44:41 +0000 |
---|---|---|
committer | Josh Bell <josh@lindenlab.com> | 2007-12-21 06:44:41 +0000 |
commit | df4d167cd13fd89a85e4d30dca94e40c934707d7 (patch) | |
tree | cde9373bce657013bf04c83ab60b4a4aa826fc76 /indra/llcommon/llstring.cpp | |
parent | 8fde5f0d3241205067e5d7bf5380757e764eff31 (diff) |
svn merge -r74200:76302 svn+ssh://svn.lindenlab.com/svn/linden/branches/Branch_1-18-6-Viewer --> release
Wheee, this was fun. Um, let's back-port fixes a little more rapidly next time. Reviewed by CG until alexandria died, did the rest by my lonesome.
Diffstat (limited to 'indra/llcommon/llstring.cpp')
-rw-r--r-- | indra/llcommon/llstring.cpp | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 9895a684b2..a688bc1c6f 100644 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -34,6 +34,13 @@ #include "llstring.h" #include "llerror.h" +#if LL_WINDOWS +#define WIN32_LEAN_AND_MEAN +#include <winsock2.h> +#include <windows.h> +#include <winnls.h> // for WideCharToMultiByte +#endif + std::string ll_safe_string(const char* in) { if(in) return std::string(in); @@ -796,19 +803,7 @@ std::string utf8str_removeCRLF(const std::string& utf8str) } #if LL_WINDOWS -/* If the size of the passed in buffer is not large enough to hold the string, - * two bad things happen: - * 1. resulting formatted string is NOT null terminated - * 2. Depending on the platform, the return value could be a) the required - * size of the buffer to copy the entire formatted string or b) -1. - * On Windows with VS.Net 2003, it returns -1 e.g. - * - * safe_snprintf always adds a NULL terminator so that the caller does not - * need to check for return value or need to add the NULL terminator. - * It does not, however change the return value - to let the caller know - * that the passed in buffer size was not large enough to hold the formatted string. - * - */ +// documentation moved to header. Phoenix 2007-11-27 int safe_snprintf(char *str, size_t size, const char *format, ...) { va_list args; @@ -820,6 +815,43 @@ int safe_snprintf(char *str, size_t size, const char *format, ...) str[size-1] = '\0'; // always null terminate return num_written; } + +std::string ll_convert_wide_to_string(const wchar_t* in) +{ + std::string out; + if(in) + { + int len_in = wcslen(in); + int len_out = WideCharToMultiByte( + CP_ACP, + 0, + in, + len_in, + NULL, + 0, + 0, + 0); + // We will need two more bytes for the double NULL ending + // created in WideCharToMultiByte(). + char* pout = new char [len_out + 2]; + memset(pout, 0, len_out + 2); + if(pout) + { + WideCharToMultiByte( + CP_ACP, + 0, + in, + len_in, + pout, + len_out, + 0, + 0); + out.assign(pout); + delete[] pout; + } + } + return out; +} #endif // LL_WINDOWS S32 LLStringOps::collate(const llwchar* a, const llwchar* b) |