looks_numeric Function

private pure function looks_numeric(arg) result(r)

Whether arg is a negative number rather than an option.

Only the shape is tested, not whether it parses: -5, -1.5 and -.5 are numbers, -s and -verbose are not. Getting this wrong in the permissive direction would let a mistyped option through as a positional, which is the bug this guards.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: arg

Token to classify; known to start with - and be longer than one.

Return Value logical


Called by

proc~~looks_numeric~~CalledByGraph proc~looks_numeric looks_numeric proc~cli_parse_args cli_t%cli_parse_args proc~cli_parse_args->proc~looks_numeric proc~cli_parse cli_t%cli_parse proc~cli_parse->proc~cli_parse_args

Variables

Type Visibility Attributes Name Initial
character(len=1), private :: c

Source Code

   pure function looks_numeric(arg) result(r)
      !! Whether `arg` is a negative number rather than an option.
      !!
      !! Only the shape is tested, not whether it parses: `-5`, `-1.5` and
      !! `-.5` are numbers, `-s` and `-verbose` are not. Getting this wrong in
      !! the permissive direction would let a mistyped option through as a
      !! positional, which is the bug this guards.
      character(len=*), intent(in) :: arg
         !! Token to classify; known to start with `-` and be longer than one.
      logical :: r

      character(len=1) :: c

      r = .false.
      c = arg(2:2)
      if (c >= "0" .and. c <= "9") then
         r = .true.
      else if (c == "." .and. len(arg) > 2) then
         c = arg(3:3)
         r = c >= "0" .and. c <= "9"
      end if
   end function looks_numeric