| Author |
Message |
xiebopublic@gmail.com *nix forums beginner
Joined: 27 Jul 2005
Posts: 9
|
Posted: Fri Jul 21, 2006 3:22 am Post subject:
Is there C/C++ corresponding function in Linux for Java's java.util.Locale.getCountry?
|
|
|
Hi all,
Is there C/C++ corresponding function in Linux for Java's
java.util.Locale.getCountry? Thanks!
Best Regards,
Xie, Bo |
|
| Back to top |
|
 |
Josef Moellers *nix forums Guru
Joined: 28 Feb 2005
Posts: 426
|
Posted: Fri Jul 21, 2006 6:46 am Post subject:
Re: Is there C/C++ corresponding function in Linux for Java's java.util.Locale.getCountry?
|
|
|
xiebopublic@gmail.com wrote:
| Quote: | Hi all,
Is there C/C++ corresponding function in Linux for Java's
java.util.Locale.getCountry? Thanks!
|
getenv("LANG")?
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett |
|
| Back to top |
|
 |
Josef Moellers *nix forums Guru
Joined: 28 Feb 2005
Posts: 426
|
Posted: Fri Jul 21, 2006 6:48 am Post subject:
Re: Is there C/C++ corresponding function in Linux for Java's java.util.Locale.getCountry?
|
|
|
xiebopublic@gmail.com wrote:
| Quote: | Hi all,
Is there C/C++ corresponding function in Linux for Java's
java.util.Locale.getCountry? Thanks!
Best Regards,
Xie, Bo
|
getenv("LANG")?
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett |
|
| Back to top |
|
 |
Binary *nix forums addict
Joined: 25 Mar 2005
Posts: 83
|
Posted: Fri Jul 21, 2006 9:17 am Post subject:
Re: Is there C/C++ corresponding function in Linux for Java's java.util.Locale.getCountry?
|
|
|
man locale
xiebopublic@gmail.com wrote:
| Quote: | Hi all,
Is there C/C++ corresponding function in Linux for Java's
java.util.Locale.getCountry? Thanks!
Best Regards,
Xie, Bo |
|
|
| Back to top |
|
 |
Roger Leigh *nix forums Guru
Joined: 28 Feb 2005
Posts: 364
|
Posted: Fri Jul 21, 2006 9:46 am Post subject:
Re: Is there C/C++ corresponding function in Linux for Java's java.util.Locale.getCountry?
|
|
|
On 2006-07-21, Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
| Quote: | xiebopublic@gmail.com wrote:
Hi all,
Is there C/C++ corresponding function in Linux for Java's
java.util.Locale.getCountry? Thanks!
Best Regards,
Xie, Bo
getenv("LANG")?
|
No. It might not be set, and there are quite a lot of other LC_*
environment variables to consider in addition.
#include <iostream>
#include <locale>
int main()
{
std::string localename = std::locale("").name();
std::string::size_type pos;
bool status = false;
// Strip off any charset.
if ((pos = localename.find_first_of('.')) != std::string::npos)
localename = localename.substr(0, pos);
std::cerr << localename << std::endl;
// Strip off language, retaining territory.
if ((pos = localename.find_first_of('_')) != std::string::npos &&
localename.size() > pos + 1)
localename = localename.substr(pos + 1);
else
localename = "";
std::cerr << localename << std::endl;
}
Also consider that in C++, you may have a separate locale imbued into
each output stream; you may wish to get the locale from the stream,
instead of using the default locale as above.
Regards,
Roger
--
.''`. Roger Leigh
: :' : Debian GNU/Linux http://people.debian.org/~rleigh/
`. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/
`- GPG Public Key: 0x25BFB848 Please sign and encrypt your mail. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|