1 // Copyright (C) 1997-2018 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
17 
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21 // <http://www.gnu.org/licenses/>.
22 
23 #define _GLIBCXX_USE_CXX11_ABI 0
24 #include <locale>
25 
26 namespace std _GLIBCXX_VISIBILITY(default)
27 {
28 _GLIBCXX_BEGIN_NAMESPACE_VERSION
29 
30   // Definitions for static const data members of time_base.
31   template<>
32     const char*
33     __timepunct_cache<char>::_S_timezones[14] =
34     {
35       "GMT", "HST", "AKST", "PST", "MST", "CST", "EST", "AST", "NST", "CET",
36       "IST", "EET", "CST", "JST"
37     };
38 
39 #ifdef _GLIBCXX_USE_WCHAR_T
40   template<>
41     const wchar_t*
42     __timepunct_cache<wchar_t>::_S_timezones[14] =
43     {
44       L"GMT", L"HST", L"AKST", L"PST", L"MST", L"CST", L"EST", L"AST",
45       L"NST", L"CET", L"IST", L"EET", L"CST", L"JST"
46     };
47 #endif
48 
49   // Definitions for static const data members of money_base.
50   const money_base::pattern
51   money_base::_S_default_pattern =  { {symbol, sign, none, value} };
52 
53   const char* money_base::_S_atoms = "-0123456789";
54 
55   const char* __num_base::_S_atoms_in = "-+xX0123456789abcdefABCDEF";
56   const char* __num_base::_S_atoms_out ="-+xX0123456789abcdef0123456789ABCDEF";
57 
58   // _GLIBCXX_RESOLVE_LIB_DEFECTS
59   // According to the resolution of DR 231, about 22.2.2.2.2, p11,
60   // "str.precision() is specified in the conversion specification".
61   void
62   __num_base::_S_format_float(const ios_base& __io, char* __fptr,
63 			      char __mod) throw()
64   {
65     ios_base::fmtflags __flags = __io.flags();
66     *__fptr++ = '%';
67     // [22.2.2.2.2] Table 60
68     if (__flags & ios_base::showpos)
69       *__fptr++ = '+';
70     if (__flags & ios_base::showpoint)
71       *__fptr++ = '#';
72 
73     ios_base::fmtflags __fltfield = __flags & ios_base::floatfield;
74 
75 #if _GLIBCXX_USE_C99_STDIO
76     // Precision is always used except for hexfloat format.
77     if (__fltfield != (ios_base::fixed | ios_base::scientific))
78 #endif
79       {
80         // As per DR 231: not only when __flags & ios_base::fixed || __prec > 0
81         *__fptr++ = '.';
82         *__fptr++ = '*';
83       }
84 
85     if (__mod)
86       *__fptr++ = __mod;
87     // [22.2.2.2.2] Table 58
88     if (__fltfield == ios_base::fixed)
89       *__fptr++ = 'f';
90     else if (__fltfield == ios_base::scientific)
91       *__fptr++ = (__flags & ios_base::uppercase) ? 'E' : 'e';
92 #if _GLIBCXX_USE_C99_STDIO
93     else if (__fltfield == (ios_base::fixed | ios_base::scientific))
94       *__fptr++ = (__flags & ios_base::uppercase) ? 'A' : 'a';
95 #endif
96     else
97       *__fptr++ = (__flags & ios_base::uppercase) ? 'G' : 'g';
98     *__fptr = '\0';
99   }
100 
101   // This function is not exported but is needed internally, by the versions
102   // of __verify_grouping below and in src/c++11/cxx11-locale-inst.cc
103   extern bool
104   __verify_grouping_impl(const char* __grouping, size_t __grouping_size,
105                          const char* __grouping_tmp, size_t __grouping_tmp_size)
106   {
107     const size_t __n = __grouping_tmp_size - 1;
108     const size_t __min = std::min(__n, size_t(__grouping_size - 1));
109     size_t __i = __n;
110     bool __test = true;
111 
112     // Parsed number groupings have to match the
113     // numpunct::grouping string exactly, starting at the
114     // right-most point of the parsed sequence of elements ...
115     for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
116       __test = __grouping_tmp[__i] == __grouping[__j];
117     for (; __i && __test; --__i)
118       __test = __grouping_tmp[__i] == __grouping[__min];
119     // ... but the first parsed grouping can be <= numpunct
120     // grouping (only do the check if the numpunct char is > 0
121     // because <= 0 means any size is ok).
122     if (static_cast<signed char>(__grouping[__min]) > 0
123 	&& __grouping[__min] != __gnu_cxx::__numeric_traits<char>::__max)
124       __test &= __grouping_tmp[0] <= __grouping[__min];
125     return __test;
126   }
127 
128   bool
129   __verify_grouping(const char* __grouping, size_t __grouping_size,
130 		    const string& __grouping_tmp) throw()
131   {
132     return __verify_grouping_impl(__grouping, __grouping_size,
133                                   __grouping_tmp.c_str(),
134                                   __grouping_tmp.size());
135   }
136 
137 _GLIBCXX_END_NAMESPACE_VERSION
138 } // namespace
139