Microsoft sublanguage string to locale identifier - c++

I can't seem to find a way to convert, or find, a local identifier from a sublanguage string. This site shows the mappings:
http://msdn.microsoft.com/en-us/library/dd318693(v=VS.85).aspx
I want the user to enter a sublanguage string, such as "France (FR)" and to get the local identifier from this, which in this case would be 0x0484. Or the other way around, if a user enters 0x0480 then to return French (FR).
Has anyone encountered this problem before and can point me in the right direction?
Otherwise I'm going to be writing a few mapping statements to hard code it and maintain future releases if anything changes.
BTW, I'm coding in C++ for Windows platform.
Cheers

A good starting point would be the LCIDToLocaleName function and it's opposite - LocaleNameToLCID. Note that these allow converting between LCID and RFC4646 locale name; to get the humanreadable country and language names, use the GetLocaleInfoEx with the LOCALE_SENGLISH* flags. If you need localized names instead of English, use LOCALE_SLOCALIZED* constants instead.

Related

Is there a a way to force LookupAccountSid to always return the name in the US locale?

I have a test that has been failing for seemingly random reasons. Turns out that the non-US Windows installations have localized names for the SIDs, which makes a simple string comparison fail.
Is there a way to always get an english name from LookupAccountSid regardless of what the OS language is? E.g. I'd always like to get "LOCAL SERVICE" and not a localized string.

Format thousands separator

I am programming in c++ using mfc in visual studio 2010.
I live in Europe, so I have the regional settings of the PC not USA but Europe.
I use the .Format function of CString to print the result of a calculation and I want to add a decimal point as separator between hundred and thousands.
For example, I would like to have displayed 23.400 instead of 23400
Is it possible using a particular formatting of % or i have to change the setting of the pc?
Thanks for the help
As far as I know CString's .Format doesn't support this.
I'd use a stringstream to handle the formatting:
std::ostringstream temp;
temp.imbue(std::locale(""));
temp << 23400;
CString result = temp.str().c_str();
Specifying an empty string as the name of the locale as I've done here means it should pick up the locale setting from the OS. You can give the name of a specific locale instead (e.g., if you want a specific locale, regardless of how the OS is configured):
temp.imbue(std::locale("de")); // German locale
As far as I know this is what your are looking for. Simple search on google gave the answer. This type of print (%.2f) by the way is pretty standard among pretty much every modern language.
"Floating point: %.2f\n"
https://msdn.microsoft.com/en-us/library/aa314327(v=vs.60).aspx

Log files in MAGMA

At Uni, we are using MAGMA. I'd like to create a log file. That should be done with SetLogFile('FileName'). The result of that, however, is User error: Identifier '20.10.txt' has not been declared or assigned (FileName being 20.10.txt). Also, load 'inputfile.magma' seems not to work. I'm working on Mac OS X 10.7.5. Why do those things happen and how do I solve these problems?
OK, it's a damn basic mistake, and I apologize, but if someone who is (or should be) supposed to teach you at least a bit of MAGMA doesn't tell you strings are delimited by double quotes "" and not signle quotes '' in MAGMA, how exactly are you supposed to guess you should write SetLogFile("20.10.txt") after a semester of MATLAB where strings are delimited by '' and so you would have '20.10.txt'? I sort of found out by myself, and then tonight, in the middle of a web search, I realized that of course, double quotes, and wondered if he is supposed to teach us MAGMA or only to show us random examples of MAGMA usage with no other purpose whatsoever. As for the load thing, I will check that is the right name and come back with either an edit to this or a follow-up, or nothing at all, since the name was from memory and might have been deformed.

Xcode codecompletion, just variables

I am learing programming and using Xcode. I would like to trim the autocompletion a bit. I feel like this make me not remember syntax, I often just look it up in codecompletion. And I would for the time being be able to hardcode everything.
Is there a way to make it only complete variable names? This is useful for saving time. But i do not want all the extra.
I am programming in c++ for the record.
Thanks in advance!
You can press escape key when you want to complete names. The first word in the suggest list always the true word. then you just press Enter/return key.

Finding unique path name for a given input

I'm working on a problem where I need to have a way to convert a user inputted filename to a unique path name. Let's say I let the user specify a path name that points to a file that contains some data. I can then do Data* pData=Open(PathName). Now if the user specifies the same path name again, I'd like to be able to have a table of already opened files and just return a pointer to the same data: Data* pData2=GetOpenedData(PathName). This is easy to accomplish with a simple std::map<std::string,Data*>, the problem is that different values of PathName can point to the same file. The simplest case is on Windows case insensitivity comes into play.
The code is cross platform C++ and I don't have access to .NET stuff (but I'm happy to #ifdef the differences between Windows and UNIX if needed). Does anyone know of either Windows API or POSIX functions that can take a path name and return a unique (to the system) string that I can key off of. The key doesn't have to be the same in both systems (Windows/POSIX), just unique within a running instance of my code.
For now, I'm not worried about links or two ways to get to the same file. Such as in Windows, if I had \myserver\share mapped to S: then \myserver\share\blah and S:\blah are the same file, but I can live with those being thought of as different. But S:\blah and S:\Blah should be the same. If there is a way to make \myserver\share and S:\ also be unique, that's a bonus and I'd be really happy, but I can live without it. (Likewise, if there are multiple links to the same file in UNIX).
Edited to add:
It's not as simple as just doing a case insensitive search in windows. For example: c://data/mydata.dat while that's an "invalid" filename, windows will accept it and it will actualy point to c:\data\mydata.dat
Edited to add another thing:
I'd also like c:\mydirectory\..\blah.dat to be recognized at the same as c:\blah.dat
For Windows, PathCanonicalize() is your friend. The shell path handing package in Windows has a few additional routines that'll help you out.
Unfortunately, I'm not sure what the Unix equivalents to this package is.
For Windows you can store the full path of a resource making all lowercase (or uppercase).
I don't use *nix so can't tell about that. But I believe in *nix systems case does matter (\home\a and \home\A are different). If that is the case then you can omit converting case of user input for *nix.
You can optionally instantiate std::map with a third template argument, which is the comparison function/functor (see e.g. http://www.cplusplus.com/reference/stl/map/). You could provide a case-insensitive string comparison function.
I believe Scott Meyers provides a good example of such a function in Effective STL; I can check this when I get home.