str_begins_with_str Function

public pure function str_begins_with_str(s, e, case_sensitive) result(r)

test if a CHARACTER string begins with a specified prefix

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s
character(len=*), intent(in) :: e
logical, intent(in), optional :: case_sensitive

Return Value logical


Source Code

pure logical function str_begins_with_str(s, e, case_sensitive) result(r)
    character(*), intent(in) :: s, e
    logical, optional, intent(in) :: case_sensitive ! Default option: case sensitive
    integer :: n1, n2
    logical :: lower_case

    ! Check if case sensitive
    if (present(case_sensitive)) then
        lower_case = .not.case_sensitive
    else
        lower_case = .false.
    end if

    n1 = 1
    n2 = 1 + len(e)-1
    if (n2 > len(s)) then
        r = .false.
    elseif (lower_case) then
        r = lower(s(n1:n2)) == lower(e)
    else
        r = (s(n1:n2) == e)
    end if
end function str_begins_with_str