Skip to content

Commit 7cf4bde

Browse files
Merge pull request #294 from jacobwilliams/lowercase-hotfix
lowercase_string bug fix
2 parents b0dd61f + b4bdb2f commit 7cf4bde

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

src/json_string_utilities.F90

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -728,26 +728,6 @@ pure elemental function default_neq_ucs4(def_str,ucs4_str) result(res)
728728
end function default_neq_ucs4
729729
!*****************************************************************************************
730730

731-
!*****************************************************************************************
732-
!> author: Jacob Williams
733-
!
734-
! Return the lowercase version of the `CK` character.
735-
736-
pure elemental function lowercase_character(c) result(c_lower)
737-
738-
implicit none
739-
740-
character(kind=CK,len=1),intent(in) :: c
741-
character(kind=CK,len=1) :: c_lower
742-
743-
integer :: i !! index in uppercase array
744-
745-
i = index(upper,c)
746-
c_lower = merge(lower(i:i),c,i>0)
747-
748-
end function lowercase_character
749-
!*****************************************************************************************
750-
751731
!*****************************************************************************************
752732
!> author: Jacob Williams
753733
!
@@ -761,23 +741,21 @@ pure elemental function lowercase_string(str) result(s_lower)
761741
character(kind=CK,len=(len(str))) :: s_lower !! lowercase version of the string
762742

763743
integer :: i !! counter
764-
integer :: n !! length of input string
744+
integer :: j !! index of uppercase character
765745

766-
s_lower = CK_''
767-
n = len_trim(str)
746+
s_lower = str
768747

769-
if (n>0) then
770-
do concurrent (i=1:n)
771-
s_lower(i:i) = lowercase_character(str(i:i))
772-
end do
773-
end if
748+
do i = 1, len_trim(str)
749+
j = index(upper,s_lower(i:i))
750+
if (j>0) s_lower(i:i) = lower(j:j)
751+
end do
774752

775753
end function lowercase_string
776754
!*****************************************************************************************
777755

778756
!*****************************************************************************************
779757
!>
780-
! Replace all occurances of `s1` in `str` with `s2`.
758+
! Replace all occurrences of `s1` in `str` with `s2`.
781759
!
782760
! A case-sensitive match is used.
783761
!

0 commit comments

Comments
 (0)