ALib C++ Library
Library Version: 2412 R0
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 !DOXYGEN
11#endif
12#if defined( _WIN32 ) || defined(__APPLE__) || defined(__ANDROID_NDK__)
13# include <clocale>
14#endif
15
16namespace alib { namespace strings {
17
18#if !DOXYGEN
19
20// #################################################################################################
21// Set methods
22// #################################################################################################
23
24template<typename TChar>
26{
27 struct lconv * lc=localeconv();
28
29 DecimalPointChar= static_cast<TChar>( *(lc->decimal_point) );
30 ThousandsGroupChar= static_cast<TChar>( *(lc->thousands_sep) );
31}
32
33template<typename TChar>
34void TNumberFormat<TChar>::Set( TNumberFormat* other )
35{
36 if ( other == nullptr )
37 other= &Global;
38
39 // let C++ do the job
40 *this= *other;
41}
42
43namespace {
44 template<typename TChar>
45 void setComputational( TNumberFormat<TChar>& nf )
46 {
47 nf.Flags = NumberFormatFlags::ForceDecimalPoint;
48 nf.DecimalPointChar = '.';
49 nf.Whitespaces = TT_CStringConstants<TChar>::DefaultWhitespaces();
50 nf.PlusSign = '\0';
51
52 // automatic field width (->minimum size of maximum accuracy)
53 nf.DecMinimumFieldWidth=
54 nf.BinFieldWidth=
55 nf.HexFieldWidth=
56 nf.OctFieldWidth=
57 nf.IntegralPartMinimumWidth=
58 nf.FractionalPartWidth= -1;
59
60 // group characters
61 nf.LeadingGroupCharReplacement= ' ';
62
63 nf.ThousandsGroupChar= ',';
64
65 nf.BinNibbleGroupChar=
66 nf.HexWordGroupChar=
67 nf.HexWord32GroupChar=
68 nf.OctGroupChar= '\'';
69
70 nf.HexByteGroupChar= '\0';
71 nf.BinByteGroupChar= '-';
72 nf.BinWordGroupChar= '=';
73 nf.BinWord32GroupChar= '#';
74
75 }
76}
77
78template<>
80{
81 setComputational( *this );
82
83 ExponentSeparator = "E" ;
84 INFLiteral = "INF" ;
85 NANLiteral = "NAN" ;
86 BinLiteralPrefix = "0b" ;
87 HexLiteralPrefix = "0x" ;
88 OctLiteralPrefix = "0o" ;
89}
90
91template<>
93{
94 setComputational( *this );
95
96 ExponentSeparator = A_WCHAR( "E" ) ;
97 INFLiteral = A_WCHAR( "INF" ) ;
98 NANLiteral = A_WCHAR( "NAN" ) ;
99 BinLiteralPrefix = A_WCHAR( "0b" ) ;
100 HexLiteralPrefix = A_WCHAR( "0x" ) ;
101 OctLiteralPrefix = A_WCHAR( "0o" ) ;
102}
103
104template<>
106{
107 setComputational( *this );
108
109 ExponentSeparator = A_XCHAR( "E" ) ;
110 INFLiteral = A_XCHAR( "INF" ) ;
111 NANLiteral = A_XCHAR( "NAN" ) ;
112 BinLiteralPrefix = A_XCHAR( "0b" ) ;
113 HexLiteralPrefix = A_XCHAR( "0x" ) ;
114 OctLiteralPrefix = A_XCHAR( "0o" ) ;
115}
116
117
118template void TNumberFormat<nchar>::Set ( TNumberFormat*);
120template void TNumberFormat<wchar>::Set ( TNumberFormat*);
122template void TNumberFormat<xchar>::Set ( TNumberFormat*);
124
125#endif // !DOXYGEN
126
127}} // namespace [alib::strings]
128
#define A_XCHAR(STR)
#define A_WCHAR(STR)
@ Global
Denotes the global (singleton) scope.
Definition alib.cpp:69
void Set(TNumberFormat *other=nullptr)