ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
strings_tfield.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
17
18//============================================== Module ============================================
19#if ALIB_C20_MODULES
20 module ALib.Boxing;
21 import ALib.Lang;
22# if ALIB_STRINGS
23 import ALib.Strings;
24# endif
25#else
26# include "ALib.Lang.H"
27# include "ALib.Strings.H"
28# include "ALib.Boxing.H"
29#endif
30//========================================== Implementation ========================================
31
32//##################################################################################################
33// TField()
34//##################################################################################################
35namespace alib::strings {
36
37template<typename TChar, typename TAllocator>
38void AppendableTraits< TField<TChar>, TChar,TAllocator>::operator()( TAString<TChar,TAllocator>& target,
39 const TField<TChar>& field) {
40 TString<TChar> theContent;
41
42 // buffer used for conversion (if none string)
43 TLocalString<TChar, 256> noneStringArgBuf;
44 noneStringArgBuf.DbgDisableBufferReplacementWarning();
45
46 // string-type box given?
47 if( !field.theContent.template IsType<void>() && field.theContent.template IsType<TString<TChar>>() )
48 theContent= field.theContent.template Unbox<TString<TChar>>();
49 else {
50 // write box into local buffer
51 noneStringArgBuf << field.theContent;
52 theContent= noneStringArgBuf;
53 }
54
55 integer padSize= field.fieldWidth
56 - theContent.WStringLength();
57
58 // check pad field.width
59 if (padSize <= 0 || field.alignment == lang::Alignment::Left ) {
60 target.template _ <NC>( theContent );
61 if (padSize > 0 ) target.template InsertChars<NC>( field.padChar, padSize );
62 return;
63 }
64
65 // align Right
66 if ( field.alignment == lang::Alignment::Right ) {
67 if( padSize > 0 )
68 target.template InsertChars<NC>( field.padChar, padSize );
69 target.template Append<NC>( theContent );
70 return;
71 }
72
73 // align Center
74 integer leftPadding= padSize / 2;
75 if( leftPadding > 0 )
76 target.template InsertChars<NC> ( field.padChar, leftPadding );
77 target.template Append<NC> ( theContent );
78 if( padSize > leftPadding ) target.template InsertChars<NC> ( field.padChar, padSize - leftPadding );
79}
80
81template void AppendableTraits<TField <nchar>, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const TField <nchar>& );
82template void AppendableTraits<TField <wchar>, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const TField <wchar>& );
83}
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:244
integer WStringLength() const
@ Right
Chooses right alignment.
@ Left
Chooses left alignment.
characters::wchar wchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
characters::nchar nchar
Type alias in namespace alib.