ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
strings_tfield.cpp
1
2//##################################################################################################
3// TField()
4//##################################################################################################
5namespace alib::strings {
6
7template<typename TChar, typename TAllocator>
8void AppendableTraits< TField<TChar>, TChar,TAllocator>::operator()( TAString<TChar,TAllocator>& target,
9 const TField<TChar>& field) {
10 TString<TChar> theContent;
11
12 // buffer used for conversion (if none string)
13 TLocalString<TChar, 256> noneStringArgBuf;
14 noneStringArgBuf.DbgDisableBufferReplacementWarning();
15
16 // string-type box given?
17 if( !field.theContent.template IsType<void>() && field.theContent.template IsType<TString<TChar>>() )
18 theContent= field.theContent.template Unbox<TString<TChar>>();
19 else {
20 // write box into local buffer
21 noneStringArgBuf << field.theContent;
22 theContent= noneStringArgBuf;
23 }
24
25 integer padSize= field.fieldWidth
26 - theContent.WStringLength();
27
28 // check pad field.width
29 if (padSize <= 0 || field.alignment == lang::Alignment::Left ) {
30 target.template _ <NC>( theContent );
31 if (padSize > 0 ) target.template InsertChars<NC>( field.padChar, padSize );
32 return;
33 }
34
35 // align Right
36 if ( field.alignment == lang::Alignment::Right ) {
37 if( padSize > 0 )
38 target.template InsertChars<NC>( field.padChar, padSize );
39 target.template Append<NC>( theContent );
40 return;
41 }
42
43 // align Center
44 integer leftPadding= padSize / 2;
45 if( leftPadding > 0 )
46 target.template InsertChars<NC> ( field.padChar, leftPadding );
47 target.template Append<NC> ( theContent );
48 if( padSize > leftPadding ) target.template InsertChars<NC> ( field.padChar, padSize - leftPadding );
49}
50
51template void AppendableTraits<TField <nchar>, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const TField <nchar>& );
52template void AppendableTraits<TField <wchar>, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const TField <wchar>& );
53}
void DbgDisableBufferReplacementWarning()
Definition tastring.hpp:236
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.hpp:149
characters::nchar nchar
Type alias in namespace #"%alib".