Skip to content

Commit cb88331

Browse files
committed
logger2: ad support for new_line(a) in stdlib_logger.f90
1 parent 0f2c0a9 commit cb88331

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/stdlib_logger.f90

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ subroutine format_output_string( self, unit, string, procedure_name, &
523523
character(*), intent(in) :: procedure_name
524524
character(*), intent(in) :: col_indent
525525

526-
integer :: count, indent_len, index, iostat, length, remain
526+
integer :: count, indent_len, index_, iostat, length, remain
527527
character(256) :: iomsg
528528

529529
length = len_trim(string)
@@ -551,20 +551,23 @@ subroutine format_first_line()
551551
return
552552
else
553553

554-
do index=self % max_width, 1, -1
555-
if ( string(index:index) == ' ' ) exit
556-
end do
554+
index_ = index( string(1:self % max_width), new_line('a'))
555+
if ( index_ == 0 ) then
556+
do index_=self % max_width, 1, -1
557+
if ( string(index_:index_) == ' ' ) exit
558+
end do
559+
end if
557560

558-
if ( index == 0 ) then
561+
if ( index_ == 0 ) then
559562
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
560563
string(1:self % max_width)
561564
count = self % max_width
562565
remain = length - count
563566
return
564567
else
565568
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
566-
string(1:index-1)
567-
count = index
569+
string(1:index_-1)
570+
count = index_
568571
remain = length - count
569572
return
570573
end if
@@ -585,20 +588,24 @@ subroutine format_subsequent_line()
585588
return
586589
else
587590

588-
do index=count+self % max_width, count+1, -1
589-
if ( string(index:index) == ' ' ) exit
590-
end do
591+
index_ = count + index( string(count+1:count+self % max_width), &
592+
new_line('a'))
593+
if(index_ == count) then
594+
do index_=count+self % max_width, count+1, -1
595+
if ( string(index_:index_) == ' ' ) exit
596+
end do
597+
end if
591598

592-
if ( index == count ) then
599+
if ( index_ == count ) then
593600
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
594601
string(count+1:count+self % max_width)
595602
count = count + self % max_width
596603
remain = length - count
597604
return
598605
else
599606
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
600-
string(count+1:index-1)
601-
count = index
607+
string(count+1:index_-1)
608+
count = index_
602609
remain = length - count
603610
return
604611
end if
@@ -611,19 +618,24 @@ end subroutine format_subsequent_line
611618

612619
subroutine indent_format_subsequent_line()
613620

614-
if ( remain <= self % max_width - indent_len ) then
621+
if ( index( string(count+1:length), new_line('a')) == 0 .and. &
622+
remain <= self % max_width - indent_len ) then
615623
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
616624
col_indent // string(count+1:length)
617625
count = length
618626
remain = 0
619627
return
620628
else
621629

622-
do index=count+self % max_width-indent_len, count+1, -1
623-
if ( string(index:index) == ' ' ) exit
624-
end do
630+
index_ = count + index( string(count+1:count+self % max_width &
631+
- indent_len), new_line('a'))
632+
if(index_ == count) then
633+
do index_=count+self % max_width-indent_len, count+1, -1
634+
if ( string(index_:index_) == ' ' ) exit
635+
end do
636+
end if
625637

626-
if ( index == count ) then
638+
if ( index_ == count ) then
627639
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
628640
col_indent // &
629641
string(count+1:count+self % max_width-indent_len)
@@ -632,8 +644,8 @@ subroutine indent_format_subsequent_line()
632644
return
633645
else
634646
write( unit, '(a)', err=999, iostat=iostat, iomsg=iomsg ) &
635-
col_indent // string(count+1:index-1)
636-
count = index
647+
col_indent // string(count+1:index_-1)
648+
count = index_
637649
remain = length - count
638650
return
639651
end if

0 commit comments

Comments
 (0)