std.locale

Sergey Gromov snake.scaly at gmail.com
Mon Mar 2 09:25:39 PST 2009


Mon, 02 Mar 2009 07:02:10 -0800, Andrei Alexandrescu wrote:

> Consider some code in phobos that must throw an exception:
> 
> throw Exception("File `%s' not found, system error is %s.",
>      filename, errnomsg);
> 
> The localized version will look like this:
> 
> auto format = "File `%s' not found, system error is %s.";
> auto localFormat = currentLocale ? currentLocale.peek(format) : null;
> if (!localFormat) localFormat = format;
> throw Exception(localFormat, filename, errnomsg);

This example does not address the encoding problem.  Currently, errnomsg
is in Russian, UTF-8 encoded.  So I get "system error is <garbage>" on
the console.  If you adopt locales I'll get garbage not only for the
system error but for the rest of the exception message as well.

To actually solve this problem the default exception handler must be
fixed to convert any UTF-8 into the current OEM code page before
printing.  It would also help if default stdin and stdout performed such
a conversion.

> What happens is that the default format string _is_ the key for looking 
> up the localized strings.

Nice.  This means that error messages become a part of API and are
subject to backward and forward compatibility issues.  Isn't it too
much?



More information about the Digitalmars-d mailing list