locale_facets.h
来自「ARM Linux Tool 各种代码包括MTD」· C头文件 代码 · 共 1,602 行 · 第 1/3 页
H
1,602 行
// Locale support -*- C++ -*-// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.//// This file is part of the GNU ISO C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// As a special exception, you may use this file as part of a free software// library without restriction. Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License. This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.//// ISO C++ 14882: 22.1 Locales//// Warning: this file is not meant for user inclusion. Use <locale>.#ifndef _CPP_BITS_LOCFACETS_H#define _CPP_BITS_LOCFACETS_H 1#pragma GCC system_header#include <bits/std_ctime.h> // For struct tm#include <bits/std_ios.h> // For ios_base#ifdef _GLIBCPP_USE_WCHAR_T# include <langinfo.h> // For codecvt# include <bits/std_cwctype.h> // For wctype_t# include <iconv.h> // For codecvt using iconv, iconv_t#endif namespace std{ // 22.2.1.1 Template class ctype // Include host-specific ctype enums for ctype_base. #include <bits/ctype_base.h> // __ctype_abstract_base is the common base for ctype<_CharT>. template<typename _CharT> class __ctype_abstract_base : public locale::facet, public ctype_base { public: // Types: typedef _CharT char_type; bool is(mask __m, char_type __c) const { return this->do_is(__m, __c); } const char_type* is(const char_type *__lo, const char_type *__hi, mask *__vec) const { return this->do_is(__lo, __hi, __vec); } const char_type* scan_is(mask __m, const char_type* __lo, const char_type* __hi) const { return this->do_scan_is(__m, __lo, __hi); } const char_type* scan_not(mask __m, const char_type* __lo, const char_type* __hi) const { return this->do_scan_not(__m, __lo, __hi); } char_type toupper(char_type __c) const { return this->do_toupper(__c); } const char_type* toupper(char_type *__lo, const char_type* __hi) const { return this->do_toupper(__lo, __hi); } char_type tolower(char_type __c) const { return this->do_tolower(__c); } const char_type* tolower(char_type* __lo, const char_type* __hi) const { return this->do_tolower(__lo, __hi); } char_type widen(char __c) const { return this->do_widen(__c); } const char* widen(const char* __lo, const char* __hi, char_type* __to) const { return this->do_widen(__lo, __hi, __to); } char narrow(char_type __c, char __dfault) const { return this->do_narrow(__c, __dfault); } const char_type* narrow(const char_type* __lo, const char_type* __hi, char __dfault, char *__to) const { return this->do_narrow(__lo, __hi, __dfault, __to); } protected: explicit __ctype_abstract_base(size_t __refs = 0): locale::facet(__refs) { } virtual ~__ctype_abstract_base() { } virtual bool do_is(mask __m, char_type __c) const = 0; virtual const char_type* do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const = 0; virtual const char_type* do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const = 0; virtual const char_type* do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const = 0; virtual char_type do_toupper(char_type) const = 0; virtual const char_type* do_toupper(char_type* __lo, const char_type* __hi) const = 0; virtual char_type do_tolower(char_type) const = 0; virtual const char_type* do_tolower(char_type* __lo, const char_type* __hi) const = 0; virtual char_type do_widen(char) const = 0; virtual const char* do_widen(const char* __lo, const char* __hi, char_type* __dest) const = 0; virtual char do_narrow(char_type, char __dfault) const = 0; virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const = 0; }; // NB: Generic, mostly useless implementation. template<typename _CharT> class ctype : public __ctype_abstract_base<_CharT> { public: // Types: typedef _CharT char_type; typedef typename ctype::mask mask; explicit ctype(size_t __refs = 0) : __ctype_abstract_base<_CharT>(__refs) { } static locale::id id; protected: virtual ~ctype() { } virtual bool do_is(mask __m, char_type __c) const { return false; } virtual const char_type* do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const { return __hi; } virtual const char_type* do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const { return __hi; } virtual const char_type* do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const { return __hi; } virtual char_type do_toupper(char_type __c) const { return __c; } virtual const char_type* do_toupper(char_type* __lo, const char_type* __hi) const { return __hi; } virtual char_type do_tolower(char_type __c) const { return __c; } virtual const char_type* do_tolower(char_type* __lo, const char_type* __hi) const { return __hi; } virtual char_type do_widen(char __c) const { return char_type(); } virtual const char* do_widen(const char* __lo, const char* __hi, char_type* __dest) const { return __hi; } virtual char do_narrow(char_type, char __dfault) const { return __dfault; } virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const { return __hi; } }; template<typename _CharT> locale::id ctype<_CharT>::id; // 22.2.1.3 ctype specializations template<> class ctype<char> : public __ctype_abstract_base<char> { public: // Types: typedef char char_type; private: // Data Members: bool _M_del; __to_type const& _M_toupper; __to_type const& _M_tolower; const mask* const& _M_ctable; const mask* _M_table; public: static locale::id id; static const size_t table_size = 1 + static_cast<unsigned char>(-1); explicit ctype(const mask* __table = 0, bool __del = false, size_t __refs = 0); inline bool is(mask __m, char __c) const; inline const char* is(const char* __lo, const char* __hi, mask* __vec) const; inline const char* scan_is(mask __m, const char* __lo, const char* __hi) const; inline const char* scan_not(mask __m, const char* __lo, const char* __hi) const; protected: virtual ~ctype(); const mask* table() const throw() { return _M_table; } const mask* classic_table() throw() { return _M_ctable; } virtual bool do_is(mask __m, char_type __c) const; virtual const char_type* do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; virtual const char_type* do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; virtual const char_type* do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const; virtual char_type do_toupper(char_type) const; virtual const char_type* do_toupper(char_type* __lo, const char_type* __hi) const; virtual char_type do_tolower(char_type) const; virtual const char_type* do_tolower(char_type* __lo, const char_type* __hi) const; virtual char_type do_widen(char) const; virtual const char* do_widen(const char* __lo, const char* __hi, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const; }; template<> const ctype<char>& use_facet<ctype<char> >(const locale& __loc);#ifdef _GLIBCPP_USE_WCHAR_T // ctype<wchar_t> specialization template<> class ctype<wchar_t> : public __ctype_abstract_base<wchar_t> { public: // Types: typedef wchar_t char_type; typedef wctype_t __wmask_type; // Data Members: static locale::id id; explicit ctype(size_t __refs = 0); protected: __wmask_type _M_convert_to_wmask(const mask __m) const; virtual ~ctype(); virtual bool do_is(mask __m, char_type __c) const; virtual const char_type* do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const; virtual const char_type* do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const; virtual const char_type* do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const; virtual char_type do_toupper(char_type) const; virtual const char_type* do_toupper(char_type* __lo, const char_type* __hi) const; virtual char_type do_tolower(char_type) const; virtual const char_type* do_tolower(char_type* __lo, const char_type* __hi) const; virtual char_type do_widen(char) const; virtual const char* do_widen(const char* __lo, const char* __hi, char_type* __dest) const; virtual char do_narrow(char_type, char __dfault) const; virtual const char_type* do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, char* __dest) const; }; template<> const ctype<wchar_t>& use_facet<ctype<wchar_t> >(const locale& __loc);#endif //_GLIBCPP_USE_WCHAR_T // Include host-specific ctype inlines. #include <bits/ctype_inline.h> // 22.2.1.2 Template class ctype_byname template<typename _CharT> class ctype_byname : public ctype<_CharT> { public: typedef _CharT char_type; explicit ctype_byname(const char*, size_t __refs = 0); protected: virtual ~ctype_byname() { } }; // 22.2.1.4 Class ctype_byname specialization template<> ctype_byname<char>::ctype_byname(const char*, size_t refs); // 22.2.1.5 Template class codecvt #include <bits/codecvt.h> template<typename _CharT, typename _InIter> class _Numeric_get; // forward // _Format_cache holds the information extracted from the numpunct<> // and moneypunct<> facets in a form optimized for parsing and // formatting. It is stored via a void* pointer in the pword() // array of an iosbase object passed to the _get and _put facets. // NB: contains no user-serviceable parts. template<typename _CharT> class _Format_cache { public: // Types: typedef _CharT char_type; typedef char_traits<_CharT> traits_type; typedef basic_string<_CharT> string_type; typedef typename string_type::size_type size_type; // Forward decls and Friends: friend class locale; template<typename _Char, typename _InIter> friend class _Numeric_get; friend class num_get<_CharT>; friend class num_put<_CharT>; friend class time_get<_CharT>; friend class money_get<_CharT>; friend class time_put<_CharT>; friend class money_put<_CharT>; // Data Members: // ios_base::pword() reserved cell static int _S_pword_ix; // True iff data members are consistent with the current locale, // ie imbue sets this to false. bool _M_valid; // A list of valid numeric literals: for the standard "C" locale, // this would usually be: "-+xX0123456789abcdef0123456789ABCDEF" static const char _S_literals[]; // NB: Code depends on the order of definitions of the names // these are indices into _S_literals, above. // This string is formatted for putting, not getting. (output, not input) enum { _S_minus, _S_plus, _S_x, _S_X, _S_digits, _S_digits_end = _S_digits + 16, _S_udigits = _S_digits_end, _S_udigits_end = _S_udigits + 16, _S_ee = _S_digits + 14, // For scientific notation, 'E' _S_Ee = _S_udigits + 14 // For scientific notation, 'e' }; // The sign used to separate decimal values: for standard US // locales, this would usually be: "." // Abstracted from numpunct::decimal_point(). char_type _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(). char_type _M_thousands_sep; // However the US's "false" and "true" are translated. // From numpunct::truename() and numpunct::falsename(), respectively. string_type _M_truename; string_type _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()). string _M_grouping; _Format_cache(); ~_Format_cache() throw() { } // Given a member of the ios heirarchy as an argument, extract // out all the current formatting information into a // _Format_cache object and return a pointer to it. static _Format_cache<_CharT>* _S_get(ios_base& __ios); void _M_populate(ios_base&); static void _S_callback(ios_base::event __event, ios_base& __ios, int __ix) throw(); }; template<typename _CharT> int _Format_cache<_CharT>::_S_pword_ix; template<typename _CharT> const char _Format_cache<_CharT>:: _S_literals[] = "-+xX0123456789abcdef0123456789ABCDEF"; template<> _Format_cache<char>::_Format_cache();#ifdef _GLIBCPP_USE_WCHAR_T template<> _Format_cache<wchar_t>::_Format_cache();#endif // _Numeric_get is used by num_get, money_get, and time_get to help // in parsing out numbers. template<typename _CharT, typename _InIter> class _Numeric_get { public:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?