You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@epam.com> on 2007/09/27 10:43:08 UTC
[PATCH] util locale
Below is a patch to localedef utility to obtain list of system locales
if RWSTD_LOCALE_ROOT environment variable is not defined.
ChangeLog:
* locale.cpp [_WIN32] (EnumLocales): New function to enumerate system
locales.
(print_locale_names): Obtain list of system locales if
RWSTD_LOCALE_ROOT
environment variable is not defined.
Index: locale.cpp
===================================================================
--- locale.cpp (revision 579898)
+++ locale.cpp (working copy)
@@ -2361,6 +2361,38 @@
}
+#ifdef _WIN32
+static BOOL CALLBACK
+EnumLocales (char* locale_id)
+{
+ const LCID lcid = std::strtoul (locale_id, 0, 16);
+
+ char buf [80];
+ const int bufsize = sizeof (buf) / sizeof (*buf);
+
+ std::string name;
+
+ if (GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE, buf, bufsize))
+ name = buf;
+
+ if (GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY, buf, bufsize)) {
+ name += '_';
+ name += buf;
+ }
+
+ if ( GetLocaleInfo (lcid, LOCALE_IDEFAULTANSICODEPAGE , buf,
bufsize)
+ && std::strtoul (buf, 0, 10)) {
+ name += '.';
+ name += buf;
+ }
+
+ if (const char* locname = std::setlocale (LC_ALL, name.c_str ()))
+ std::cout << locname << '\n';
+
+ return TRUE;
+}
+#endif
+
// print the available locales
static void
print_locale_names ()
@@ -2374,6 +2406,13 @@
std::system (cmd.c_str ());
}
+ else {
+#ifndef _WIN32
+ std::system ("/usr/bin/locale -a");
+#else
+ EnumSystemLocales (EnumLocales, LCID_INSTALLED);
+#endif
+ }
}
Farid.
Re: [PATCH] util locale
Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
> Below is a patch to localedef utility to obtain list of system locales
> if RWSTD_LOCALE_ROOT environment variable is not defined.
Cool! Thanks for doing this. I think I said I would but spaced
it. As before, please wait until I'm done with the merge. I was
hoping to be done today but because of the svn snags it'll have
to wait till tomorrow. I've had enough for one day!
Martin
>
> ChangeLog:
> * locale.cpp [_WIN32] (EnumLocales): New function to enumerate system
> locales.
> (print_locale_names): Obtain list of system locales if
> RWSTD_LOCALE_ROOT
> environment variable is not defined.
>
> Index: locale.cpp
> ===================================================================
> --- locale.cpp (revision 579898)
> +++ locale.cpp (working copy)
> @@ -2361,6 +2361,38 @@
> }
>
>
> +#ifdef _WIN32
> +static BOOL CALLBACK
> +EnumLocales (char* locale_id)
> +{
> + const LCID lcid = std::strtoul (locale_id, 0, 16);
> +
> + char buf [80];
> + const int bufsize = sizeof (buf) / sizeof (*buf);
> +
> + std::string name;
> +
> + if (GetLocaleInfo (lcid, LOCALE_SENGLANGUAGE, buf, bufsize))
> + name = buf;
> +
> + if (GetLocaleInfo (lcid, LOCALE_SENGCOUNTRY, buf, bufsize)) {
> + name += '_';
> + name += buf;
> + }
> +
> + if ( GetLocaleInfo (lcid, LOCALE_IDEFAULTANSICODEPAGE , buf,
> bufsize)
> + && std::strtoul (buf, 0, 10)) {
> + name += '.';
> + name += buf;
> + }
> +
> + if (const char* locname = std::setlocale (LC_ALL, name.c_str ()))
> + std::cout << locname << '\n';
> +
> + return TRUE;
> +}
> +#endif
> +
> // print the available locales
> static void
> print_locale_names ()
> @@ -2374,6 +2406,13 @@
>
> std::system (cmd.c_str ());
> }
> + else {
> +#ifndef _WIN32
> + std::system ("/usr/bin/locale -a");
> +#else
> + EnumSystemLocales (EnumLocales, LCID_INSTALLED);
> +#endif
> + }
> }
>
>
> Farid.