ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
numberformat.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !defined(ALIB_DOX)
10#if !defined (HPP_ALIB_STRINGS_NUMBERFORMAT)
12#endif
13#endif // !defined(ALIB_DOX)
14
15#if defined( _WIN32 ) || defined(__APPLE__) || defined(__ANDROID_NDK__)
16# include <clocale>
17#endif
18
19namespace alib { namespace strings {
20
21#if !defined(ALIB_DOX)
22
23// #################################################################################################
24// Set methods
25// #################################################################################################
26
27template<typename TChar>
29{
30 struct lconv * lc=localeconv();
31
32 DecimalPointChar= static_cast<TChar>( *(lc->decimal_point) );
33 ThousandsGroupChar= static_cast<TChar>( *(lc->thousands_sep) );
34}
35
36template<typename TChar>
37void TNumberFormat<TChar>::Set( TNumberFormat* other )
38{
39 if ( other == nullptr )
40 other= &Global;
41
42 // let C++ do the job
43 *this= *other;
44}
45
46namespace {
47 template<typename TChar>
48 void setComputational( TNumberFormat<TChar>& nf )
49 {
50 nf.Flags = NumberFormatFlags::NONE;
51 nf.DecimalPointChar = '.';
52 nf.Flags = NumberFormatFlags( uint8_t(nf.Flags) | uint8_t(NumberFormatFlags::ForceDecimalPoint) );
53 nf.Whitespaces = TT_StringConstants<TChar>::DefaultWhitespaces();
54 nf.PlusSign = '\0';
55
56 // automatic field width (->minimum size of maximum accuracy)
57 nf.DecMinimumFieldWidth=
58 nf.BinFieldWidth=
59 nf.HexFieldWidth=
60 nf.OctFieldWidth=
61 nf.IntegralPartMinimumWidth=
62 nf.FractionalPartWidth= -1;
63
64 // group characters
65 nf.LeadingGroupCharReplacement= ' ';
66
67 nf.ThousandsGroupChar= ',';
68
69 nf.BinNibbleGroupChar=
70 nf.HexWordGroupChar=
71 nf.HexWord32GroupChar=
72 nf.OctGroupChar= '\'';
73
74 nf.HexByteGroupChar= '\0';
75 nf.BinByteGroupChar= '-';
76 nf.BinWordGroupChar= '=';
77 nf.BinWord32GroupChar= '#';
78
79 }
80}
81
82template<>
84{
85 setComputational( *this );
86
87 ExponentSeparator = "E" ;
88 INFLiteral = "INF" ;
89 NANLiteral = "NAN" ;
90 BinLiteralPrefix = "0b" ;
91 HexLiteralPrefix = "0x" ;
92 OctLiteralPrefix = "0o" ;
93}
94
95template<>
97{
98 setComputational( *this );
99
100 ExponentSeparator = A_WCHAR( "E" ) ;
101 INFLiteral = A_WCHAR( "INF" ) ;
102 NANLiteral = A_WCHAR( "NAN" ) ;
103 BinLiteralPrefix = A_WCHAR( "0b" ) ;
104 HexLiteralPrefix = A_WCHAR( "0x" ) ;
105 OctLiteralPrefix = A_WCHAR( "0o" ) ;
106}
107
108template<>
110{
111 setComputational( *this );
112
113 ExponentSeparator = A_XCHAR( "E" ) ;
114 INFLiteral = A_XCHAR( "INF" ) ;
115 NANLiteral = A_XCHAR( "NAN" ) ;
116 BinLiteralPrefix = A_XCHAR( "0b" ) ;
117 HexLiteralPrefix = A_XCHAR( "0x" ) ;
118 OctLiteralPrefix = A_XCHAR( "0o" ) ;
119}
120
121
122template void TNumberFormat<nchar>::Set ( TNumberFormat*);
124template void TNumberFormat<wchar>::Set ( TNumberFormat*);
126template void TNumberFormat<xchar>::Set ( TNumberFormat*);
128
129#endif // HPP_ALIB_STRINGS_DETAIL_NUMBERCONVERSION
130
131}} // namespace [alib::strings]
#define A_XCHAR(STR)
#define A_WCHAR(STR)
Definition alib.cpp:57
void Set(TNumberFormat *other=nullptr)