lower Function

private pure elemental function lower(str, begin, end) result(string)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer, intent(in), optional :: begin
integer, intent(in), optional :: end

Return Value character(len=len(str))


Source Code

    elemental pure function lower(str, begin, end) result(string)

! ident_25="@(#) M_strings lower(3f) Changes a string to lowercase over specified range"

        character(*), intent(in) :: str
        character(len(str)) :: string
        integer, intent(in), optional :: begin, end
        integer :: i
        integer :: ibegin, iend
        integer, parameter :: diff = iachar('A') - iachar('a')
        string = str
        ibegin = 1
        iend = len_trim(str)

        if (present(begin)) then
            ibegin = min(max(1, begin), iend)
        end if

        if (present(end)) then
            iend = max(1, min(iend, end))
        end if

        do concurrent(i=ibegin:iend)                   ! step thru each letter in the string in specified range
            select case (str(i:i))
            case ('A':'Z')
                string(i:i) = achar(iachar(str(i:i)) - diff)   ! change letter to miniscule
            case default
            end select
        end do

    end function lower