ALib C++ Library
Library Version: 2510 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{
41 TString<TChar> theContent;
42
43 // buffer used for conversion (if none string)
44 TLocalString<TChar, 256> noneStringArgBuf;
45 noneStringArgBuf.DbgDisableBufferReplacementWarning();
46
47 // string-type box given?
48 if( !field.theContent.template IsType<void>() && field.theContent.template IsType<TString<TChar>>() )
49 theContent= field.theContent.template Unbox<TString<TChar>>();
50 else
51 {
52 // write box into local buffer
53 noneStringArgBuf << field.theContent;
54 theContent= noneStringArgBuf;
55 }
56
57 integer padSize= field.fieldWidth
58 - theContent.WStringLength();
59
60 // check pad field.width
61 if (padSize <= 0 || field.alignment == lang::Alignment::Left )
62 {
63 target.template _ <NC>( theContent );
64 if (padSize > 0 ) target.template InsertChars<NC>( field.padChar, padSize );
65 return;
66 }
67
68 // align Right
69 if ( field.alignment == lang::Alignment::Right )
70 {
71 if( padSize > 0 )
72 target.template InsertChars<NC>( field.padChar, padSize );
73 target.template Append<NC>( theContent );
74 return;
75 }
76
77 // align Center
78 integer leftPadding= padSize / 2;
79 if( leftPadding > 0 )
80 target.template InsertChars<NC> ( field.padChar, leftPadding );
81 target.template Append<NC> ( theContent );
82 if( padSize > leftPadding ) target.template InsertChars<NC> ( field.padChar, padSize - leftPadding );
83}
84
85template void AppendableTraits<TField <nchar>, nchar, lang::HeapAllocator>::operator()( TAString<nchar, lang::HeapAllocator>&, const TField <nchar>& );
86template void AppendableTraits<TField <wchar>, wchar, lang::HeapAllocator>::operator()( TAString<wchar, lang::HeapAllocator>&, const TField <wchar>& );
87}
void DbgDisableBufferReplacementWarning()
Definition tastring.inl:245
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.