Skip to content

Commit 30efb0c

Browse files
committed
suggested renaming of rmComment
1 parent 6936e9e commit 30efb0c

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

src/YAML.f90

+36-37
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ logical function isKeyValue(line)
310310
isKeyValue = .false.
311311

312312

313-
if ( .not. isKey(line) .and. index(rmComment(line),':') > 0 .and. .not. isFlow(line)) then
314-
if (index(rmComment(line),': ') > 0) isKeyValue = .true.
313+
if ( .not. isKey(line) .and. index(clean(line),':') > 0 .and. .not. isFlow(line)) then
314+
if (index(clean(line),': ') > 0) isKeyValue = .true.
315315
end if
316316

317317
end function isKeyValue
@@ -326,11 +326,11 @@ logical function isKey(line)
326326
character(len=*), intent(in) :: line
327327

328328

329-
if (len(rmComment(line)) == 0) then
329+
if (len(clean(line)) == 0) then
330330
isKey = .false.
331331
else
332-
isKey = index(rmComment(line),':',back=.false.) == len(rmComment(line)) .and. &
333-
index(rmComment(line),':',back=.true.) == len(rmComment(line)) .and. &
332+
isKey = index(clean(line),':',back=.false.) == len(clean(line)) .and. &
333+
index(clean(line),':',back=.true.) == len(clean(line)) .and. &
334334
.not. isFlow(line)
335335
end if
336336

@@ -364,7 +364,7 @@ subroutine skip_empty_lines(blck,s_blck)
364364

365365
empty = .true.
366366
do while (empty .and. len_trim(blck(s_blck:)) /= 0)
367-
empty = len_trim(rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))) == 0
367+
empty = len_trim(clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))) == 0
368368
if (empty) s_blck = s_blck + index(blck(s_blck:),IO_EOL)
369369
end do
370370

@@ -383,11 +383,11 @@ subroutine skip_file_header(blck,s_blck)
383383
character(len=:), allocatable :: line
384384

385385

386-
line = rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
386+
line = clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
387387
if (index(adjustl(line),'%YAML') == 1) then
388388
s_blck = s_blck + index(blck(s_blck:),IO_EOL)
389389
call skip_empty_lines(blck,s_blck)
390-
if (trim(rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))) == '---') then
390+
if (trim(clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))) == '---') then
391391
s_blck = s_blck + index(blck(s_blck:),IO_EOL)
392392
else
393393
call IO_error(708,ext_msg = line)
@@ -443,7 +443,7 @@ subroutine remove_line_break(blck,s_blck,e_char,flow_line)
443443
flow_line = ''
444444

445445
do while (.not. line_end)
446-
flow_line = flow_line//rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))//' '
446+
flow_line = flow_line//clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))//' '
447447
line_end = flow_is_closed(flow_line,e_char)
448448
s_blck = s_blck + index(blck(s_blck:),IO_EOL)
449449
end do
@@ -466,14 +466,14 @@ subroutine list_item_inline(blck,s_blck,inline,offset)
466466

467467

468468
indent = indentDepth(blck(s_blck:),offset)
469-
line = rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
469+
line = clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
470470
inline = line(indent-offset+3:)
471471
s_blck = s_blck + index(blck(s_blck:),IO_EOL)
472472

473473
indent_next = indentDepth(blck(s_blck:))
474474

475475
do while (indent_next > indent)
476-
inline = inline//' '//trim(adjustl(rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))))
476+
inline = inline//' '//trim(adjustl(clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))))
477477
s_blck = s_blck + index(blck(s_blck:),IO_EOL)
478478
indent_next = indentDepth(blck(s_blck:))
479479
end do
@@ -621,7 +621,7 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset)
621621
indent = indentDepth(blck(s_blck:),offset)
622622
do while (s_blck <= len_trim(blck))
623623
e_blck = s_blck + index(blck(s_blck:),IO_EOL) - 2
624-
line = rmComment(blck(s_blck:e_blck))
624+
line = clean(blck(s_blck:e_blck))
625625
if (trim(line) == '---' .or. trim(line) == '...') then
626626
exit
627627
elseif (len_trim(line) == 0) then
@@ -640,7 +640,7 @@ recursive subroutine lst(blck,flow,s_blck,s_flow,offset)
640640
s_blck = e_blck + 2
641641
call skip_empty_lines(blck,s_blck)
642642
e_blck = s_blck + index(blck(s_blck:),IO_EOL) - 2
643-
line = rmComment(blck(s_blck:e_blck))
643+
line = clean(blck(s_blck:e_blck))
644644
if (trim(line) == '---') call IO_error(707,ext_msg=line)
645645
if (indentDepth(line) < indent .or. indentDepth(line) == indent) &
646646
call IO_error(701,ext_msg=line)
@@ -718,7 +718,7 @@ recursive subroutine dct(blck,flow,s_blck,s_flow,offset)
718718

719719
do while (s_blck <= len_trim(blck))
720720
e_blck = s_blck + index(blck(s_blck:),IO_EOL) - 2
721-
line = rmComment(blck(s_blck:e_blck))
721+
line = clean(blck(s_blck:e_blck))
722722
if (trim(line) == '---' .or. trim(line) == '...') then
723723
exit
724724
elseif (len_trim(line) == 0) then
@@ -796,7 +796,7 @@ recursive subroutine decide(blck,flow,s_blck,s_flow,offset)
796796
if (s_blck <= len(blck)) then
797797
call skip_empty_lines(blck,s_blck)
798798
e_blck = s_blck + index(blck(s_blck:),IO_EOL) - 2
799-
line = rmComment(blck(s_blck:e_blck))
799+
line = clean(blck(s_blck:e_blck))
800800
if (trim(line) == '---' .or. trim(line) == '...') then
801801
continue ! end parsing at this point but not stop the simulation
802802
elseif (len_trim(line) == 0) then
@@ -854,11 +854,11 @@ function to_flow(blck)
854854
if (len_trim(blck) /= 0) then
855855
call skip_empty_lines(blck,s_blck)
856856
call skip_file_header(blck,s_blck)
857-
line = rmComment(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
857+
line = clean(blck(s_blck:s_blck + index(blck(s_blck:),IO_EOL) - 2))
858858
if (trim(line) == '---') s_blck = s_blck + index(blck(s_blck:),IO_EOL)
859859
call decide(blck,to_flow,s_blck,s_flow,offset)
860860
end if
861-
line = rmComment(blck(s_blck:s_blck+index(blck(s_blck:),IO_EOL)-2))
861+
line = clean(blck(s_blck:s_blck+index(blck(s_blck:),IO_EOL)-2))
862862
if (trim(line)== '---') call IO_warning(709,ext_msg=line)
863863
to_flow = trim(to_flow(:s_flow-1))
864864
end_line = index(to_flow,IO_EOL)
@@ -869,26 +869,25 @@ end function to_flow
869869

870870
!--------------------------------------------------------------------------------------------------
871871
! @brief Remove comments (characters beyond '#') and trailing space.
872-
! ToDo: Discuss name (the trim aspect is not clear)
873872
!--------------------------------------------------------------------------------------------------
874-
function rmComment(line)
873+
function clean(line)
875874

876875
character(len=*), intent(in) :: line
877-
character(len=:), allocatable :: rmComment
876+
character(len=:), allocatable :: clean
878877

879878
integer :: split
880-
character, parameter :: COMMENT_SIGN = '#'
879+
character, parameter :: COMMENT_CHAR = '#'
881880

882881

883-
split = index(line,COMMENT_SIGN)
882+
split = index(line,COMMENT_CHAR)
884883

885884
if (split == 0) then
886-
rmComment = trim(line)
885+
clean = trim(line)
887886
else
888-
rmComment = trim(line(:split-1))
887+
clean = trim(line(:split-1))
889888
end if
890889

891-
end function rmComment
890+
end function clean
892891

893892

894893
!--------------------------------------------------------------------------------------------------
@@ -1058,18 +1057,18 @@ subroutine YAML_selfTest()
10581057
comment: block
10591058
character(len=:), allocatable :: str,out
10601059

1061-
str='#';out=rmComment(str)
1062-
if (out /= '' .or. len(out) /= 0) error stop 'rmComment/1'
1063-
str=' #';out=rmComment(str)
1064-
if (out /= '' .or. len(out) /= 0) error stop 'rmComment/2'
1065-
str=' # ';out=rmComment(str)
1066-
if (out /= '' .or. len(out) /= 0) error stop 'rmComment/3'
1067-
str=' # a';out=rmComment(str)
1068-
if (out /= '' .or. len(out) /= 0) error stop 'rmComment/4'
1069-
str=' a#';out=rmComment(str)
1070-
if (out /= ' a' .or. len(out) /= 2) error stop 'rmComment/5'
1071-
str=' ab #';out=rmComment(str)
1072-
if (out /= ' ab'.or. len(out) /= 3) error stop 'rmComment/6'
1060+
str='#';out=clean(str)
1061+
if (out /= '' .or. len(out) /= 0) error stop 'clean/1'
1062+
str=' #';out=clean(str)
1063+
if (out /= '' .or. len(out) /= 0) error stop 'clean/2'
1064+
str=' # ';out=clean(str)
1065+
if (out /= '' .or. len(out) /= 0) error stop 'clean/3'
1066+
str=' # a';out=clean(str)
1067+
if (out /= '' .or. len(out) /= 0) error stop 'clean/4'
1068+
str=' a#';out=clean(str)
1069+
if (out /= ' a' .or. len(out) /= 2) error stop 'clean/5'
1070+
str=' ab #';out=clean(str)
1071+
if (out /= ' ab'.or. len(out) /= 3) error stop 'clean/6'
10731072
end block comment
10741073

10751074
end subroutine YAML_selfTest

0 commit comments

Comments
 (0)