ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
substring.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#include <cstdint>
18#include <typeinfo>
19// =========================================== Module ==========================================
20#if ALIB_C20_MODULES
21 module ALib.Strings;
22 import ALib.Lang;
23#else
24# include "ALib.Lang.H"
25# include "ALib.Strings.H"
26#endif
27// ====================================== Implementation =======================================
28// Windows.h might bring in max/min macros
29#if defined( max )
30 #undef max
31 #undef min
32#endif
33
34namespace alib { namespace strings {
35
36template<typename TChar>
38{
39 integer idx= 0;
40 result= detail::ParseDecDigits( *this, idx );
41 if( idx > 0 )
42 {
43 ConsumeChars<NC>( idx );
44 return true;
45 }
46 return false;
47}
48
49template<typename TChar>
50bool TSubstring<TChar>::consumeIntImpl( int64_t& result, TNumberFormat<TChar>* numberFormat )
51{
52 if ( numberFormat == nullptr )
54
55 integer idx= 0;
56 result= detail::ParseInt( *this, idx, *numberFormat );
57 if( idx > 0 )
58 {
59 ConsumeChars<NC>( idx );
60 return true;
61 }
62 return false;
63}
64
65template<typename TChar>
66bool TSubstring<TChar>::consumeDecImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat )
67{
68 if ( numberFormat == nullptr )
70
71 integer idx= 0;
72 result= detail::ParseDec( *this, idx, *numberFormat );
73 if( idx > 0 )
74 {
75 ConsumeChars<NC>( idx );
76 return true;
77 }
78 return false;
79}
80
81template<typename TChar>
82bool TSubstring<TChar>::consumeBinImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat )
83{
84 if ( numberFormat == nullptr )
86
87 integer idx= 0;
88 result= detail::ParseBin( *this, idx, *numberFormat );
89 if( idx > 0 )
90 {
91 ConsumeChars<NC>( idx );
92 return true;
93 }
94 return false;
95}
96
97template<typename TChar>
98bool TSubstring<TChar>::consumeHexImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat )
99{
100 if ( numberFormat == nullptr )
102
103 integer idx= 0;
104 result= detail::ParseHex( *this, idx, *numberFormat );
105 if( idx > 0 )
106 {
107 ConsumeChars<NC>( idx );
108 return true;
109 }
110 return false;
111}
112
113template<typename TChar>
114bool TSubstring<TChar>::consumeOctImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat )
115{
116 if ( numberFormat == nullptr )
118
119 integer idx= 0;
120 result= detail::ParseOct( *this, idx, *numberFormat );
121 if( idx > 0 )
122 {
123 ConsumeChars<NC>( idx );
124 return true;
125 }
126 return false;
127}
128
129template<typename TChar>
131 TNumberFormat<TChar>* numberFormat )
132{
133 if ( numberFormat == nullptr )
135
136 integer idx= 0;
137 result= detail::ParseFloat( *this, idx, *numberFormat );
138 if( idx > 0 )
139 {
140 ConsumeChars<NC>( idx );
141 return true;
142 }
143 return false;
144}
145
146
147template bool TSubstring<nchar>::ConsumeFloat ( double& , TNumberFormat<nchar>* );
148template bool TSubstring<nchar>::consumeDecDigitsImpl( uint64_t& );
149template bool TSubstring<nchar>::consumeIntImpl ( int64_t& , TNumberFormat<nchar>* );
150template bool TSubstring<nchar>::consumeDecImpl ( uint64_t& , TNumberFormat<nchar>* );
151template bool TSubstring<nchar>::consumeBinImpl ( uint64_t& , TNumberFormat<nchar>* );
152template bool TSubstring<nchar>::consumeHexImpl ( uint64_t& , TNumberFormat<nchar>* );
153template bool TSubstring<nchar>::consumeOctImpl ( uint64_t& , TNumberFormat<nchar>* );
154
155template bool TSubstring<wchar>::ConsumeFloat ( double& , TNumberFormat<wchar>* );
156template bool TSubstring<wchar>::consumeDecDigitsImpl( uint64_t& );
157template bool TSubstring<wchar>::consumeIntImpl ( int64_t& , TNumberFormat<wchar>* );
158template bool TSubstring<wchar>::consumeDecImpl ( uint64_t& , TNumberFormat<wchar>* );
159template bool TSubstring<wchar>::consumeBinImpl ( uint64_t& , TNumberFormat<wchar>* );
160template bool TSubstring<wchar>::consumeHexImpl ( uint64_t& , TNumberFormat<wchar>* );
161template bool TSubstring<wchar>::consumeOctImpl ( uint64_t& , TNumberFormat<wchar>* );
162
163template bool TSubstring<xchar>::ConsumeFloat ( double& , TNumberFormat<xchar>* );
164template bool TSubstring<xchar>::consumeDecDigitsImpl( uint64_t& );
165template bool TSubstring<xchar>::consumeIntImpl ( int64_t& , TNumberFormat<xchar>* );
166template bool TSubstring<xchar>::consumeDecImpl ( uint64_t& , TNumberFormat<xchar>* );
167template bool TSubstring<xchar>::consumeBinImpl ( uint64_t& , TNumberFormat<xchar>* );
168template bool TSubstring<xchar>::consumeHexImpl ( uint64_t& , TNumberFormat<xchar>* );
169template bool TSubstring<xchar>::consumeOctImpl ( uint64_t& , TNumberFormat<xchar>* );
170
171}} // namespace [alib::strings]
172
ALIB_DLL bool ConsumeFloat(double &result, TNumberFormat< TChar > *numberFormat=nullptr)
ALIB_DLL bool consumeHexImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:98
ALIB_DLL bool consumeDecDigitsImpl(uint64_t &result)
Definition substring.cpp:37
ALIB_DLL bool consumeDecImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:66
ALIB_DLL bool consumeBinImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:82
integer ConsumeChars(integer regionLength, TSubstring *target=nullptr)
ALIB_DLL bool consumeOctImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
ALIB_DLL bool consumeIntImpl(int64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:50
ALIB_DLL uint64_t ParseDec(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_DLL double ParseFloat(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_DLL uint64_t ParseHex(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_DLL uint64_t ParseOct(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_DLL int64_t ParseInt(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
uint64_t ParseDecDigits(const TString< TChar > &src, integer &idx)
ALIB_DLL uint64_t ParseBin(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
static TNumberFormat Computational