diff options
author | Jacek Antonelli | 2008-08-15 23:45:19 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:19 -0500 |
commit | b235c59d60472f818a9142c0886b95a0ff4191d7 (patch) | |
tree | d323c55587584b19cc43a03f58a178823f12d3cd /linden/indra/llcommon/llstring.cpp | |
parent | Second Life viewer sources 1.18.5.3 (diff) | |
download | meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.zip meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.gz meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.bz2 meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.xz |
Second Life viewer sources 1.18.6.0-RC
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llstring.cpp | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/linden/indra/llcommon/llstring.cpp b/linden/indra/llcommon/llstring.cpp index 6dab598..e701ea0 100644 --- a/linden/indra/llcommon/llstring.cpp +++ b/linden/indra/llcommon/llstring.cpp | |||
@@ -34,6 +34,13 @@ | |||
34 | #include "llstring.h" | 34 | #include "llstring.h" |
35 | #include "llerror.h" | 35 | #include "llerror.h" |
36 | 36 | ||
37 | #if LL_WINDOWS | ||
38 | #define WIN32_LEAN_AND_MEAN | ||
39 | #include <winsock2.h> | ||
40 | #include <windows.h> | ||
41 | #include <winnls.h> // for WideCharToMultiByte | ||
42 | #endif | ||
43 | |||
37 | std::string ll_safe_string(const char* in) | 44 | std::string ll_safe_string(const char* in) |
38 | { | 45 | { |
39 | if(in) return std::string(in); | 46 | if(in) return std::string(in); |
@@ -718,19 +725,7 @@ std::string utf8str_removeCRLF(const std::string& utf8str) | |||
718 | } | 725 | } |
719 | 726 | ||
720 | #if LL_WINDOWS | 727 | #if LL_WINDOWS |
721 | /* If the size of the passed in buffer is not large enough to hold the string, | 728 | // documentation moved to header. Phoenix 2007-11-27 |
722 | * two bad things happen: | ||
723 | * 1. resulting formatted string is NOT null terminated | ||
724 | * 2. Depending on the platform, the return value could be a) the required | ||
725 | * size of the buffer to copy the entire formatted string or b) -1. | ||
726 | * On Windows with VS.Net 2003, it returns -1 e.g. | ||
727 | * | ||
728 | * safe_snprintf always adds a NULL terminator so that the caller does not | ||
729 | * need to check for return value or need to add the NULL terminator. | ||
730 | * It does not, however change the return value - to let the caller know | ||
731 | * that the passed in buffer size was not large enough to hold the formatted string. | ||
732 | * | ||
733 | */ | ||
734 | int safe_snprintf(char *str, size_t size, const char *format, ...) | 729 | int safe_snprintf(char *str, size_t size, const char *format, ...) |
735 | { | 730 | { |
736 | va_list args; | 731 | va_list args; |
@@ -742,6 +737,43 @@ int safe_snprintf(char *str, size_t size, const char *format, ...) | |||
742 | str[size-1] = '\0'; // always null terminate | 737 | str[size-1] = '\0'; // always null terminate |
743 | return num_written; | 738 | return num_written; |
744 | } | 739 | } |
740 | |||
741 | std::string ll_convert_wide_to_string(const wchar_t* in) | ||
742 | { | ||
743 | std::string out; | ||
744 | if(in) | ||
745 | { | ||
746 | int len_in = wcslen(in); | ||
747 | int len_out = WideCharToMultiByte( | ||
748 | CP_ACP, | ||
749 | 0, | ||
750 | in, | ||
751 | len_in, | ||
752 | NULL, | ||
753 | 0, | ||
754 | 0, | ||
755 | 0); | ||
756 | // We will need two more bytes for the double NULL ending | ||
757 | // created in WideCharToMultiByte(). | ||
758 | char* pout = new char [len_out + 2]; | ||
759 | memset(pout, 0, len_out + 2); | ||
760 | if(pout) | ||
761 | { | ||
762 | WideCharToMultiByte( | ||
763 | CP_ACP, | ||
764 | 0, | ||
765 | in, | ||
766 | len_in, | ||
767 | pout, | ||
768 | len_out, | ||
769 | 0, | ||
770 | 0); | ||
771 | out.assign(pout); | ||
772 | delete[] pout; | ||
773 | } | ||
774 | } | ||
775 | return out; | ||
776 | } | ||
745 | #endif // LL_WINDOWS | 777 | #endif // LL_WINDOWS |
746 | 778 | ||
747 | S32 LLStringOps::collate(const llwchar* a, const llwchar* b) | 779 | S32 LLStringOps::collate(const llwchar* a, const llwchar* b) |