named locale error checking
Benjamin Kosnik
bkoz@redhat.com
Thu Jun 28 15:30:00 GMT 2001
I've a question about how to handle error checking in named
locales. Under linux, available locales can be found by doing `locale
-a` at shell prompt.
However, these available locales are not necessarily complete. If I
construct locales such as:
locale loc_us("en_US");
locale loc_fr("fr_FR");
locale loc_de("de_DE");
const numpunct<char>& nump_fr = use_facet<numpunct<char> >(loc_fr);
const numpunct<char>& nump_de = use_facet<numpunct<char> >(loc_de);
One can see that
(gdb) p nump_fr
$5 = (numpunct<char> &) @0x8109998: {<facet> = {_vptr.facet = 0x80e76a8,
_M_references = 0}, static id = {_M_index = 8, static _S_highwater = 26},
_M_decimal_point = 44 ',', _M_thousands_sep = 0 '\000', _M_grouping = {
static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x810730c "ÿÿ"}, static _S_empty_rep_storage = {0, 0, 23, 0}},
_M_truename = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x8107614 "true"}, static _S_empty_rep_storage = {0, 0, 23, 0}},
_M_falsename = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x810762c "false"}, static _S_empty_rep_storage = {0, 0, 23, 0}}}
(gdb) p nump_de
$6 = (numpunct<char> &) @0x810a0c8: {<facet> = {_vptr.facet = 0x80e76a8,
_M_references = 0}, static id = {_M_index = 8, static _S_highwater = 26},
_M_decimal_point = 44 ',', _M_thousands_sep = 46 '.', _M_grouping = {
static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x8107dec "\003\003"}, static _S_empty_rep_storage = {0, 0, 23,
0}}, _M_truename = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x810765c "true"}, static _S_empty_rep_storage = {0, 0, 23, 0}},
_M_falsename = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x8107674 "false"}, static _S_empty_rep_storage = {0, 0, 23, 0}}}
In this case, nump_de is "mostly complete" in that everything except
for _M_truename/_M_falsename is correct. (Getting correct true/false
is not possible, only yes/no strings are localized.)
However, nump_fr isn't complete: _M_grouping isn't set, for one.
Currently, v3 doesn't do error checking, but I think it should. In
22.1.1.2 locale constructor and destructor, p 6:
explicit locale(const char* name)
Throws: runtime_error if the argument is not valid or is null
Notes: the set of valid string arguments is "C", "*", and
implementation-defined values.
I'm thinking that even though "FR_fr" is a valid name, runtime_error
should be thrown in the creation of the numpunct facet, because the
info isn't complete (say runtime_error("numpunct facet
incomplete").
In essence, this clarifies "valid name" to mean "we can construct a
useful facet from the underlying OS" instead of "something by the name
of that locale exists in the underlying OS"
Does this seem sane to anybody else besides me?
-benjamin
More information about the Libstdc++
mailing list