diff options
author | Joerg Bornemann <joerg.bornemann@nokia.com> | 2012-09-22 14:05:37 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2012-09-22 14:12:30 +0200 |
commit | f021f26522344bb5a0612b3a33ba0691867c0cf3 (patch) | |
tree | f83d4a70adbeb7e381372223be11688932cf84cc | |
parent | b227482ef1f7bd0577a344a8801d34fa8ab40f4e (diff) |
added environment variable unicode functions
On Windows, environment variable names and values
can be in Unicode.
Change-Id: I49e4c28fd99614825800b724af80eca7419164c8
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r-- | src/jomlib/helperfunctions.cpp | 17 | ||||
-rw-r--r-- | src/jomlib/helperfunctions.h | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/jomlib/helperfunctions.cpp b/src/jomlib/helperfunctions.cpp index 6f4c63f..aa184d6 100644 --- a/src/jomlib/helperfunctions.cpp +++ b/src/jomlib/helperfunctions.cpp @@ -22,6 +22,7 @@ ****************************************************************************/ #include "helperfunctions.h" +#include <qt_windows.h> /** * Splits the string, respects "foo bar" and "foo ""knuffi"" bar". @@ -66,3 +67,19 @@ QString trimLeft(const QString &s) result.remove(0, 1); return result; } + +QString qGetEnvironmentVariable(const wchar_t *lpName) +{ + const size_t bufferSize = 32767; + TCHAR buffer[bufferSize]; + if (GetEnvironmentVariable(lpName, buffer, bufferSize)) + return QString::fromWCharArray(buffer); + return QString(); +} + +bool qSetEnvironmentVariable(const QString &name, const QString &value) +{ + return SetEnvironmentVariable( + reinterpret_cast<const wchar_t *>(name.utf16()), + reinterpret_cast<const wchar_t *>(value.utf16())); +} diff --git a/src/jomlib/helperfunctions.h b/src/jomlib/helperfunctions.h index a5986e6..f2c80a8 100644 --- a/src/jomlib/helperfunctions.h +++ b/src/jomlib/helperfunctions.h @@ -71,3 +71,6 @@ QStringList splitCommandLine(QString commandLine); * Returns a copy of s with all whitespace removed from the left. */ QString trimLeft(const QString &s); + +QString qGetEnvironmentVariable(const wchar_t *lpName); +bool qSetEnvironmentVariable(const QString &name, const QString &value); |