📄 locale_facets.h
字号:
string_type positive_sign() const { return this->do_positive_sign(); } string_type negative_sign() const { return this->do_negative_sign(); } int frac_digits() const { return this->do_frac_digits(); } pattern pos_format() const { return this->do_pos_format(); } pattern neg_format() const { return this->do_neg_format(); } protected: virtual ~moneypunct(); virtual char_type do_decimal_point() const { return _M_decimal_point; } virtual char_type do_thousands_sep() const { return _M_thousands_sep; } virtual string do_grouping() const { return _M_grouping; } virtual string_type do_curr_symbol() const { return _M_curr_symbol; } virtual string_type do_positive_sign() const { return _M_positive_sign; } virtual string_type do_negative_sign() const { return _M_negative_sign; } virtual int do_frac_digits() const { return _M_frac_digits; } virtual pattern do_pos_format() const { return _M_pos_format; } virtual pattern do_neg_format() const { return _M_neg_format; } // For use at construction time only. void _M_initialize_moneypunct(__c_locale __cloc = NULL, const char* __name = NULL); }; template<typename _CharT, bool _Intl> locale::id moneypunct<_CharT, _Intl>::id; template<typename _CharT, bool _Intl> const bool moneypunct<_CharT, _Intl>::intl; template<> moneypunct<char, true>::~moneypunct(); template<> moneypunct<char, false>::~moneypunct(); template<> void moneypunct<char, true>::_M_initialize_moneypunct(__c_locale, const char*); template<> void moneypunct<char, false>::_M_initialize_moneypunct(__c_locale, const char*);#ifdef _GLIBCPP_USE_WCHAR_T template<> moneypunct<wchar_t, true>::~moneypunct(); template<> moneypunct<wchar_t, false>::~moneypunct(); template<> void moneypunct<wchar_t, true>::_M_initialize_moneypunct(__c_locale, const char*); template<> void moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale, const char*);#endif template<typename _CharT, bool _Intl> class moneypunct_byname : public moneypunct<_CharT, _Intl> { __c_locale _M_c_locale_moneypunct; public: typedef _CharT char_type; typedef basic_string<_CharT> string_type; static const bool intl = _Intl; explicit moneypunct_byname(const char* __s, size_t __refs = 0) : moneypunct<_CharT, _Intl>(__refs) { _S_create_c_locale(_M_c_locale_moneypunct, __s); _M_initialize_moneypunct(_M_c_locale_moneypunct); } protected: virtual ~moneypunct_byname() { _S_destroy_c_locale(_M_c_locale_moneypunct); } }; template<typename _CharT, bool _Intl> const bool moneypunct_byname<_CharT, _Intl>::intl; template<typename _CharT, typename _InIter> class money_get : public locale::facet { public: // Types: typedef _CharT char_type; typedef _InIter iter_type; typedef basic_string<_CharT> string_type; static locale::id id; explicit money_get(size_t __refs = 0) : locale::facet(__refs) { } iter_type get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, long double& __units) const { return this->do_get(__s, __end, __intl, __io, __err, __units); } iter_type get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, string_type& __digits) const { return this->do_get(__s, __end, __intl, __io, __err, __digits); } protected: virtual ~money_get() { } virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, long double& __units) const; virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, string_type& __digits) const; }; template<typename _CharT, typename _InIter> locale::id money_get<_CharT, _InIter>::id; template<typename _CharT, typename _OutIter> class money_put : public locale::facet { public: typedef _CharT char_type; typedef _OutIter iter_type; typedef basic_string<_CharT> string_type; static locale::id id; explicit money_put(size_t __refs = 0) : locale::facet(__refs) { } iter_type put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, long double __units) const { return this->do_put(__s, __intl, __io, __fill, __units); } iter_type put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, const string_type& __digits) const { return this->do_put(__s, __intl, __io, __fill, __digits); } protected: virtual ~money_put() { } virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, long double __units) const; virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, const string_type& __digits) const; }; template<typename _CharT, typename _OutIter> locale::id money_put<_CharT, _OutIter>::id; struct messages_base { typedef int catalog; }; template<typename _CharT> class messages : public locale::facet, public messages_base { public: // Types: typedef _CharT char_type; typedef basic_string<_CharT> string_type; protected: // Underlying "C" library locale information saved from // initialization, needed by messages_byname as well. __c_locale _M_c_locale_messages; char* _M_name_messages; public: static locale::id id; explicit messages(size_t __refs = 0); // Non-standard. explicit messages(__c_locale __cloc, const char* __s, size_t __refs = 0); catalog open(const basic_string<char>& __s, const locale& __loc) const { return this->do_open(__s, __loc); } // Non-standard and unorthodox, yet effective. catalog open(const basic_string<char>&, const locale&, const char*) const; string_type get(catalog __c, int __set, int __msgid, const string_type& __s) const { return this->do_get(__c, __set, __msgid, __s); } void close(catalog __c) const { return this->do_close(__c); } protected: virtual ~messages(); virtual catalog do_open(const basic_string<char>&, const locale&) const; virtual string_type do_get(catalog, int, int, const string_type& __dfault) const; virtual void do_close(catalog) const; // Returns a locale and codeset-converted string, given a char* message. char* _M_convert_to_char(const string_type& __msg) const { // XXX return reinterpret_cast<char*>(const_cast<_CharT*>(__msg.c_str())); } // Returns a locale and codeset-converted string, given a char* message. string_type _M_convert_from_char(char* __msg) const { // Length of message string without terminating null. size_t __len = char_traits<char>::length(__msg) - 1; // "everybody can easily convert the string using // mbsrtowcs/wcsrtombs or with iconv()"#if 0 // Convert char* to _CharT in locale used to open catalog. // XXX need additional template parameter on messages class for this.. // typedef typename codecvt<char, _CharT, _StateT> __codecvt_type; typedef typename codecvt<char, _CharT, mbstate_t> __codecvt_type; __codecvt_type::state_type __state; // XXX may need to initialize state. //initialize_state(__state._M_init()); char* __from_next; // XXX what size for this string? _CharT* __to = static_cast<_CharT*>(__builtin_alloca(__len + 1)); const __codecvt_type& __cvt = use_facet<__codecvt_type>(_M_locale_conv); __cvt.out(__state, __msg, __msg + __len, __from_next, __to, __to + __len + 1, __to_next); return string_type(__to);#endif#if 0 typedef ctype<_CharT> __ctype_type; // const __ctype_type& __cvt = use_facet<__ctype_type>(_M_locale_msg); const __ctype_type& __cvt = use_facet<__ctype_type>(locale()); // XXX Again, proper length of converted string an issue here. // For now, assume the converted length is not larger. _CharT* __dest = static_cast<_CharT*>(__builtin_alloca(__len + 1)); __cvt.widen(__msg, __msg + __len, __dest); return basic_string<_CharT>(__dest);#endif return string_type(); } }; template<typename _CharT> locale::id messages<_CharT>::id; // Specializations for required instantiations. template<> string messages<char>::do_get(catalog, int, int, const string&) const;#ifdef _GLIBCPP_USE_WCHAR_T template<> wstring messages<wchar_t>::do_get(catalog, int, int, const wstring&) const;#endif template<typename _CharT> class messages_byname : public messages<_CharT> { public: typedef _CharT char_type; typedef basic_string<_CharT> string_type; explicit messages_byname(const char* __s, size_t __refs = 0); protected: virtual ~messages_byname() { } }; // Include host and configuration specific messages functions. #include <bits/messages_members.h> // Subclause convenience interfaces, inlines. // NB: These are inline because, when used in a loop, some compilers // can hoist the body out of the loop; then it's just as fast as the // C is*() function. template<typename _CharT> inline bool isspace(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); } template<typename _CharT> inline bool isprint(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); } template<typename _CharT> inline bool iscntrl(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); } template<typename _CharT> inline bool isupper(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); } template<typename _CharT> inline bool islower(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); } template<typename _CharT> inline bool isalpha(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); } template<typename _CharT> inline bool isdigit(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); } template<typename _CharT> inline bool ispunct(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); } template<typename _CharT> inline bool isxdigit(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); } template<typename _CharT> inline bool isalnum(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); } template<typename _CharT> inline bool isgraph(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); } template<typename _CharT> inline _CharT toupper(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).toupper(__c); } template<typename _CharT> inline _CharT tolower(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).tolower(__c); } /** * @if maint * __locale_cache objects hold information extracted from facets in * a form optimized for parsing and formatting. They are stored in * a locale's facet array and accessed via __use_cache<_Facet>. * * The intent twofold: to avoid the costs of creating a locale * object and to avoid calling the virtual functions in a locale's * facet to look up data. * @endif */ class __locale_cache_base { friend class std::locale::_Impl; friend class locale; public: virtual ~__locale_cache_base() { } }; // This template doesn't really get used for anything except a // placeholder for specializations template<typename _Facet> class __locale_cache : public __locale_cache_base { // ctor __locale_cache(const locale&) {} }; template<typename _CharT> class __locale_cache<numpunct<_CharT> > : public __locale_cache_base { // Types: typedef _CharT char_type; typedef char_traits<_CharT> traits_type; typedef basic_string<_CharT> string_type; public: // Data Members: // The sign used to separate decimal values: for standard US // locales, this would usually be: "." Abstracted from // numpunct::decimal_point(). _CharT _M_decimal_point; // The sign used to separate groups of digits into smaller // strings that the eye can parse with less difficulty: for // standard US locales, this would usually be: "," Abstracted // from numpunct::thousands_sep(). _CharT _M_thousands_sep; // However the US's "false" and "true" are translated. From // numpunct::truename() and numpunct::falsename(), respectively. const _CharT* _M_truename; const _CharT* _M_falsename; // If we are checking groupings. This should be equivalent to // numpunct::groupings().size() != 0 bool _M_use_grouping; // If we are using numpunct's groupings, this is the current // grouping string in effect (from numpunct::grouping()). const char* _M_grouping; // A list of valid numeric literals: for the standard "C" // locale, this is "-+xX0123456789abcdef0123456789ABCDEF". This // array contains the chars after having been passed through the // current locale's ctype<_CharT>.widen(). // Copied here from __locale_cache<ctype> to save multiple cache // access in num_put functions. _CharT _M_atoms_out[__num_base::_S_end]; // ctor __locale_cache(const locale& __loc); __locale_cache(const locale& __loc, bool); ~__locale_cache() { delete [] _M_truename; delete [] _M_falsename; delete [] _M_grouping; } };} // namespace std#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -