8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Configuration MACRO ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
18 module ALib.Format.Paragraphs;
21 import ALib.Exceptions;
23 import ALib.Camp.Base;
74 const String& pIndentOtherLines ) {
75 String indentOtherLines= pIndentOtherLines.
IsNull() ? indentFirstLine
98 "Paragraphs: PopIndent without prior push." )
103 "Paragraphs: PopIndent without prior push." )
127 #if !ALIB_SINGLE_THREADED
140 #if defined( _WIN32 )
153 integer exceptStart= errPos - 25;
154 if( exceptStart <= 0 ) {
155 exceptPos+= exceptStart;
163 actText.
_( markedBuffer, exceptStart, 50 );
164 if( markedBuffer.
Length() > exceptStart + 50 )
179 searchCharBuf[1]=
'\n';
180 String searchChars(searchCharBuf, 2);
182 #if !ALIB_SINGLE_THREADED
183 lang::OwnerRecursive<RecursiveLock, true> lock(
194 integer pos= parser.template IndexOfAny<lang::Inclusion::Include, NC>( searchChars );
203 if( parser.
CharAt( pos ) ==
'\n' ) {
204 parser.template ConsumeChars<NC, lang::CurrentData::Keep>( pos,
Buffer, 1 );
205 if (
Buffer.CharAtEnd() ==
'\r')
212 lastTextStart=
Buffer.Length();
216 parser.template ConsumeChars<NC, lang::CurrentData::Keep>( pos,
Buffer, 1 );
275 if( lastTextStart <
Buffer.Length() ) {
294 const String& pIndentFirstLine,
295 const String& pIndentOtherLines ) {
298 String indentOtherLines= pIndentOtherLines.
IsNotNull() ? pIndentOtherLines : pIndentFirstLine;
300 bool isFirstLine=
true;
303 bool indentAreJustSpaces=
false;
306 integer maxLineWidthDetectionStartIdx= startIdx;
309 maxLineWidth= (std::max)( maxLineWidth, startIdx - maxLineWidthDetectionStartIdx
311 #
if defined( _WIN32 )
318 if ( startIdx ==
text.Length() )
320 maxLineWidthDetectionStartIdx= startIdx;
324 int isWinNL=
text[ startIdx ] ==
'\r' ? 1 : 0;
325 if (
text[ startIdx + isWinNL ] ==
'\n' ) {
330 indent = isFirstLine ? indentFirstLines : indentOtherLines;
331 indentAreJustSpaces= (indent.template IndexOfAny<lang::Inclusion::Exclude>(
A_CHAR(
" " ) ) < 0 );
335 if ( !indentAreJustSpaces ) {
336 text.InsertAt( indent, startIdx );
337 startIdx+= indent.
Length();
340 #if defined( _WIN32 )
342 text.template InsertChars<NC>(
'\r', 1, startIdx );
347 text.template Delete<NC>(startIdx, 1);
353 startIdx+= 1 + isWinNL;
364 indent = isFirstLine ? indentFirstLines : indentOtherLines;
365 indentAreJustSpaces= (indent.template IndexOfAny<lang::Inclusion::Exclude>(
A_CHAR(
" " ) ) < 0 );
367 text.InsertAt( indent, startIdx );
378 bool isLastLine =
true;
379 bool exceeds =
false;
380 while (++idx <
text.Length() ) {
387 exceeds= lineWidth > 0 && idx - startIdx >= lineWidth;
390 if(idx - startIdx <= lineWidth )
391 lastSpaceInLine= idx;
399 #if defined( _WIN32 )
400 if(
text[idx-1] ==
'\n' &&
text[idx-2] !=
'\r' ) {
401 text.template InsertChars<NC>(
'\r', 1, idx-1 );
405 if(
text[idx-1] ==
'\n' &&
text[idx-2] ==
'\r' ) {
406 text.template Delete<NC>((idx-2), 1);
412 if( exceeds && ( lastSpaceInLine || !isLastLine ) ) {
413 integer wrapPos= lastSpaceInLine > 0 ? lastSpaceInLine : idx;
414 text.template ReplaceSubstring<NC>(
NEW_LINE, wrapPos, 1 );
419 if( justifyChar !=
'\0' ) {
420 integer qtyInserts= lineWidth - (wrapPos - startIdx );
421 if( qtyInserts > 0 ) {
424 while ( leftInsertBoundary < idx &&
text[leftInsertBoundary] ==
' ' )
425 ++leftInsertBoundary;
427 if( leftInsertBoundary < idx ) {
428 while( qtyInserts > 0 ) {
430 bool foundOne=
false;
431 while( qtyInserts > 0 ) {
432 actPos=
text.LastIndexOf(
' ', actPos );
433 if( actPos < leftInsertBoundary )
436 text.InsertChars( justifyChar, 1, actPos );
439 while( --actPos > leftInsertBoundary &&
text[actPos] ==
' ' )
#define ALIB_COMMA_CALLER_PRUNED
#define ALIB_CALLER_NULLED
#define ALIB_ASSERT_ERROR(cond, domain,...)
integer SearchAndReplace(TChar needle, TChar replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN)
TAString & DeleteEnd(integer regionLength)
TAString & _(const TAppendable &src)
constexpr integer Length() const
bool EndsWith(const TString &needle) const
constexpr bool IsNotNull() const
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
constexpr bool IsNull() const
bool ConsumeString(const TString< TChar > &consumable)
TString< TChar > ConsumeToken(TChar separator=',', lang::Inclusion includeSeparator=lang::Inclusion::Include)
std::deque< T, StdMA< T > > StdDequeMA
Type alias in namespace alib.
LocalString< 64 > String64
Type alias name for #"TLocalString;TLocalString<character,64>".
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
constexpr const String EMPTY_STRING
An empty string of the default character type.
lang::integer integer
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
exceptions::Exception Exception
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.