ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
spaces.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !defined(ALIB_DOX)
10#if !defined(HPP_ALIB_STRINGS_UTIL_SPACES)
12#endif
13#if !defined (HPP_ALIB_STRINGS_ASTRING)
15#endif
16
17#include <ostream>
18#endif // !defined(ALIB_DOX)
19
20namespace alib { namespace strings { namespace util {
21
22
23//! @cond NO_DOX
24namespace
25{
26 NAString nSpaces;
27 WAString wSpaces;
28}
29//! @endcond
30
32{
33 integer spacesLength= nSpaces.Length();
34 if ( spacesLength < minLength )
35 nSpaces.InsertChars( ' ', minLength - spacesLength );
36 return nSpaces;
37}
38
40{
41 integer spacesLength= wSpaces.Length();
42 if ( spacesLength < minLength )
44 wSpaces.InsertChars( ' ', minLength - spacesLength );
46 return wSpaces;
47}
48
49void Spaces::Write( std::basic_ostream<char>& os, integer qty )
50{
51 if( nSpaces.Length() < 128 )
52 GetN( 128 );
53
54 while ( qty > 0 )
55 {
56 integer size= qty < nSpaces.Length() ? qty : nSpaces.Length();
57 os.write( nSpaces.Buffer(), size );
58 qty-= size;
59 }
60}
61
62#if ALIB_CHARACTERS_NATIVE_WCHAR
63void Spaces::Write( std::basic_ostream<wchar_t>& os, integer qty )
64{
65 if( wSpaces.Length() < 128 )
66 GetW( 128 );
67
68 while ( qty > 0 )
69 {
70 integer size= qty < wSpaces.Length() ? qty : wSpaces.Length();
71 os.write( wSpaces.Buffer(), size );
72 qty-= size;
73 }
74}
75#endif
76
77}}} // namespace [alib::strings::util]
constexpr integer Length() const
Definition string.hpp:357
static ALIB_API WString & GetW(integer minLength=128)
Definition spaces.cpp:39
static ALIB_API void Write(std::basic_ostream< char > &os, integer qty)
Definition spaces.cpp:49
static ALIB_API NString & GetN(integer minLength=128)
Definition spaces.cpp:31
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:715
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:644
Definition alib.cpp:57
strings::TAString< nchar > NAString
Type alias in namespace alib.
strings::TAString< wchar > WAString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286