Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Environment variables code page
Environment variables code page [message #22538] Sat, 25 July 2009 13:05 Go to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi,

GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page. I think that there should be another function - FromOEMCharset (defined only in section PLATFORM_WIN32) and GetEnv should be split in two versions (windows and posix).

App.cpp, line ~10:

#ifdef PLATFORM_WIN32
String GetEnv(const char *id)
{
	return FromOEMCharset(getenv(id));
}

[...]

App.cpp line ~20:

#ifdef PLATFORM_POSIX

String GetEnv(const char *id)
{
	return FromSystemCharset(getenv(id));
}

[...]

Util.cpp line ~620:
String FromOEMCharset(const String& src)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}



[Updated on: Sat, 25 July 2009 13:05]

Report message to a moderator

Re: Environment variables code page [message #22540 is a reply to message #22538] Sun, 26 July 2009 03:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Zbych wrote on Sat, 25 July 2009 07:05

Hi,

GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page. I think that there should be another function - FromOEMCharset (defined only in section PLATFORM_WIN32) and GetEnv should be split in two versions (windows and posix).

App.cpp, line ~10:

#ifdef PLATFORM_WIN32
String GetEnv(const char *id)
{
	return FromOEMCharset(getenv(id));
}

[...]

App.cpp line ~20:

#ifdef PLATFORM_POSIX

String GetEnv(const char *id)
{
	return FromSystemCharset(getenv(id));
}

[...]

Util.cpp line ~620:
String FromOEMCharset(const String& src)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}






OK, I have only tried to size-optimize a little (please check):

String FromWin32Charset(const String& src, int cp)
{
	WStringBuffer b(src.GetLength());
	int q = MultiByteToWideChar(cp, MB_PRECOMPOSED, ~src, src.GetLength(), (WCHAR*)~b, src.GetLength());
	if(q <= 0)
		return src;
	b.SetCount(q);
	return WString(b).ToString();
}

String FromOEMCharset(const String& src)
{
	return FromWin32Charset(src, CP_OEMCP);
}

String FromSystemCharset(const String& src)
{
	return FromWin32Charset(src, CP_ACP);
}


Mirek
Re: Environment variables code page [message #22546 is a reply to message #22540] Sun, 26 July 2009 11:18 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
luzr wrote on Sun, 26 July 2009 03:26

OK, I have only tried to size-optimize a little (please check)


Works like a charm Smile. Thanks.

Re: Environment variables code page [message #22547 is a reply to message #22538] Sun, 26 July 2009 11:21 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Zbych wrote on Sat, 25 July 2009 14:05


GetEnv function uses FromSystemCharset to convert code page, but environment variables in windows use OEM not ANSI code page.


This must be the reason why Unicode strings where not recognized in environment variables. I proposed a solution here, but I guess this will work a lot better. I'll try to see if it works correctly.
Previous Topic: string filtering bug
Next Topic: GZDecompress bug
Goto Forum:
  


Current Time: Sat Apr 27 20:57:52 CEST 2024

Total time taken to generate the page: 0.05074 seconds