ALib C++ Library
Library Version: 2510 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{
34 struct lconv * lc=localeconv();
35
36 DecimalPointChar= static_cast<TChar>( *(lc->decimal_point) );
37 ThousandsGroupChar= static_cast<TChar>( *(lc->thousands_sep) );
38}
39
40template<typename TChar>
42{
43 if ( other == nullptr )
44 other= &Global;
45
46 // let C++ do the job
47 *this= *other;
48}
49
50namespace {
51 template<typename TChar>
52 void setComputational( TNumberFormat<TChar>& nf )
53 {
54 nf.Flags = NumberFormatFlags::ForceDecimalPoint;
55 nf.DecimalPointChar = '.';
56 nf.Whitespaces = CStringConstantsTraits<TChar>::DefaultWhitespaces();
57 nf.PlusSign = '\0';
58
59 // automatic field width (->minimum size of maximum accuracy)
60 nf.DecMinimumFieldWidth=
61 nf.BinFieldWidth=
62 nf.HexFieldWidth=
63 nf.OctFieldWidth=
64 nf.IntegralPartMinimumWidth=
65 nf.FractionalPartWidth= -1;
66
67 // group characters
68 nf.LeadingGroupCharReplacement= ' ';
69
70 nf.ThousandsGroupChar= ',';
71
72 nf.BinNibbleGroupChar=
73 nf.HexWordGroupChar=
74 nf.HexWord32GroupChar=
75 nf.OctGroupChar= '\'';
76
77 nf.HexByteGroupChar= '\0';
78 nf.BinByteGroupChar= '-';
79 nf.BinWordGroupChar= '=';
80 nf.BinWord32GroupChar= '#';
81
82 }
83}
84
85template<>
87{
88 setComputational( *this );
89
90 ExponentSeparator = "E" ;
91 INFLiteral = "INF" ;
92 NANLiteral = "NAN" ;
93 BinLiteralPrefix = "0b" ;
94 HexLiteralPrefix = "0x" ;
95 OctLiteralPrefix = "0o" ;
96}
97
98template<>
100{
101 setComputational( *this );
102
103 ExponentSeparator = A_WCHAR( "E" ) ;
104 INFLiteral = A_WCHAR( "INF" ) ;
105 NANLiteral = A_WCHAR( "NAN" ) ;
106 BinLiteralPrefix = A_WCHAR( "0b" ) ;
107 HexLiteralPrefix = A_WCHAR( "0x" ) ;
108 OctLiteralPrefix = A_WCHAR( "0o" ) ;
109}
110
111template<>
113{
114 setComputational( *this );
115
116 ExponentSeparator = A_XCHAR( "E" ) ;
117 INFLiteral = A_XCHAR( "INF" ) ;
118 NANLiteral = A_XCHAR( "NAN" ) ;
119 BinLiteralPrefix = A_XCHAR( "0b" ) ;
120 HexLiteralPrefix = A_XCHAR( "0x" ) ;
121 OctLiteralPrefix = A_XCHAR( "0o" ) ;
122}
123
124
131
132#endif // !DOXYGEN
133
134}} // namespace [alib::strings]
135
#define A_XCHAR(STR)
#define A_WCHAR(STR)
@ Global
Denotes the global (singleton) scope.
void Set(TNumberFormat *other=nullptr)