ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
numberformat.cpp
1//##################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6//##################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14//========================================= Global Fragment ========================================
16#include <locale.h>
17//============================================== Module ============================================
18#if ALIB_C20_MODULES
19 module ALib.Strings;
20#else
21# include "ALib.Strings.H"
22#endif
23//========================================== Implementation ========================================
24namespace alib { namespace strings {
25
26#if !DOXYGEN
27//##################################################################################################
28// Set methods
29//##################################################################################################
30
31template<typename TChar>
33 struct lconv * lc=localeconv();
34
35 DecimalPointChar= static_cast<TChar>( *(lc->decimal_point) );
36 ThousandsGroupChar= static_cast<TChar>( *(lc->thousands_sep) );
37}
38
39template<typename TChar>
41 if ( other == nullptr )
42 other= &Global;
43
44 // let C++ do the job
45 *this= *other;
46}
47
48namespace {
49 template<typename TChar>
50void setComputational( TNumberFormat<TChar>& nf ) {
51 nf.Flags = NumberFormatFlags::ForceDecimalPoint;
52 nf.DecimalPointChar = '.';
53 nf.Whitespaces = CStringConstantsTraits<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 setComputational( *this );
85
86 ExponentSeparator = "E" ;
87 INFLiteral = "INF" ;
88 NANLiteral = "NAN" ;
89 BinLiteralPrefix = "0b" ;
90 HexLiteralPrefix = "0x" ;
91 OctLiteralPrefix = "0o" ;
92}
93
94template<>
96 setComputational( *this );
97
98 ExponentSeparator = A_WCHAR( "E" ) ;
99 INFLiteral = A_WCHAR( "INF" ) ;
100 NANLiteral = A_WCHAR( "NAN" ) ;
101 BinLiteralPrefix = A_WCHAR( "0b" ) ;
102 HexLiteralPrefix = A_WCHAR( "0x" ) ;
103 OctLiteralPrefix = A_WCHAR( "0o" ) ;
104}
105
106template<>
108 setComputational( *this );
109
110 ExponentSeparator = A_XCHAR( "E" ) ;
111 INFLiteral = A_XCHAR( "INF" ) ;
112 NANLiteral = A_XCHAR( "NAN" ) ;
113 BinLiteralPrefix = A_XCHAR( "0b" ) ;
114 HexLiteralPrefix = A_XCHAR( "0x" ) ;
115 OctLiteralPrefix = A_XCHAR( "0o" ) ;
116}
117
118
125
126#endif // !DOXYGEN
127
128}} // namespace [alib::strings]
#define A_XCHAR(STR)
#define A_WCHAR(STR)
@ Global
Denotes the global (singleton) scope.
void Set(TNumberFormat *other=nullptr)