A C++ implementation defines both:
1) the named locales that are available and
2) the definitions of the facets contained in each locale.
The C++ standard has no say in the matter (except that each implementation must define the classic "C" locale.
Thus, even if a particular locale is defined by an implementation, there is no guarantee that its contained facets encapsulate conventions appropriate for the culture indicated by the locale's name.
For example, consider coliru. It defines the "de_DE.utf8" named locale. This is expected to be the locale that encapsulates German conventions. ("de" stands for Deutsch, the German name for "German".) However, this isn't the case:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <locale>
#include <iostream>
using namespace std;
int main()
{
locale german {"de_DE.utf8"};
const numpunct<char>& fac =
use_facet<numpunct<char>> (german);
cout << "decimal point in German: "
<< fac.decimal_point() << endl << endl;
cout << "true in German: " << fac.truename() << endl;
cout << "false in German: " << fac.falsename() << endl ;
}
|
http://coliru.stacked-crooked.com/a/8e9de2cb88d03c6f
Here's the output:
decimal point in German: ,
true in German: true
false in German: false
|
We see the following:
1) The decimal point in German is defined correctly as , rather than .
2) The German names for "true" and "false" are "wahr" and "falsch", but the locale defines them as "true" and "false" instead.
Thus, we really can't depend on an implementation's definition of a POSIX or Microsoft locale.
To get a locale's correct definition, the following are perhaps the only options:
1) Use boost.locale in conjunction with ICU.
2) If interested in a certain set of conventions, write custom facets, generate a new locale from an existing one plus the custom facets and use the custom locale.
The 2nd option would be more efficient in space.
By the way, if I need to create a new locale containing 2 new facets, are 2 steps required?
1) Create locale1 from an existing one, adding the 1st new facet.
2) Create locale2 from locale1, adding the 2nd new facet.
This is because the available locale ctor allows us to add only 1 facet pointer at a time.
Thanks.