is_digit Function

private elemental function is_digit(self)

Arguments

Type IntentOptional AttributesName
class(string), intent(in) :: self

The string.

Return Value logical

Result of the test.

Description

Return true if all characters in the string are digits.


Variables

TypeVisibility AttributesNameInitial
integer, public :: c

Character counter.


Source Code

  elemental function is_digit(self)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Return true if all characters in the string are digits.
  !---------------------------------------------------------------------------------------------------------------------------------
  class(string), intent(in) :: self     !< The string.
  logical                   :: is_digit !< Result of the test.
  integer                   :: c        !< Character counter.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  is_digit = .false.
  if (allocated(self%raw)) then
    do c=1, len(self%raw)
      select case (self%raw(c:c))
      case ('0':'9')
        is_digit = .true.
      case default
        is_digit = .false.
        exit
      end select
    enddo
  endif
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction is_digit