ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
plaintextlogger.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//============================================== Module ============================================
18#if ALIB_C20_MODULES
19 module ALib.ALox.Impl;
20 import ALib.Lang;
21 import ALib.Characters.Functions;
22 import ALib.Strings;
23 import ALib.Boxing;
24 import ALib.EnumRecords;
25 import ALib.EnumRecords.Bootstrap;
26 import ALib.Variables;
27 import ALib.Camp;
28 import ALib.Camp.Base;
29#else
30# include "ALib.Lang.H"
32# include "ALib.Strings.H"
33# include "ALib.Boxing.H"
35# include "ALib.Variables.H"
36# include "ALib.Camp.H"
37# include "ALib.Camp.Base.H"
38# include "ALib.ALox.H"
39# include "ALib.ALox.Impl.H"
40#endif
41//========================================== Implementation ========================================
42using namespace alib;
43using namespace alib::lox;
44using namespace alib::lox::detail;
45using namespace alib::lox::textlogger;
46
49 AString& msg,
50 ScopeInfo&,
51 int,
52 bool ) {
54 return;
55
56 // loop over message, print the parts between the escape sequences
57 integer msgLength= msg.Length();
58 integer start= 0;
59 integer end;
60 integer column= 0;
61 while( start < msgLength ) {
62 bool foundESC= true;
63 end= msg.String::IndexOf<NC>( '\x1B', start );
64 if( end < 0 ) {
65 foundESC= false;
66 end= msgLength ;
67 }
68
69 if( end > start ) {
70 integer logWidth= logPlainTextPart( msg, start, end - start );
71 if ( logWidth < 0 )
72 return;
73 column+= logWidth;
74 }
75
76 // interpret escape sequence
77 if ( foundESC ) {
78 character c= msg[++end];
79
80 // auto tab or end of meta info part
81 if ( c == 't' || c == 'A') {
82 ++end;
83 c= msg[end++];
84 int extraSpace= c >= '0' && c <= '9' ? c - '0'
85 : c - 'A' + 10;
86
87 integer tabStop= varFormatAutoSizes.Get<FormatAutoSizes>().Main.Next(
88 AutoSizes::Types::Tabstop, column, extraSpace );
89
90 if ( tabStop > column ) {
91 AlignedCharArray spaces( ' ' );
92 integer remaining= tabStop - column;
93 while ( remaining > 0 ) {
94 integer size= remaining < spaces.Length() ? remaining
95 : spaces.Length();
96 if( logPlainTextPart( String(spaces.Buffer(), spaces.Length()), 0, size ) < 0 )
97 return;
98 remaining-= size;
99 }
100 column= tabStop;
101 } }
102
103 // prune or ignore all others
104 else {
105 if ( !PruneESCSequences )
106 if( logPlainTextPart( msg, end - 1, 3 ) < 0)
107 return;
108 end+= 2;
109 } }
110
111 // next
112 start= end;
113
114 } // write loop
115
116 ALIB_ASSERT_WARNING( start == msgLength, "ALOX", "Loop error when pruning ESC codes" )
118}
virtual ALIB_DLL void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber, bool isRecursion) override
virtual bool notifyPlainTextLogOp(lang::Phase phase)=0
virtual integer logPlainTextPart(const String &buffer, integer start, integer length)=0
constexpr integer Length() const
Definition string.inl:316
@ Tabstop
denotes a tab stop entry.
Definition autosizes.inl:57
#define ALIB_ASSERT_WARNING(cond, domain,...)
Definition alib.inl:1067
@ Begin
The start of a transaction.
@ End
The end of a transaction.
This namespaces defines class TextLogger and its helpers.
Definition loxpimpl.inl:13
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
characters::AlignedCharArray<> AlignedCharArray
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
characters::character character
Type alias in namespace alib.
constexpr integer Length() const noexcept
constexpr TChar * Buffer() noexcept