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
Re: Environment variables code page [message #22540 is a reply to message #22538] Sun, 26 July 2009 03:26 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14258
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
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: string filtering bug
Next Topic: GZDecompress bug
Goto Forum:
  


Current Time: Wed May 14 22:45:20 CEST 2025

Total time taken to generate the page: 0.01035 seconds