Skip to content

Commit 1a87696

Browse files
committed
Apply suggestions from code review
Changed to work even when string size is 0.
1 parent 4dbe22c commit 1a87696

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/stdlib_string_type.fypp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ contains
421421
type(string_type), intent(in) :: string
422422
integer :: ich
423423

424-
ich = merge(ichar(string%raw(1:1)), 0, allocated(string%raw))
424+
if (allocated(string%raw) .and. len_trim(string%raw) > 0) then
425+
ich = ichar(string%raw(1:1))
426+
else
427+
ich = 0
428+
end if
425429

426430
end function ichar_string
427431

@@ -431,7 +435,11 @@ contains
431435
type(string_type), intent(in) :: string
432436
integer :: ich
433437

434-
ich = merge(iachar(string%raw(1:1)), 0, allocated(string%raw))
438+
if (allocated(string%raw) .and. len_trim(string%raw) > 0) then
439+
ich = iachar(string%raw(1:1))
440+
else
441+
ich = 0
442+
end if
435443

436444
end function iachar_string
437445

0 commit comments

Comments
 (0)