ALib C++ Library
Library Version: 2511 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 integer idx= 0;
39 result= detail::ParseDecDigits( *this, idx );
40 if( idx > 0 ) {
41 ConsumeChars<NC>( idx );
42 return true;
43 }
44 return false;
45}
46
47template<typename TChar>
48bool TSubstring<TChar>::consumeIntImpl( int64_t& result, TNumberFormat<TChar>* numberFormat ) {
49 if ( numberFormat == nullptr )
51
52 integer idx= 0;
53 result= detail::ParseInt( *this, idx, *numberFormat );
54 if( idx > 0 ) {
55 ConsumeChars<NC>( idx );
56 return true;
57 }
58 return false;
59}
60
61template<typename TChar>
62bool TSubstring<TChar>::consumeDecImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat ) {
63 if ( numberFormat == nullptr )
65
66 integer idx= 0;
67 result= detail::ParseDec( *this, idx, *numberFormat );
68 if( idx > 0 ) {
69 ConsumeChars<NC>( idx );
70 return true;
71 }
72 return false;
73}
74
75template<typename TChar>
76bool TSubstring<TChar>::consumeBinImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat ) {
77 if ( numberFormat == nullptr )
79
80 integer idx= 0;
81 result= detail::ParseBin( *this, idx, *numberFormat );
82 if( idx > 0 ) {
83 ConsumeChars<NC>( idx );
84 return true;
85 }
86 return false;
87}
88
89template<typename TChar>
90bool TSubstring<TChar>::consumeHexImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat ) {
91 if ( numberFormat == nullptr )
93
94 integer idx= 0;
95 result= detail::ParseHex( *this, idx, *numberFormat );
96 if( idx > 0 ) {
97 ConsumeChars<NC>( idx );
98 return true;
99 }
100 return false;
101}
102
103template<typename TChar>
104bool TSubstring<TChar>::consumeOctImpl( uint64_t& result, TNumberFormat<TChar>* numberFormat ) {
105 if ( numberFormat == nullptr )
107
108 integer idx= 0;
109 result= detail::ParseOct( *this, idx, *numberFormat );
110 if( idx > 0 ) {
111 ConsumeChars<NC>( idx );
112 return true;
113 }
114 return false;
115}
116
117template<typename TChar>
119 TNumberFormat<TChar>* numberFormat ) {
120 if ( numberFormat == nullptr )
122
123 integer idx= 0;
124 result= detail::ParseFloat( *this, idx, *numberFormat );
125 if( idx > 0 ) {
126 ConsumeChars<NC>( idx );
127 return true;
128 }
129 return false;
130}
131
132
133template bool TSubstring<nchar>::ConsumeFloat ( double& , TNumberFormat<nchar>* );
134template bool TSubstring<nchar>::consumeDecDigitsImpl( uint64_t& );
135template bool TSubstring<nchar>::consumeIntImpl ( int64_t& , TNumberFormat<nchar>* );
136template bool TSubstring<nchar>::consumeDecImpl ( uint64_t& , TNumberFormat<nchar>* );
137template bool TSubstring<nchar>::consumeBinImpl ( uint64_t& , TNumberFormat<nchar>* );
138template bool TSubstring<nchar>::consumeHexImpl ( uint64_t& , TNumberFormat<nchar>* );
139template bool TSubstring<nchar>::consumeOctImpl ( uint64_t& , TNumberFormat<nchar>* );
140
141template bool TSubstring<wchar>::ConsumeFloat ( double& , TNumberFormat<wchar>* );
142template bool TSubstring<wchar>::consumeDecDigitsImpl( uint64_t& );
143template bool TSubstring<wchar>::consumeIntImpl ( int64_t& , TNumberFormat<wchar>* );
144template bool TSubstring<wchar>::consumeDecImpl ( uint64_t& , TNumberFormat<wchar>* );
145template bool TSubstring<wchar>::consumeBinImpl ( uint64_t& , TNumberFormat<wchar>* );
146template bool TSubstring<wchar>::consumeHexImpl ( uint64_t& , TNumberFormat<wchar>* );
147template bool TSubstring<wchar>::consumeOctImpl ( uint64_t& , TNumberFormat<wchar>* );
148
149template bool TSubstring<xchar>::ConsumeFloat ( double& , TNumberFormat<xchar>* );
150template bool TSubstring<xchar>::consumeDecDigitsImpl( uint64_t& );
151template bool TSubstring<xchar>::consumeIntImpl ( int64_t& , TNumberFormat<xchar>* );
152template bool TSubstring<xchar>::consumeDecImpl ( uint64_t& , TNumberFormat<xchar>* );
153template bool TSubstring<xchar>::consumeBinImpl ( uint64_t& , TNumberFormat<xchar>* );
154template bool TSubstring<xchar>::consumeHexImpl ( uint64_t& , TNumberFormat<xchar>* );
155template bool TSubstring<xchar>::consumeOctImpl ( uint64_t& , TNumberFormat<xchar>* );
156
157}} // namespace [alib::strings]
ALIB_DLL bool ConsumeFloat(double &result, TNumberFormat< TChar > *numberFormat=nullptr)
ALIB_DLL bool consumeHexImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:90
ALIB_DLL bool consumeDecDigitsImpl(uint64_t &result)
Definition substring.cpp:37
ALIB_DLL bool consumeDecImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:62
ALIB_DLL bool consumeBinImpl(uint64_t &result, TNumberFormat< TChar > *numberFormat)
Definition substring.cpp:76
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:48
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