- locale::locale(const char* __s)
- {
- if (__s)
- {
- _S_initialize();
- if (strcmp(__s, "C") == 0 || strcmp(__s, "POSIX") == 0)
- (_M_impl = _S_classic)->_M_add_reference();
- else if (strcmp(__s, "") != 0)
- _M_impl = new _Impl(__s, 1);
- else
- {
- // Get it from the environment.
- char* __env = getenv("LC_ALL");
- // If LC_ALL is set we are done.
- if (__env && strcmp(__env, "") != 0)
- {
- if (strcmp(__env, "C") == 0 || strcmp(__env, "POSIX") == 0)
- (_M_impl = _S_classic)->_M_add_reference();
- else
- _M_impl = new _Impl(__env, 1);
- }
- else
- {
- char* __res;
- // LANG may set a default different from "C".
- char* __env = getenv("LANG");
- if (!__env || strcmp(__env, "") == 0 || strcmp(__env, "C") == 0
- || strcmp(__env, "POSIX") == 0)
- __res = strdup("C");
- else
- __res = strdup(__env);
-
- // Scan the categories looking for the first one
- // different from LANG.
- size_t __i = 0;
- if (strcmp(__res, "C") == 0)
- for (__i = 0;
- __i < _S_categories_size + _S_extra_categories_size;
- ++__i)
- {
- __env = getenv(_S_categories[__i]);
- if (__env && strcmp(__env, "") != 0
- && strcmp(__env, "C") != 0
- && strcmp(__env, "POSIX") != 0)
- break;
- }
- else
- for (__i = 0;
- __i < _S_categories_size + _S_extra_categories_size;
- ++__i)
- {
- __env = getenv(_S_categories[__i]);
- if (__env && strcmp(__env, "") != 0
- && strcmp(__env, __res) != 0)
- break;
- }
-
- // If one is found, build the complete string of
- // the form LC_CTYPE=xxx;LC_NUMERIC=yyy; and so on...
- if (__i < _S_categories_size + _S_extra_categories_size)
- {
- string __str;
- for (size_t __j = 0; __j < __i; ++__j)
- {
- __str += _S_categories[__j];
- __str += "=";
- __str += __res;
- __str += ";";
- }
- __str += _S_categories[__i];
- __str += "=";
- __str += __env;
- __str += ";";
- __i++;
- for (; __i < _S_categories_size
- + _S_extra_categories_size; ++__i)
- {
- __env = getenv(_S_categories[__i]);
- if (!__env || strcmp(__env, "") == 0)
- {
- __str += _S_categories[__i];
- __str += '=';
- __str += __res;
- __str += ';';
- }
- else if (strcmp(__env, "C") == 0
- || strcmp(__env, "POSIX") == 0)
- {
- __str += _S_categories[__i];
- __str += "=C;";
- }
- else
- {
- __str += _S_categories[__i];
- __str += "=";
- __str += __env;
- __str += ";";
- }
- }
- __str.erase(__str.end() - 1);
- _M_impl = new _Impl(__str.c_str(), 1);
- }
- // ... otherwise either an additional instance of
- // the "C" locale or LANG.
- else if (strcmp(__res, "C") == 0)
- (_M_impl = _S_classic)->_M_add_reference();
- else
- _M_impl = new _Impl(__res, 1);
- free(__res);
- }
- }
- }
- else
- __throw_runtime_error("attempt to create locale from NULL name");
- }
-
- locale::locale(const locale& __base, const char* __s, category __cat)
- {
- // NB: There are complicated, yet more efficient ways to do
- // this. Building up locales on a per-category way is tedious, so
- // let's do it this way until people complain.
- locale __add(__s);
- _M_coalesce(__base, __add, __cat);
- }
-
- locale::locale(const locale& __base, const locale& __add, category __cat)
- { _M_coalesce(__base, __add, __cat); }
-