regex_version_from_text Function

public function regex_version_from_text(text, what, error) result(ver)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text
character(len=*), intent(in) :: what
type(error_t), intent(out), allocatable :: error

Return Value type(string_t)


Source Code

    type(string_t) function regex_version_from_text(text,what,error) result(ver)
        character(*), intent(in) :: text
        character(*), intent(in) :: what
        type(error_t), allocatable, intent(out) :: error

        integer :: ire, length

        if (len_trim(text)<=0) then
            call syntax_error(error,'cannot retrieve '//what//' version: empty input string')
            return
        end if

        ! Extract 3-sized version "1.0.4"
        ire = regex(text,'\d+\.\d+\.\d+',length=length)
        if (ire>0 .and. length>0) then
            ! Parse version into the object (this should always work)
            ver = string_t(text(ire:ire+length-1))
        else

            ! Try 2-sized version "1.0"
            ire = regex(text,'\d+\.\d+',length=length)

            if (ire>0 .and. length>0) then
                ver = string_t(text(ire:ire+length-1))
            else
                call syntax_error(error,'cannot retrieve '//what//' version.')
            end if

        end if

    end function regex_version_from_text