diff options
author | Marianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com> | 2016-03-11 15:59:32 +0000 |
---|---|---|
committer | Marianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com> | 2016-03-11 15:59:32 +0000 |
commit | 7423f40674b16c746dfaa94dfc4b3f962dd6b156 (patch) | |
tree | d8b5b933e70c1fd1a41f89a347def0d325608075 /llvm/lib/Support/CommandLine.cpp | |
parent | 47c3a4743eda479b46e0fd436a33128b7be616d4 (diff) | |
download | bcm5719-llvm-7423f40674b16c746dfaa94dfc4b3f962dd6b156.tar.gz bcm5719-llvm-7423f40674b16c746dfaa94dfc4b3f962dd6b156.zip |
More UTF string conversion wrappers
Added new string conversion wrappers that convert between `std::string` (of UTF-8 bytes) and `std::wstring`, which is particularly useful for Win32 interop. Also fixed a missing string conversion for `getenv` on Win32, using these new wrappers.
The motivation behind this is to provide the support functions required for LLDB to work properly on Windows with non-ASCII data; however, the functions are not LLDB specific.
Patch by cameron314
Differential Revision: http://reviews.llvm.org/D17549
llvm-svn: 263247
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index c1615a0a683..b0867b453de 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -787,9 +787,28 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, assert(envVar && "Environment variable name missing"); // Get the environment variable they want us to parse options out of. +#ifdef _WIN32 + std::wstring wenvVar; + if (!llvm::ConvertUTF8toWide(envVar, wenvVar)) { + assert(false && + "Unicode conversion of environment variable name failed"); + return; + } + const wchar_t *wenvValue = _wgetenv(wenvVar.c_str()); + if (!wenvValue) + return; + std::string envValueBuffer; + if (!llvm::convertWideToUTF8(wenvValue, envValueBuffer)) { + assert(false && + "Unicode conversion of environment variable value failed"); + return; + } + const char *envValue = envValueBuffer.c_str(); +#else const char *envValue = getenv(envVar); if (!envValue) return; +#endif // Get program's "name", which we wouldn't know without the caller // telling us. |